Skip to content

Commit e8a0641

Browse files
committed
build: reduce manual setup for entry-points of packages
Reduces the manual setup for entry-poitns of packages. With this change, we no longer need to update the dev-app system config if we add/remove entry-points. We basically only need to configure entry-points in the `config.bzl` file. Though this is not 100% complete yet, because we still have legacy karma tests which need another system config. The bazel karma tests do not need this anymore.
1 parent 2f197cd commit e8a0641

File tree

3 files changed

+47
-65
lines changed

3 files changed

+47
-65
lines changed

src/dev-app/BUILD.bazel

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
4+
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_ENTRYPOINTS")
5+
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS")
6+
load("//src/material-experimental:config.bzl", "MATERIAL_EXPERIMENTAL_ENTRYPOINTS")
37
load("//tools:defaults.bzl", "ng_module", "sass_binary")
8+
load("//tools/bazel:expand_template.bzl", "expand_template")
49
load("//tools/dev-server:index.bzl", "dev_server")
510

611
ng_module(
@@ -92,13 +97,25 @@ sass_binary(
9297
],
9398
)
9499

100+
expand_template(
101+
name = "system-config",
102+
output_name = "system-config.js",
103+
substitutions = {
104+
"$CDK_ENTRYPOINTS_TMPL": str(CDK_ENTRYPOINTS),
105+
"$CDK_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(CDK_EXPERIMENTAL_ENTRYPOINTS),
106+
"$MATERIAL_ENTRYPOINTS_TMPL": str(MATERIAL_ENTRYPOINTS),
107+
"$MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(MATERIAL_EXPERIMENTAL_ENTRYPOINTS),
108+
},
109+
template = "system-config-tmpl.js",
110+
)
111+
95112
dev_server(
96113
name = "devserver",
97114
srcs = [
98115
"favicon.ico",
99116
"index.html",
100-
"system-config.js",
101117
"system-rxjs-operators.js",
118+
":system-config",
102119
":theme",
103120
"//src/dev-app/icon:icon_demo_assets",
104121
"@npm//:node_modules/@material/animation/dist/mdc.animation.js",

src/dev-app/system-config.js renamed to src/dev-app/system-config-tmpl.js

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,14 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// Note that this file isn't being transpiled so we need to keep it in ES5.
10-
11-
var CDK_PACKAGES = [
12-
'a11y',
13-
'accordion',
14-
'bidi',
15-
'clipboard',
16-
'coercion',
17-
'collections',
18-
'drag-drop',
19-
'keycodes',
20-
'layout',
21-
'observers',
22-
'overlay',
23-
'platform',
24-
'portal',
25-
'scrolling',
26-
'stepper',
27-
'table',
28-
'text-field',
29-
'tree',
30-
];
31-
32-
var CDK_EXPERIMENTAL_PACKAGES = [
33-
'dialog',
34-
'popover-edit',
35-
'scrolling',
36-
];
37-
38-
var MATERIAL_PACKAGES = [
39-
'autocomplete', 'badge',
40-
'bottom-sheet', 'button',
41-
'button-toggle', 'card',
42-
'checkbox', 'chips',
43-
'core', 'datepicker',
44-
'dialog', 'divider',
45-
'expansion', 'form-field',
46-
'grid-list', 'icon',
47-
'input', 'list',
48-
'menu', 'paginator',
49-
'progress-bar', 'progress-spinner',
50-
'radio', 'select',
51-
'sidenav', 'slide-toggle',
52-
'slider', 'snack-bar',
53-
'sort', 'stepper',
54-
'table', 'tabs',
55-
'toolbar', 'tooltip',
56-
'tree',
57-
];
58-
59-
var MATERIAL_EXPERIMENTAL_PACKAGES = [
60-
'mdc-button',
61-
'mdc-card',
62-
'mdc-checkbox',
63-
'mdc-chips',
64-
'mdc-tabs',
65-
'mdc-helpers',
66-
'mdc-menu',
67-
'mdc-radio',
68-
'mdc-progress-bar',
69-
'mdc-slide-toggle',
70-
'mdc-slider',
71-
'popover-edit',
72-
];
9+
// Note that this file isn't being transpiled so we need to keep it in ES5. Also
10+
// identifiers of the format "$NAME_TMPL" will be replaced by the Bazel rule that
11+
// converts this template file into the actual SystemJS configuration file.
12+
13+
var CDK_PACKAGES = $CDK_ENTRYPOINTS_TMPL;
14+
var CDK_EXPERIMENTAL_PACKAGES = $CDK_EXPERIMENTAL_ENTRYPOINTS_TMPL;
15+
var MATERIAL_PACKAGES = $MATERIAL_ENTRYPOINTS_TMPL;
16+
var MATERIAL_EXPERIMENTAL_PACKAGES = $MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL;
7317

7418
/** Bazel runfile path referring to the "src/" folder of the project. */
7519
var srcRunfilePath = 'angular_material/src';

tools/bazel/expand_template.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Implementation of the expand_template rule """
2+
3+
def expand_template_impl(ctx):
4+
ctx.actions.expand_template(
5+
template = ctx.file.template,
6+
output = ctx.outputs.output_name,
7+
substitutions = ctx.attr.substitutions,
8+
)
9+
10+
"""
11+
Rule that can be used to output a file from a specified
12+
template by applying given substitutions.
13+
"""
14+
expand_template = rule(
15+
implementation = expand_template_impl,
16+
attrs = {
17+
"output_name": attr.output(mandatory = True),
18+
"substitutions": attr.string_dict(mandatory = True),
19+
"template": attr.label(mandatory = True, allow_single_file = True),
20+
},
21+
)

0 commit comments

Comments
 (0)