Merge "Bazel: Migrate to gerrit_js_bundle rule" into main
diff --git a/.eslintignore b/.eslintignore
deleted file mode 100644
index e69de29..0000000
--- a/.eslintignore
+++ /dev/null
diff --git a/.eslintrc.json b/.eslintrc.json
deleted file mode 100644
index 8adc172..0000000
--- a/.eslintrc.json
+++ /dev/null
@@ -1,238 +0,0 @@
-{
-    "extends": [
-        "eslint:recommended",
-        "google"
-    ],
-    "parserOptions": {
-        "ecmaVersion": 2018,
-        "sourceType": "module"
-    },
-    "env": {
-        "browser": true,
-        "es6": true
-    },
-    "globals": {
-        "__dirname": false,
-        "app": false,
-        "page": false,
-        "Polymer": false,
-        "process": false,
-        "require": false,
-        "Gerrit": false,
-        "Promise": false,
-        "assert": false,
-        "test": false,
-        "flushAsynchronousOperations": false
-    },
-    "rules": {
-        "arrow-parens": [
-            "error",
-            "as-needed"
-        ],
-        "block-spacing": [
-            "error",
-            "always"
-        ],
-        "brace-style": [
-            "error",
-            "1tbs",
-            {
-                "allowSingleLine": true
-            }
-        ],
-        "camelcase": "off",
-        "comma-dangle": [
-            "error",
-            {
-                "arrays": "always-multiline",
-                "objects": "always-multiline",
-                "imports": "always-multiline",
-                "exports": "always-multiline",
-                "functions": "never"
-            }
-        ],
-        "eol-last": "off",
-        "indent": [
-            "error",
-            2,
-            {
-                "MemberExpression": 2,
-                "FunctionDeclaration": {
-                    "body": 1,
-                    "parameters": 2
-                },
-                "FunctionExpression": {
-                    "body": 1,
-                    "parameters": 2
-                },
-                "CallExpression": {
-                    "arguments": 2
-                },
-                "ArrayExpression": 1,
-                "ObjectExpression": 1,
-                "SwitchCase": 1
-            }
-        ],
-        "keyword-spacing": [
-            "error",
-            {
-                "after": true,
-                "before": true
-            }
-        ],
-        "lines-between-class-members": [
-            "error",
-            "always"
-        ],
-        "max-len": [
-            "error",
-            80,
-            2,
-            {
-                "ignoreComments": true,
-                "ignorePattern": "^import .*;$"
-            }
-        ],
-        "new-cap": [
-            "error",
-            {
-                "capIsNewExceptions": [
-                    "Polymer",
-                    "LegacyElementMixin",
-                    "GestureEventListeners",
-                    "LegacyDataMixin"
-                ]
-            }
-        ],
-        "no-console": "off",
-        "no-multiple-empty-lines": [
-            "error",
-            {
-                "max": 1
-            }
-        ],
-        "no-prototype-builtins": "off",
-        "no-redeclare": "off",
-        "no-restricted-syntax": [
-            "error",
-            {
-                "selector": "ExpressionStatement > CallExpression > MemberExpression[object.name='test'][property.name='only']",
-                "message": "Remove test.only."
-            },
-            {
-                "selector": "ExpressionStatement > CallExpression > MemberExpression[object.name='suite'][property.name='only']",
-                "message": "Remove suite.only."
-            }
-        ],
-        "no-undef": "off",
-        "no-useless-escape": "off",
-        "no-var": "error",
-        "object-shorthand": [
-            "error",
-            "always"
-        ],
-        "padding-line-between-statements": [
-            "error",
-            {
-                "blankLine": "always",
-                "prev": "class",
-                "next": "*"
-            },
-            {
-                "blankLine": "always",
-                "prev": "*",
-                "next": "class"
-            }
-        ],
-        "prefer-arrow-callback": "error",
-        "prefer-const": "error",
-        "prefer-spread": "error",
-        "quote-props": [
-            "error",
-            "consistent-as-needed"
-        ],
-        "require-jsdoc": "off",
-        "semi": [
-            2,
-            "always"
-        ],
-        "template-curly-spacing": "error",
-        "valid-jsdoc": "off",
-        "require-jsdoc": 0,
-        "valid-jsdoc": 0,
-        "jsdoc/check-alignment": 2,
-        "jsdoc/check-examples": 0,
-        "jsdoc/check-indentation": 0,
-        "jsdoc/check-param-names": 0,
-        "jsdoc/check-syntax": 0,
-        "jsdoc/check-tag-names": 0,
-        "jsdoc/check-types": 0,
-        "jsdoc/implements-on-classes": 2,
-        "jsdoc/match-description": 0,
-        "jsdoc/newline-after-description": 2,
-        "jsdoc/no-types": 0,
-        "jsdoc/no-undefined-types": 0,
-        "jsdoc/require-description": 0,
-        "jsdoc/require-description-complete-sentence": 0,
-        "jsdoc/require-example": 0,
-        "jsdoc/require-hyphen-before-param-description": 0,
-        "jsdoc/require-jsdoc": 0,
-        "jsdoc/require-param": 0,
-        "jsdoc/require-param-description": 0,
-        "jsdoc/require-param-name": 2,
-        "jsdoc/require-param-type": 2,
-        "jsdoc/require-returns": 0,
-        "jsdoc/require-returns-check": 0,
-        "jsdoc/require-returns-description": 0,
-        "jsdoc/require-returns-type": 2,
-        "jsdoc/valid-types": 2,
-        "jsdoc/require-file-overview": [
-            "error",
-            {
-                "tags": {
-                    "license": {
-                        "mustExist": true,
-                        "preventDuplicates": true
-                    }
-                }
-            }
-        ],
-        "import/named": 2,
-        "import/no-unresolved": 2,
-        "import/no-self-import": 2,
-        // The no-cycle rule is slow, because it doesn't cache dependencies.
-        // Disable it.
-        "import/no-cycle": 0,
-        "import/no-useless-path-segments": 2,
-        "import/no-unused-modules": 2,
-        "import/no-default-export": 2
-    },
-    "plugins": [
-        "html",
-        "jsdoc",
-        "import"
-    ],
-    "settings": {
-        "html/report-bad-indent": "error"
-    },
-    "overrides": [
-        {
-            "files": [
-                "*_html.js",
-                "*-styles.js",
-                "externs.js"
-            ],
-            "rules": {
-                "max-len": "off"
-            }
-        },
-        {
-            "files": [
-                "*.html"
-            ],
-            "rules": {
-                "jsdoc/require-file-overview": "off"
-            }
-        }
-    ]
-}
diff --git a/BUILD b/BUILD
index 0c21d23..16b543e 100644
--- a/BUILD
+++ b/BUILD
@@ -1,7 +1,4 @@
-load("//tools/bzl:genrule2.bzl", "genrule2")
-load("//tools/bzl:js.bzl", "polygerrit_plugin")
 load("//tools/bzl:plugin.bzl", "gerrit_plugin")
