forked from angular/angular
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerate_element_api_json.bzl
54 lines (44 loc) · 1.94 KB
/
generate_element_api_json.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
def _generate_element_api_json(ctx):
"""Implementation of the generate_element_api_json rule"""
# Define arguments that will be passed to the underlying nodejs program.
args = ctx.actions.args()
# Use a param file for consistency with other doc generation rules.
args.set_param_file_format("multiline")
args.use_param_file("%s", use_always = True)
# Pass the set of source files from which the API data will be generated.
args.add_joined(ctx.files.srcs, join_with = ",")
# Pass the name of the output JSON file.
manifest = ctx.actions.declare_file("elements.json")
args.add(manifest.path)
# Define an action that runs the nodejs_binary executable. This is
# the main thing that this rule does.
run_node(
ctx = ctx,
inputs = depset(ctx.files.srcs),
executable = "_generate_element_api_json",
outputs = [manifest],
arguments = [args],
)
# The return value describes what the rule is producing. In this case we need to specify
# the "DefaultInfo" with the output JSON manifest.
return [DefaultInfo(files = depset([manifest]))]
generate_element_api_json = rule(
# Point to the starlark function that will execute for this rule.
implementation = _generate_element_api_json,
doc = """Rule that generates an Angular API doc collection for hand-written element APIs""",
# The attributes that can be set to this rule.
attrs = {
"srcs": attr.label_list(
doc = """The source files for this rule, must include one or more markdown files.""",
allow_empty = False,
allow_files = True,
),
# The executable for this rule (private).
"_generate_element_api_json": attr.label(
default = Label("//tools/manual_api_docs:generate_element_api_json"),
executable = True,
cfg = "exec",
),
},
)