Replace vulcanize with bundle_assets build rule

New rule uses polymer-bundler instead of deprecated vulcanize.
Also use this rule to package UI plugins.
Also for combining PolyGerrit UI.

Feature: Issue 7144
Change-Id: I17380c670fe4a980dc9748b356e7df18aebdb4ca
diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl
index 68a929f..d6d0c95 100644
--- a/tools/bzl/js.bzl
+++ b/tools/bzl/js.bzl
@@ -286,38 +286,38 @@
     },
 )
 
-"""Groups a set of bower components together in a zip file.
+def _bundle_impl(ctx):
+    """Groups a set of .html and .js together in a zip file.
 
-Outputs:
-  NAME-versions.json:
-    a JSON file containing a PKG-NAME => PKG-NAME#VERSION mapping for the
-    transitive dependencies.
-  NAME.zip:
-    a zip file containing the transitive dependencies for this bundle.
-"""
+    Outputs:
+      NAME-versions.json:
+        a JSON file containing a PKG-NAME => PKG-NAME#VERSION mapping for the
+        transitive dependencies.
+    NAME.zip:
+      a zip file containing the transitive dependencies for this bundle.
+    """
 
-def _vulcanize_impl(ctx):
     # intermediate artifact if split is wanted.
     if ctx.attr.split:
-        vulcanized = ctx.new_file(
+        bundled = ctx.new_file(
             ctx.configuration.genfiles_dir,
             ctx.outputs.html,
-            ".vulcanized.html",
+            ".bundled.html",
         )
     else:
-        vulcanized = ctx.outputs.html
+        bundled = ctx.outputs.html
     destdir = ctx.outputs.html.path + ".dir"
     zips = [z for d in ctx.attr.deps for z in d.transitive_zipfiles]
 
     hermetic_npm_binary = " ".join([
         "python",
         "$p/" + ctx.file._run_npm.path,
-        "$p/" + ctx.file._vulcanize_archive.path,
+        "$p/" + ctx.file._bundler_archive.path,
         "--inline-scripts",
         "--inline-css",
         "--strip-comments",
-        "--out-html",
-        "$p/" + vulcanized.path,
+        "--out-file",
+        "$p/" + bundled.path,
         ctx.file.app.path,
     ])
 
@@ -346,13 +346,13 @@
         use_default_shell_env = True,
     )
     ctx.actions.run_shell(
-        mnemonic = "Vulcanize",
+        mnemonic = "Bundle",
         inputs = [
             ctx.file._run_npm,
             ctx.file.app,
-            ctx.file._vulcanize_archive,
+            ctx.file._bundler_archive,
         ] + list(zips) + ctx.files.srcs,
-        outputs = [vulcanized],
+        outputs = [bundled],
         command = cmd,
         **node_tweaks
     )
@@ -364,7 +364,7 @@
             ctx.file._crisper_archive.path,
             "--always-write-script",
             "--source",
-            vulcanized.path,
+            bundled.path,
             "--html",
             ctx.outputs.html.path,
             "--js",
@@ -377,22 +377,22 @@
                 ctx.file._run_npm,
                 ctx.file.app,
                 ctx.file._crisper_archive,
-                vulcanized,
+                bundled,
             ],
             outputs = [ctx.outputs.js, ctx.outputs.html],
             command = hermetic_npm_command,
             **node_tweaks
         )
 
-def _vulcanize_output_func(name, split):
+def _bundle_output_func(name, split):
     _ignore = [name]  # unused.
     out = {"html": "%{name}.html"}
     if split:
         out["js"] = "%{name}.js"
     return out
 
-_vulcanize_rule = rule(
-    _vulcanize_impl,
+_bundle_rule = rule(
+    _bundle_impl,
     attrs = {
         "deps": attr.label_list(providers = ["transitive_zipfiles"]),
         "app": attr.label(
@@ -412,8 +412,8 @@
             default = Label("//tools/js:run_npm_binary.py"),
             allow_single_file = True,
         ),
-        "_vulcanize_archive": attr.label(
-            default = Label("@vulcanize//:%s" % _npm_tarball("vulcanize")),
+        "_bundler_archive": attr.label(
+            default = Label("@polymer-bundler//:%s" % _npm_tarball("polymer-bundler")),
             allow_single_file = True,
         ),
         "_crisper_archive": attr.label(
@@ -421,12 +421,12 @@
             allow_single_file = True,
         ),
     },
-    outputs = _vulcanize_output_func,
+    outputs = _bundle_output_func,
 )
 
-def vulcanize(*args, **kwargs):
-    """Vulcanize runs vulcanize and (optionally) crisper on a set of sources."""
-    _vulcanize_rule(*args, pkg = PACKAGE_NAME, **kwargs)
+def bundle_assets(*args, **kwargs):
+    """Combine html, js, css files and optionally split into js and html bundles."""
+    _bundle_rule(*args, pkg = PACKAGE_NAME, **kwargs)
 
 def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
     """Bundles plugin dependencies for deployment.
@@ -443,7 +443,7 @@
     """
 
     # Combines all .js and .html files into foo_combined.js and foo_combined.html
-    _vulcanize_rule(
+    _bundle_rule(
         name = name + "_combined",
         app = app,
         srcs = srcs if app in srcs else srcs + [app],