Simplify scouting bundle

The `babel()` rule dumps its outputs into a directory without telling
bazel about what files are in that directory. That means other rules
are forced to interact with the directory instead of the actual file
we're interested in.

This patch adds a `genrule()` to copy the one file we care about out
of that problematic directory. This lets other rules easily interact
with that one file.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I46233dd47f4bfdc77dfe562e95a0adab20aa20c5
diff --git a/scouting/BUILD b/scouting/BUILD
index c543c17..f58a157 100644
--- a/scouting/BUILD
+++ b/scouting/BUILD
@@ -1,10 +1,5 @@
 load("//tools/build_rules:apache.bzl", "apache_wrapper")
-load("//tools/build_rules:js.bzl", "protractor_ts_test", "turn_files_into_runfiles")
-
-turn_files_into_runfiles(
-    name = "main_bundle_compiled_runfiles",
-    files = "//scouting/www:main_bundle_compiled",
-)
+load("//tools/build_rules:js.bzl", "protractor_ts_test")
 
 sh_binary(
     name = "scouting",
@@ -12,7 +7,6 @@
         "scouting.sh",
     ],
     data = [
-        ":main_bundle_compiled_runfiles",
         "//scouting/webserver",
         "//scouting/www:static_files",
     ],
diff --git a/scouting/www/BUILD b/scouting/www/BUILD
index e33416b..aba70bf 100644
--- a/scouting/www/BUILD
+++ b/scouting/www/BUILD
@@ -53,7 +53,17 @@
         "@npm//@angular/compiler-cli",
     ],
     output_dir = True,
-    visibility = ["//visibility:public"],
+)
+
+# The babel() rule above puts everything into a directory without telling bazel
+# what's in the directory. That makes it annoying to work with from other
+# rules. This genrule() here copies the one file in the directory we care about
+# so that other rules have an easier time using the file.
+genrule(
+    name = "main_bundle_file",
+    srcs = [":main_bundle_compiled"],
+    outs = ["main_bundle_file.js"],
+    cmd = "cp $(location :main_bundle_compiled)/main_bundle.js $(OUTS)",
 )
 
 # Create a copy of zone.js here so that we can have a predictable path to
@@ -84,6 +94,7 @@
     srcs = [
         "index.html",
         ":field_pictures_copy",
+        ":main_bundle_file.js",
         ":zonejs_copy",
     ],
     visibility = ["//visibility:public"],
diff --git a/scouting/www/index.html b/scouting/www/index.html
index 84777d1..c9e2bb3 100644
--- a/scouting/www/index.html
+++ b/scouting/www/index.html
@@ -14,6 +14,6 @@
   </head>
   <body>
     <my-app></my-app>
-    <script src="./main_bundle_compiled/main_bundle.js"></script>
+    <script src="./main_bundle_file.js"></script>
   </body>
 </html>
diff --git a/tools/build_rules/js.bzl b/tools/build_rules/js.bzl
index eeb5594..f5a7543 100644
--- a/tools/build_rules/js.bzl
+++ b/tools/build_rules/js.bzl
@@ -63,25 +63,6 @@
     },
 )
 
-# Some rules (e.g. babel()) do not expose their files as runfiles. So we need
-# to do this step manually.
-def _turn_files_into_runfiles_impl(ctx):
-    files = ctx.attr.files.files
-    return [DefaultInfo(
-        files = files,
-        runfiles = ctx.runfiles(transitive_files = files),
-    )]
-
-turn_files_into_runfiles = rule(
-    implementation = _turn_files_into_runfiles_impl,
-    attrs = {
-        "files": attr.label(
-            mandatory = True,
-            doc = "The target whose files should be turned into runfiles.",
-        ),
-    },
-)
-
 def protractor_ts_test(name, srcs, deps = None, **kwargs):
     """Wraps upstream protractor_web_test_suite() to reduce boilerplate.