blob: 647af14738e897e97aa90f0e8577d4da67446584 [file] [log] [blame]
Philipp Schrader54047962022-02-16 21:05:11 -08001load("@npm//@bazel/typescript:index.bzl", "ts_library")
Alex Perryb3168082022-01-22 13:36:13 -08002load("//tools/build_rules:js.bzl", "rollup_bundle")
Alex Perryb3168082022-01-22 13:36:13 -08003load("@npm//@babel/cli:index.bzl", "babel")
4
Philipp Schrader54047962022-02-16 21:05:11 -08005ts_library(
Alex Perryb3168082022-01-22 13:36:13 -08006 name = "app",
7 srcs = glob([
8 "*.ts",
Philipp Schrader54047962022-02-16 21:05:11 -08009 ]),
10 angular_assets = glob([
Alex Perryb3168082022-01-22 13:36:13 -080011 "*.ng.html",
Philipp Schrader80587432022-03-05 15:41:22 -080012 "*.css",
Alex Perryb3168082022-01-22 13:36:13 -080013 ]),
Philipp Schrader54047962022-02-16 21:05:11 -080014 compiler = "//tools:tsc_wrapped_with_angular",
15 target_compatible_with = ["@platforms//cpu:x86_64"],
16 use_angular_plugin = True,
Alex Perryb3168082022-01-22 13:36:13 -080017 visibility = ["//visibility:public"],
18 deps = [
Philipp Schrader80587432022-03-05 15:41:22 -080019 "//scouting/www/entry",
Philipp Schrader72beced2022-03-07 05:29:52 -080020 "//scouting/www/import_match_list",
Ravago Jones2813c032022-03-16 23:44:11 -070021 "//scouting/www/match_list",
Alex Perrybb901052022-03-23 19:46:15 -070022 "//scouting/www/notes",
Milo Lin26b2cbb2022-03-26 17:35:20 -070023 "//scouting/www/shift_schedule",
Alex Perryb3168082022-01-22 13:36:13 -080024 "@npm//@angular/animations",
25 "@npm//@angular/common",
Alex Perryb3168082022-01-22 13:36:13 -080026 "@npm//@angular/core",
27 "@npm//@angular/platform-browser",
28 ],
29)
30
31rollup_bundle(
32 name = "main_bundle",
33 entry_point = "main.ts",
34 deps = [
35 "app",
36 ],
37)
38
39babel(
40 name = "main_bundle_compiled",
41 args = [
Alex Perrya96eb6a2022-04-02 17:05:17 -070042 "$(execpath :main_bundle.min.js)",
Alex Perryb3168082022-01-22 13:36:13 -080043 "--no-babelrc",
44 "--source-maps",
Alex Perry7ed62bf2022-04-02 13:33:58 -070045 "--minified",
46 "--no-comments",
Alex Perryb3168082022-01-22 13:36:13 -080047 "--plugins=@angular/compiler-cli/linker/babel",
48 "--out-dir",
49 "$(@D)",
50 ],
51 data = [
Alex Perrya96eb6a2022-04-02 17:05:17 -070052 ":main_bundle.min.js",
Alex Perryb3168082022-01-22 13:36:13 -080053 "@npm//@angular/compiler-cli",
54 ],
55 output_dir = True,
Philipp Schraderbc38b4e2022-04-02 15:47:23 -070056)
57
58# The babel() rule above puts everything into a directory without telling bazel
59# what's in the directory. That makes it annoying to work with from other
60# rules. This genrule() here copies the one file in the directory we care about
61# so that other rules have an easier time using the file.
62genrule(
63 name = "main_bundle_file",
64 srcs = [":main_bundle_compiled"],
65 outs = ["main_bundle_file.js"],
Alex Perrya96eb6a2022-04-02 17:05:17 -070066 cmd = "cp $(location :main_bundle_compiled)/main_bundle.min.js $(OUTS)",
Philipp Schrader684a8e82022-02-25 17:39:28 -080067)
68
Philipp Schrader45721a72022-04-02 16:27:53 -070069py_binary(
70 name = "index_html_generator",
71 srcs = ["index_html_generator.py"],
72)
73
74genrule(
75 name = "generate_index_html",
76 srcs = [
77 "index.template.html",
78 "main_bundle_file.js",
79 ],
80 outs = ["index.html"],
81 cmd = " ".join([
82 "$(location :index_html_generator)",
83 "--template $(location index.template.html)",
84 "--bundle $(location main_bundle_file.js)",
85 "--output $(location index.html)",
86 ]),
87 tools = [
88 ":index_html_generator",
89 ],
90)
91
Philipp Schrader684a8e82022-02-25 17:39:28 -080092# Create a copy of zone.js here so that we can have a predictable path to
93# source it from on the webserver.
94genrule(
95 name = "zonejs_copy",
96 srcs = [
97 "@npm//:node_modules/zone.js/dist/zone.min.js",
98 ],
99 outs = [
100 "npm/node_modules/zone.js/dist/zone.min.js",
101 ],
102 cmd = "cp $(SRCS) $(OUTS)",
Philipp Schrader577befe2022-03-15 00:00:49 -0700103)
104
105genrule(
106 name = "field_pictures_copy",
107 srcs = ["//third_party/y2022/field:pictures"],
108 outs = [
109 "pictures/field/balls.jpeg",
110 "pictures/field/quadrants.jpeg",
111 ],
112 cmd = "cp $(SRCS) $(@D)/pictures/field/",
113)
114
115filegroup(
116 name = "static_files",
117 srcs = [
118 "index.html",
119 ":field_pictures_copy",
Philipp Schraderbc38b4e2022-04-02 15:47:23 -0700120 ":main_bundle_file.js",
Philipp Schrader577befe2022-03-15 00:00:49 -0700121 ":zonejs_copy",
122 ],
Philipp Schrader684a8e82022-02-25 17:39:28 -0800123 visibility = ["//visibility:public"],
Alex Perryb3168082022-01-22 13:36:13 -0800124)
125
Philipp Schrader72beced2022-03-07 05:29:52 -0800126filegroup(
127 name = "common_css",
128 srcs = ["common.css"],
129 visibility = ["//scouting/www:__subpackages__"],
130)