angular/adev/shared-docs/pipeline/_previews.bzl
Miles Malerba 4fec563f7f docs: Restructure example build rules (#60778)
Restructures the examples build rules so that all examples are exposed
through a single file group in adev/src/content/examples.

Also adds a separate filegroup in the same location for just the
embeddable examples and adds it to the APPLICATION_FILES for the docs
app.

This uncovered the fact that some of our examples have broken
non-compiling code. I've excluded these ones from being embeddable for
now, until the breakages can be addressed

PR Close #60778
2025-04-11 17:19:35 -04:00

56 lines
1.9 KiB
Python

load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
def _generate_previews_impl(ctx):
"""Implementation of the previews generator rule"""
# File declaration of the generated ts file
ts_output = ctx.actions.declare_file("previews.ts")
# Set the arguments for the actions inputs and out put location.
args = ctx.actions.args()
# Path to the examples for which previews are being generated.
args.add(ctx.attr.example_srcs.label.package)
# Path to the preview map template.
args.add(ctx.file._template_src)
# Path to the ts output file to write to.
args.add(ts_output.path)
ctx.runfiles(files = ctx.files._template_src)
run_node(
ctx = ctx,
inputs = depset(ctx.files.example_srcs + ctx.files._template_src),
executable = "_generate_previews",
outputs = [ts_output],
arguments = [args],
)
# The return value describes what the rule is producing. In this case we need to specify
# the "DefaultInfo" with the output ts file.
return [DefaultInfo(files = depset([ts_output]))]
generate_previews = rule(
# Point to the starlark function that will execute for this rule.
implementation = _generate_previews_impl,
doc = """Rule that generates a map of example previews to their component""",
# The attributes that can be set to this rule.
attrs = {
"example_srcs": attr.label(
doc = """Files used for the previews map generation.""",
),
"_template_src": attr.label(
doc = """The previews map template file to base the generated file on.""",
default = Label("//adev/shared-docs/pipeline/examples/previews:template"),
allow_single_file = True,
),
"_generate_previews": attr.label(
default = Label("//adev/shared-docs/pipeline:previews"),
executable = True,
cfg = "exec",
),
},
)