blob: 6c391e270daede45a4534ff8434ff99011d3253b [file] [log] [blame]
Sean Condon6a6f9a02020-01-09 14:09:36 +00001"""
2 Copyright ${year}-present Open Networking Foundation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15"""
16
17package(default_visibility = ["//visibility:public"])
18
19load("@npm_angular_bazel//:index.bzl", "ng_module")
20load("@npm_bazel_karma//:index.bzl", "karma_web_test_suite")
21load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
22load("@npm//history-server:index.bzl", "history_server")
23load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
24load("@npm_bazel_terser//:index.bzl", "terser_minified")
25load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")
26load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary", "sass_binary")
27
28sass_binary(
29 name = "global_stylesheet",
30 src = glob([
31 "styles.css",
32 "styles.scss",
33 ])[0],
34 output_name = "global_stylesheet.css",
35)
36
37multi_sass_binary(
38 name = "styles",
39 srcs = glob(
40 include = ["**/*.scss"],
41 exclude = ["styles.scss"],
42 ),
43)
44
45ng_module(
46 name = "src",
47 srcs = glob(
48 include = ["**/*.ts"],
49 exclude = [
50 "**/*.spec.ts",
51 "main.ts",
52 "test.ts",
53 "initialize_testbed.ts",
54 ],
55 ),
56 assets = glob([
57 "**/*.css",
58 "**/*.html",
59 ]) + ([":styles"] if len(glob(["**/*.scss"])) else []),
60 generate_ve_shims = True,
61 deps = [
62 "@npm//@angular/core",
63 "@npm//@angular/platform-browser",
64 "@npm//@angular/router",
65 "@npm//@types",
66 "@npm//d3",
67 "@npm//gui2-fw-lib",
68 "@npm//rxjs",
69 ],
70)
71
72rollup_bundle(
73 name = "bundle",
74 config_file = "rollup.config.js",
75 entry_point = ":main.prod.ts",
76 deps = [
77 "//src",
78 "@npm//rollup-plugin-commonjs",
79 "@npm//rollup-plugin-node-resolve",
80 ],
81)
82
83terser_minified(
84 name = "bundle.min",
85 src = ":bundle",
86)
87
88pkg_web(
89 name = "prodapp",
90 srcs = [
91 # do not sort
92 "favicon.ico",
93 ":bundle.min",
94 "index.html",
95 ":global_stylesheet",
96 ],
97)
98
99history_server(
100 name = "prodserver",
101 data = [":prodapp"],
102 templated_args = ["src/prodapp"],
103)
104
105filegroup(
106 name = "rxjs_umd_modules",
107 srcs = [
108 # do not sort
109 "@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
110 ":rxjs_shims.js",
111 ],
112)
113
114ts_devserver(
115 name = "devserver",
116 entry_module = "project/src/main.dev",
117 port = 4200,
118 scripts = [
119 "@npm//:node_modules/tslib/tslib.js",
120 ":rxjs_umd_modules",
121 ],
122 serving_path = "/bundle.min.js",
123 static_files = [
124 "@npm//:node_modules/zone.js/dist/zone.min.js",
125 ":global_stylesheet",
126 ],
127 deps = [":src"],
128)
129
130ts_library(
131 name = "test_lib",
132 testonly = 1,
133 srcs = glob(["**/*.spec.ts"]),
134 deps = [
135 ":src",
136 "@npm//@angular/core",
137 "@npm//@angular/router",
138 "@npm//@types",
139 ],
140)
141
142ts_library(
143 name = "initialize_testbed",
144 testonly = 1,
145 srcs = [
146 "initialize_testbed.ts",
147 ],
148 deps = [
149 "@npm//@angular/core",
150 "@npm//@angular/platform-browser-dynamic",
151 "@npm//@types",
152 ],
153)
154
155karma_web_test_suite(
156 name = "test",
157 srcs = [
158 "@npm//:node_modules/tslib/tslib.js",
159 ],
160 # do not sort
161 bootstrap = [
162 "@npm//:node_modules/zone.js/dist/zone-testing-bundle.js",
163 "@npm//:node_modules/reflect-metadata/Reflect.js",
164 ],
165 browsers = [
166 "@io_bazel_rules_webtesting//browsers:firefox-local",
167 ],
168 tags = ["native"],
169 runtime_deps = [
170 ":initialize_testbed",
171 ],
172 deps = [
173 ":rxjs_umd_modules",
174 ":test_lib",
175 ],
176)