Skip to content

Commit bfdbdc2

Browse files
alexeaglekara
authored andcommitted
docs(bazel): add skydoc generation (angular#23544)
PR Close angular#23544
1 parent 638ff76 commit bfdbdc2

File tree

8 files changed

+133
-16
lines changed

8 files changed

+133
-16
lines changed

WORKSPACE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ http_archive(
3838
sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
3939
)
4040

41+
http_archive(
42+
name = "io_bazel_rules_sass",
43+
url = "https://github.com/bazelbuild/rules_sass/archive/0.1.0.zip",
44+
strip_prefix = "rules_sass-0.1.0",
45+
sha256 = "b243c4d64f054c174051785862ab079050d90b37a1cef7da93821c6981cb9ad4",
46+
)
47+
4148
# This commit matches the version of buildifier in angular/ngcontainer
4249
# If you change this, also check if it matches the version in the angular/ngcontainer
4350
# version in /.circleci/config.yml
@@ -58,6 +65,14 @@ http_archive(
5865
sha256 = "e373d2ae24955c1254c495c9c421c009d88966565c35e4e8444c082cb1f0f48f",
5966
)
6067

68+
http_archive(
69+
name = "io_bazel_skydoc",
70+
# TODO: switch to upstream when https://github.com/bazelbuild/skydoc/pull/103 is merged
71+
url = "https://github.com/alexeagle/skydoc/archive/fe2e9f888d28e567fef62ec9d4a93c425526d701.zip",
72+
strip_prefix = "skydoc-fe2e9f888d28e567fef62ec9d4a93c425526d701",
73+
sha256 = "7bfb5545f59792a2745f2523b9eef363f9c3e7274791c030885e7069f8116016",
74+
)
75+
6176
# We have a source dependency on the Devkit repository, because it's built with
6277
# Bazel.
6378
# This allows us to edit sources and have the effect appear immediately without
@@ -144,3 +159,12 @@ yarn_install(
144159
package_json = "//tools/http-server:package.json",
145160
yarn_lock = "//tools/http-server:yarn.lock",
146161
)
162+
163+
##################################
164+
# Skylark documentation generation
165+
166+
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
167+
sass_repositories()
168+
169+
load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")
170+
skydoc_repositories()

packages/bazel/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ npm_package(
1414
"package.json",
1515
"//packages/bazel/src:package_assets",
1616
],
17+
packages = ["//packages/bazel/docs"],
1718
# Re-host //packages/bazel/ which is just // in the public distro
1819
replacements = {
1920
"//packages/bazel/": "//",

packages/bazel/docs/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@io_bazel_skydoc//skylark:skylark.bzl", "skylark_doc")
2+
3+
skylark_doc(
4+
name = "docs",
5+
srcs = [
6+
"//packages/bazel/src:ng_module.bzl",
7+
"//packages/bazel/src:ng_rollup_bundle.bzl",
8+
"//packages/bazel/src:ng_setup_workspace.bzl",
9+
"//packages/bazel/src/ng_package:ng_package.bzl",
10+
"//packages/bazel/src/protractor:protractor_web_test.bzl",
11+
],
12+
format = "html",
13+
site_root = "/bazel-builds",
14+
strip_prefix = "packages/bazel/",
15+
visibility = ["//packages/bazel:__subpackages__"],
16+
)

packages/bazel/index.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ ng_package = _ng_package
1919
protractor_web_test = _protractor_web_test
2020
protractor_web_test_suite = _protractor_web_test_suite
2121
ng_setup_workspace = _ng_setup_workspace
22+
# DO NOT ADD PUBLIC API without including in the documentation generation
23+
# Run `bazel build //packages/bazel/docs` to verify

packages/bazel/src/ng_module.bzl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
5-
"""Implementation of the ng_module rule.
5+
"""Run Angular's AOT template compiler
66
"""
77

88
load(":rules_typescript.bzl",
@@ -453,13 +453,21 @@ def _ng_module_impl(ctx):
453453
NG_MODULE_ATTRIBUTES = {
454454
"srcs": attr.label_list(allow_files = [".ts"]),
455455

456-
"deps": attr.label_list(aspects = DEPS_ASPECTS + [_collect_summaries_aspect]),
456+
# Note: DEPS_ASPECTS is already a list, we add the cast to workaround
457+
# https://github.com/bazelbuild/skydoc/issues/21
458+
"deps": attr.label_list(
459+
doc = "Targets that are imported by this target",
460+
aspects = list(DEPS_ASPECTS) + [_collect_summaries_aspect]
461+
),
457462

458-
"assets": attr.label_list(allow_files = [
459-
".css",
460-
# TODO(alexeagle): change this to ".ng.html" when usages updated
461-
".html",
462-
]),
463+
"assets": attr.label_list(
464+
doc = ".html and .css files needed by the Angular compiler",
465+
allow_files = [
466+
".css",
467+
# TODO(alexeagle): change this to ".ng.html" when usages updated
468+
".html",
469+
],
470+
),
463471

464472
"factories": attr.label_list(
465473
allow_files = [".ts", ".html"],
@@ -515,7 +523,13 @@ ng_module = rule(
515523
attrs = NG_MODULE_RULE_ATTRS,
516524
outputs = COMMON_OUTPUTS,
517525
)
526+
"""
527+
Run the Angular AOT template compiler.
518528
529+
This rule extends the [ts_library] rule.
530+
531+
[ts_library]: http://tsetse.info/api/build_defs.html#ts_library
532+
"""
519533

520534
# TODO(alxhub): this rule causes legacy ngc to produce Ivy outputs from global analysis information.
521535
# It exists to facilitate testing of the Ivy runtime until ngtsc is mature enough to be used

packages/bazel/src/ng_package/ng_package.bzl

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
#
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
5-
"""Implementation of the ng_package rule.
5+
"""Package Angular libraries for npm distribution
6+
7+
If all users of an Angular library use Bazel (e.g. internal usage in your company)
8+
then you should simply add your library to the `deps` of the consuming application.
9+
10+
These rules exist for compatibility with non-Bazel consumers of your library.
11+
12+
It packages your library following the Angular Package Format, see the
13+
specification of this format at https://goo.gl/jB3GVv
614
"""
715

816
load("@build_bazel_rules_nodejs//:internal/collect_es6_sources.bzl", "collect_es6_sources")
@@ -352,6 +360,18 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
352360
# some/path/to/my/package/index.js
353361
# we assume the files should be named "package.*.js"
354362
def primary_entry_point_name(name, entry_point, entry_point_name):
363+
"""This is not a public API.
364+
365+
Compute the name of the primary entry point in the library.
366+
367+
Args:
368+
name: the name of the `ng_package` rule, as a fallback.
369+
entry_point: The starting point of the application, see rollup_bundle.
370+
entry_point_name: if set, this is the returned value.
371+
372+
Returns:
373+
name of the entry point, which will appear in the name of generated bundles
374+
"""
355375
if entry_point_name:
356376
# If an explicit entry_point_name is given, use that.
357377
return entry_point_name
@@ -364,6 +384,19 @@ def primary_entry_point_name(name, entry_point, entry_point_name):
364384
return name
365385

366386
def ng_package_outputs(name, entry_point, entry_point_name):
387+
"""This is not a public API.
388+
389+
This function computes the named outputs for an ng_package rule.
390+
391+
Args:
392+
name: value of the name attribute
393+
entry_point: value of the entry_point attribute
394+
entry_point_name: value of the entry_point_name attribute
395+
396+
Returns:
397+
dict of named outputs of the rule
398+
"""
399+
367400
basename = primary_entry_point_name(name, entry_point, entry_point_name)
368401
outputs = {
369402
"fesm5": "fesm5/%s.js" % basename,
@@ -384,3 +417,6 @@ ng_package = rule(
384417
attrs = NG_PACKAGE_ATTRS,
385418
outputs = ng_package_outputs,
386419
)
420+
"""
421+
ng_package produces an npm-ready package from an Angular library.
422+
"""

packages/bazel/src/ng_rollup_bundle.bzl

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55

6-
"""This provides a variant of rollup_bundle that works better for Angular apps.
6+
"""Rollup with Build Optimizer
77
8-
It registers @angular-devkit/build-optimizer as a rollup plugin, to get
8+
This provides a variant of the [rollup_bundle] rule that works better for Angular apps.
9+
10+
It registers `@angular-devkit/build-optimizer` as a rollup plugin, to get
911
better optimization. It also uses ESM5 format inputs, as this is what
1012
build-optimizer is hard-coded to look for and transform.
13+
14+
[rollup_bundle]: https://bazelbuild.github.io/rules_nodejs/rollup/rollup_bundle.html
1115
"""
1216

1317
load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
@@ -51,6 +55,13 @@ def _use_plain_rollup(ctx):
5155

5256

5357
def run_brotli(ctx, input, output):
58+
"""Execute the Brotli compression utility.
59+
60+
Args:
61+
ctx: Bazel's rule execution context
62+
input: any file
63+
output: the compressed file
64+
"""
5465
ctx.actions.run(
5566
executable = ctx.executable._brotli,
5667
inputs = [input],
@@ -126,10 +137,14 @@ def _ng_rollup_bundle(ctx):
126137
ng_rollup_bundle = rule(
127138
implementation = _ng_rollup_bundle,
128139
attrs = dict(ROLLUP_ATTRS, **{
129-
"deps": attr.label_list(aspects = [
130-
rollup_module_mappings_aspect,
131-
esm5_outputs_aspect,
132-
]),
140+
"deps": attr.label_list(
141+
doc = """Other targets that provide JavaScript files.
142+
Typically this will be `ts_library` or `ng_module` targets.""",
143+
aspects = [
144+
rollup_module_mappings_aspect,
145+
esm5_outputs_aspect,
146+
]
147+
),
133148
"_rollup": attr.label(
134149
executable = True,
135150
cfg = "host",
@@ -143,3 +158,13 @@ ng_rollup_bundle = rule(
143158
"build_es5_min_compressed": "%{name}.min.js.br",
144159
}),
145160
)
161+
"""
162+
Run [Rollup] with the [Build Optimizer] plugin.
163+
164+
This rule extends from the [rollup_bundle] rule, so attributes and outputs of
165+
that rule are used here too.
166+
167+
[Rollup]: https://rollupjs.org/
168+
[Build Optimizer]: https://www.npmjs.com/package/@angular-devkit/build-optimizer
169+
[rollup_bundle]: https://bazelbuild.github.io/rules_nodejs/rollup/rollup_bundle.html
170+
"""

packages/bazel/src/protractor/protractor_web_test.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
#
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
5-
"""Implementation of the protractor_web_test and protractor_web_test_suite rules.
6-
"""
5+
"Run end-to-end tests with Protractor"
76

87
load("@build_bazel_rules_nodejs//internal:node.bzl",
98
"sources_aspect",

0 commit comments

Comments
 (0)