-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathngsw_config.bzl
More file actions
47 lines (40 loc) · 1.26 KB
/
Copy pathngsw_config.bzl
File metadata and controls
47 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
def ngsw_config(name, config, index_html, src, out = None, **kwargs):
"""Creates ngsw.json with service worker configuration and hashes for all source files"
Args:
name: name
config: ngsw.config.json file
index_html: index.html file
src: pkg_web assets
out: out file
**kwargs:
Credits: https://github.com/marcus-sa
"""
if not out:
out = name
ngsw_config_name = "%s_bin" % name
nodejs_binary(
name = ngsw_config_name,
data = ["@npm//@angular/service-worker", index_html, config, src],
visibility = ["//visibility:private"],
entry_point = "@npm//:node_modules/@angular/service-worker/ngsw-config.js",
)
cmd = """
mkdir -p $@
cp -R $(locations {TMPL_src})/. $@/
cp $(location {TMPL_index}) $@/index.html
$(location :{TMPL_bin}) $@ $(location {TMPL_conf})
""".format(
TMPL_src = src,
TMPL_bin = ngsw_config_name,
TMPL_index = index_html,
TMPL_conf = config,
)
native.genrule(
name = "generate_%s" % name,
outs = [out],
srcs = [src, config, index_html],
tools = [ngsw_config_name],
cmd = cmd,
**kwargs
)