-load("//tools/js:eslint.bzl", "eslint")
 
 gerrit_plugin(
     name = "zuul-results-summary",
@@ -12,46 +9,7 @@
         "Implementation-Title: Zuul-Results-Summary plugin",
         "Implementation-URL: https://gerrit.googlesource.com/plugins/zuul-results-summary",
     ],
-    resource_jars = [":zuul-results-summary-static"],
+    resource_jars = ["//plugins/zuul-results-summary/web:zuul-results-summary"],
     resource_strip_prefix = "plugins/zuul-results-summary/resources",
     resources = glob(["resources/**/*"]),
 )
-
-genrule2(
-    name = "zuul-results-summary-static",
-    srcs = [":zuul-results-summary-ui"],
-    outs = ["zuul-results-summary-static.jar"],
-    cmd = " && ".join([
-        "mkdir $$TMP/static",
-        "cp -r $(locations :zuul-results-summary-ui) $$TMP/static",
-        "cd $$TMP",
-        "zip -Drq $$ROOT/$@ -g .",
-    ]),
-)
-
-polygerrit_plugin(
-    name = "zuul-results-summary-ui",
-    app = "zuul-results-summary/zuul-results-summary.js",
-    plugin_name = "zuul-results-summary",
-)
-
-# Define the eslinter for the plugin
-# The eslint macro creates 2 rules: lint_test and lint_bin
-eslint(
-    name = "lint",
-    srcs = glob([
-        "zuul-results-summary/**/*.js",
-    ]),
-    config = ".eslintrc.json",
-    data = [],
-    extensions = [
-        ".js",
-    ],
-    ignore = ".eslintignore",
-    plugins = [
-        "@npm//eslint-config-google",
-        "@npm//eslint-plugin-html",
-        "@npm//eslint-plugin-import",
-        "@npm//eslint-plugin-jsdoc",
-    ],
-)
diff --git a/web/.eslintrc.js b/web/.eslintrc.js
new file mode 100644
index 0000000..cdb0d00
--- /dev/null
+++ b/web/.eslintrc.js
@@ -0,0 +1,20 @@
+/**
+ * @license
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+__plugindir = 'zuul-results-summary/web';
+module.exports = {
+  extends: '../../.eslintrc.js',
+};
diff --git a/web/BUILD b/web/BUILD
new file mode 100644
index 0000000..818e7a7
--- /dev/null
+++ b/web/BUILD
@@ -0,0 +1,17 @@
+load("//tools/js:eslint.bzl", "plugin_eslint")
+load("//tools/bzl:js.bzl", "gerrit_js_bundle")
+
+package_group(
+    name = "visibility",
+    packages = ["//plugins/zuul-results-summary/..."],
+)
+
+package(default_visibility = [":visibility"])
+
+gerrit_js_bundle(
+    name = "zuul-results-summary",
+    entry_point = "plugin.js",
+)
+
+# bazel run plugins/zuul-results-summary/web:lint_bin
+plugin_eslint()
diff --git a/zuul-results-summary/zuul-results-summary.js b/web/plugin.js
similarity index 100%
rename from zuul-results-summary/zuul-results-summary.js
rename to web/plugin.js
diff --git a/web/tsconfig.json b/web/tsconfig.json
new file mode 100644
index 0000000..19040ee
--- /dev/null
+++ b/web/tsconfig.json
@@ -0,0 +1,6 @@
+{
+  "extends": "../../tsconfig-plugins-base.json",
+  "include": [
+    "**/*.ts"
+  ]
+}