Merge branch 'stable-3.2'
* stable-3.2:
Add Polymer 3 support
Change-Id: I471f9087c902385c129789f85c54f79a6f433c3a
diff --git a/gerrit_polymer.bzl b/gerrit_polymer.bzl
index 2d019d2..735d22f 100644
--- a/gerrit_polymer.bzl
+++ b/gerrit_polymer.bzl
@@ -16,3 +16,9 @@
sha256 = "5a589bdba674e1fec7188e9251c8624ebf2d4d969beb6635f9148f420d1e08b1",
urls = ["https://raw.githubusercontent.com/google/closure-compiler/775609aad61e14aef289ebec4bfc09ad88877f9e/contrib/externs/polymer-1.0.js"],
)
+
+ http_archive(
+ name = "build_bazel_rules_nodejs",
+ sha256 = "1134ec9b7baee008f1d54f0483049a97e53a57cd3913ec9d6db625549c98395a",
+ urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.4.0/rules_nodejs-3.4.0.tar.gz"],
+ )
diff --git a/tools/js.bzl b/tools/js.bzl
index 21cfa73..7bd33da 100644
--- a/tools/js.bzl
+++ b/tools/js.bzl
@@ -1,6 +1,10 @@
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library")
load("//lib/js:npm.bzl", "NPM_SHA1S", "NPM_VERSIONS")
+load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
+load("@npm//@bazel/terser:index.bzl", "terser_minified")
+load("@com_googlesource_gerrit_bazlets//tools:genrule2.bzl", "genrule2")
+
NPMJS = "NPMJS"
GERRIT = "GERRIT:"
@@ -519,3 +523,56 @@
name = name,
srcs = static_files,
)
+
+def gerrit_js_bundle(name, srcs, entry_point):
+ """Produces a Gerrit JavaScript bundle archive.
+
+ This rule bundles and minifies the javascript files of a frontend plugin and
+ produces a file archive.
+ Output of this rule is an archive with "${name}.jar" with specific layout for
+ Gerrit frontend plugins. That archive should be provided to gerrit_plugin
+ rule as resource_jars attribute.
+
+ Args:
+ name: Plugin name.
+ srcs: Plugin sources.
+ entry_point: Plugin entry_point.
+ """
+
+ bundle = name + "-bundle"
+ minified = name + ".min"
+ main = name + ".js"
+
+ rollup_bundle(
+ name = bundle,
+ srcs = srcs,
+ entry_point = entry_point,
+ format = "iife",
+ sourcemap = "hidden",
+ )
+
+ terser_minified(
+ name = minified,
+ sourcemap = False,
+ src = bundle,
+ )
+
+ native.genrule(
+ name = name + "_rename_js",
+ srcs = [minified],
+ outs = [main],
+ cmd = "cp $< $@",
+ output_to_bindir = True,
+ )
+
+ genrule2(
+ name = name,
+ srcs = [main],
+ outs = [name + ".jar"],
+ cmd = " && ".join([
+ "mkdir $$TMP/static",
+ "cp $(SRCS) $$TMP/static",
+ "cd $$TMP",
+ "zip -Drq $$ROOT/$@ -g .",
+ ]),
+ )