blob: 6e1f63a14bcc818240cac67596be8210b30e8015 [file] [log] [blame]
load("//tools/bzl:genrule2.bzl", "genrule2")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
def polygerrit_bundle(name, srcs, outs, entry_point):
"""Build .zip bundle from source code
Args:
name: rule name
srcs: source files
outs: array with a single item - the output file name
entry_point: application entry-point
"""
app_name = entry_point.split(".html")[0].split("/").pop() # eg: gr-app
native.filegroup(
name = app_name + "-full-src",
srcs = srcs + [
"@ui_npm//:node_modules",
],
)
rollup_bundle(
name = app_name + "-bundle-js",
srcs = [app_name + "-full-src"],
config_file = ":rollup.config.js",
entry_point = "elements/" + app_name + ".js",
rollup_bin = "//tools/node_tools:rollup-bin",
sourcemap = "hidden",
deps = [
"@tools_npm//rollup-plugin-node-resolve",
],
)
native.filegroup(
name = name + "_app_sources",
srcs = [
app_name + "-bundle-js.js",
entry_point,
],
)
native.filegroup(
name = name + "_css_sources",
srcs = native.glob(["styles/**/*.css"]),
)
native.filegroup(
name = name + "_theme_sources",
srcs = native.glob(
["styles/themes/*.html"],
# app-theme.html already included via an import in gr-app.html.
exclude = ["styles/themes/app-theme.html"],
),
)
native.filegroup(
name = name + "_top_sources",
srcs = [
"favicon.ico",
],
)
# Preserve bower_components directory in the final directory layout to
# avoid plugins break
genrule2(
name = name,
srcs = [
name + "_app_sources",
name + "_css_sources",
name + "_theme_sources",
name + "_top_sources",
"//lib/fonts:robotofonts",
"//lib/js:highlightjs__files",
"@ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js",
"@ui_npm//@polymer/font-roboto-local",
"@ui_npm//:node_modules/@polymer/font-roboto-local/package.json",
],
outs = outs,
cmd = " && ".join([
"FONT_DIR=$$(dirname $(location @ui_npm//:node_modules/@polymer/font-roboto-local/package.json))/fonts",
"mkdir -p $$TMP/polygerrit_ui/{styles/themes,fonts/{roboto,robotomono},bower_components/{highlightjs,webcomponentsjs},elements}",
"for f in $(locations " + name + "_app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/" + app_name + ".$$ext; done",
"cp $(locations //lib/fonts:robotofonts) $$TMP/polygerrit_ui/fonts/",
"for f in $(locations " + name + "_top_sources); do cp $$f $$TMP/polygerrit_ui/; done",
"for f in $(locations " + name + "_css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done",
"for f in $(locations " + name + "_theme_sources); do cp $$f $$TMP/polygerrit_ui/styles/themes; done",
"for f in $(locations //lib/js:highlightjs__files); do cp $$f $$TMP/polygerrit_ui/bower_components/highlightjs/ ; done",
"cp $(location @ui_npm//:node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js) $$TMP/polygerrit_ui/bower_components/webcomponentsjs/webcomponents-lite.js",
"cp $$FONT_DIR/roboto/*.ttf $$TMP/polygerrit_ui/fonts/roboto/",
"cp $$FONT_DIR/robotomono/*.ttf $$TMP/polygerrit_ui/fonts/robotomono/",
"cd $$TMP",
"find . -exec touch -t 198001010000 '{}' ';'",
"zip -qr $$ROOT/$@ *",
]),
)