2020-03-27 03:26:10 +03:00
|
|
|
|
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
2020-01-16 17:55:32 +03:00
|
|
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
|
2019-04-16 11:00:58 +03:00
|
|
|
|
load("@os_info//:os_info.bzl", "is_windows")
|
2020-01-16 17:55:32 +03:00
|
|
|
|
# load ("@npm_bazel_typescript//:index.bzl", "ts_library")
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
|
|
|
|
filegroup(
|
2019-04-12 14:10:16 +03:00
|
|
|
|
name = "src",
|
|
|
|
|
srcs = glob(["src/**"]),
|
2019-04-04 11:33:38 +03:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# TODO: Set up a target for generating GraphQL query definition files.
|
|
|
|
|
# Currently, these checked in, and updated with 'make update-graphql-types'.
|
|
|
|
|
# TODO: Consider switching from Apollo to https://github.com/dotansimha/graphql-code-generator,
|
|
|
|
|
# as the latter can be configured such that no postprocessing on the generated files is necessary.
|
|
|
|
|
# nodejs_binary(
|
|
|
|
|
# name = "apollo_codegen",
|
|
|
|
|
# entry_point = "node_modules/apollo/bin/run",
|
|
|
|
|
# data = [
|
|
|
|
|
# "@navigator_frontend_deps//apollo",
|
|
|
|
|
# ":src_files"
|
|
|
|
|
# ],
|
|
|
|
|
# templated_args = [
|
|
|
|
|
# "client:codegen",
|
|
|
|
|
# "-c ./apollo.config.js",
|
|
|
|
|
# "--passthroughCustomScalars",
|
|
|
|
|
# "--customScalarsPrefix=OpaqueTypes.",
|
|
|
|
|
# "--outputFlat",
|
|
|
|
|
# "--target",
|
|
|
|
|
# "typescript",
|
|
|
|
|
# "--includes=\"$(location :src)/ui-core/**/*.ts*\"",
|
|
|
|
|
# "$(location :src)/ui-core/src/api/QueriesBody.txt"
|
|
|
|
|
# ]
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
# Webpack build tool
|
|
|
|
|
# The webpack config is a JavaScript file that can import other modules.
|
|
|
|
|
# These dependencies are not automagically detected by the pregenerated
|
|
|
|
|
# "@navigator_frontend_deps//webpack/bin:webpack" target, so we need to create
|
|
|
|
|
# a custom node.js binary that has access to all plugins loaded by webpack at runtime.
|
|
|
|
|
nodejs_binary(
|
2019-04-12 14:10:16 +03:00
|
|
|
|
name = "webpack",
|
2019-07-05 17:04:47 +03:00
|
|
|
|
entry_point = "@navigator_frontend_deps//:node_modules/webpack/bin/webpack.js",
|
2019-04-12 14:10:16 +03:00
|
|
|
|
node_modules = "@navigator_frontend_deps//:node_modules",
|
|
|
|
|
# The webpack build step requires almost all of the node_modules dependencies
|
2019-04-16 11:00:58 +03:00
|
|
|
|
# data = [
|
|
|
|
|
# ...
|
|
|
|
|
# ],
|
2019-04-04 11:33:38 +03:00
|
|
|
|
)
|
|
|
|
|
|
2020-01-16 17:55:32 +03:00
|
|
|
|
# TODO (drsk) We should switch the frontend rule to use the bazel typescript rules instead of
|
|
|
|
|
# webpack. Something like the following:
|
|
|
|
|
# ts_library(
|
|
|
|
|
# name = "frontend",
|
|
|
|
|
# tsconfig = ":tsconfig.json",
|
|
|
|
|
# srcs = glob(["**/*.ts"]),
|
|
|
|
|
# data = [":package.json", ":tslint.json"],
|
|
|
|
|
# node_modules = "@navigator_frontend_deps//:node_modules",
|
|
|
|
|
# visibility = [
|
|
|
|
|
# "//navigator:__subpackages__",
|
|
|
|
|
# ],
|
|
|
|
|
# )
|
|
|
|
|
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# Builds the frontend single page application and bundles all output files
|
2020-01-16 17:55:32 +03:00
|
|
|
|
# (HTML + JavaScript + CSS + images) in a .tgz or .jar archive.
|
2020-08-13 12:19:46 +03:00
|
|
|
|
# This target is non-reproducible. The browsercheck and bundle outputs
|
|
|
|
|
# generated by webpack contain hashes in their file names that are different
|
|
|
|
|
# on each invokation. The following were attempted to make the outputs
|
|
|
|
|
# reproducible but failed:
|
|
|
|
|
# - Use `[contenthash]` instead of `[hash]` (including `output.chunkFilename`), see https://webpack.js.org/guides/caching/
|
|
|
|
|
# - Configure `optimization.moduleIds = 'hashed'`, see https://webpack.js.org/configuration/optimization/#optimizationmoduleids
|
|
|
|
|
# - Configure `optimization.chunkIds = 'named'`, see https://webpack.js.org/configuration/optimization/#optimizationchunkids
|
|
|
|
|
# - Use https://www.npmjs.com/package/webpack-plugin-hash-output
|
|
|
|
|
# - Disable source map
|
2019-04-04 11:33:38 +03:00
|
|
|
|
genrule(
|
2019-04-12 14:10:16 +03:00
|
|
|
|
name = "frontend",
|
|
|
|
|
srcs = [
|
|
|
|
|
"webpack.config.js",
|
|
|
|
|
"declarations.d.ts",
|
|
|
|
|
"tsconfig.json",
|
|
|
|
|
"tslint.json",
|
|
|
|
|
"package.json",
|
|
|
|
|
".modernizrrc",
|
|
|
|
|
":src",
|
|
|
|
|
"@navigator_frontend_deps//:node_modules",
|
|
|
|
|
],
|
|
|
|
|
outs = [
|
|
|
|
|
"frontend.tgz",
|
|
|
|
|
"frontend.jar",
|
|
|
|
|
],
|
|
|
|
|
cmd = """
|
2019-04-04 11:33:38 +03:00
|
|
|
|
# Working directories
|
|
|
|
|
export IN="$$(pwd)/$(@D)/in"
|
|
|
|
|
export OUT="$$(pwd)/$(@D)/out"
|
2019-05-23 12:38:39 +03:00
|
|
|
|
rm -rf $$IN $$OUT
|
|
|
|
|
mkdir "$$IN" "$$OUT"
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
|
|
|
|
# Our tools (node.js, webpack, webpack plugins, typescript) do not work nicely
|
|
|
|
|
# with symbolic links and a node_modules directory that is not in the project root.
|
|
|
|
|
# All input files are therefore copied to a working directory.
|
|
|
|
|
cp -rL "$$(pwd)/$$(dirname $(execpath declarations.d.ts))/src" "$$IN/src"
|
|
|
|
|
cp -rL "$$(pwd)/external/navigator_frontend_deps/node_modules" "$$IN/node_modules"
|
|
|
|
|
cp -L "$$(pwd)/$(execpath webpack.config.js)" "$$IN/webpack.config.js"
|
|
|
|
|
cp -L "$$(pwd)/$(execpath .modernizrrc)" "$$IN/.modernizrrc"
|
|
|
|
|
cp -L "$$(pwd)/$(execpath tsconfig.json)" "$$IN/tsconfig.json"
|
|
|
|
|
cp -L "$$(pwd)/$(execpath tslint.json)" "$$IN/tslint.json"
|
|
|
|
|
cp -L "$$(pwd)/$(execpath declarations.d.ts)" "$$IN/declarations.d.ts"
|
|
|
|
|
|
2019-04-16 11:00:58 +03:00
|
|
|
|
# Webpack needs the HOME variable to be set
|
2019-04-04 11:33:38 +03:00
|
|
|
|
export HOME="$$IN"
|
|
|
|
|
|
|
|
|
|
# Run webpack.
|
|
|
|
|
# To debug, add the following options:
|
2019-04-16 11:00:58 +03:00
|
|
|
|
# -d --progress --display-error-details --verbose
|
2020-01-22 20:54:04 +03:00
|
|
|
|
WP_IN={WP_IN}
|
|
|
|
|
WP_OUT={WP_OUT}
|
2020-07-06 19:07:47 +03:00
|
|
|
|
$(execpath :webpack) \\
|
|
|
|
|
--config="$$IN/webpack.config.js" \\
|
|
|
|
|
--env.prod \\
|
|
|
|
|
--env.paths_case_check="{PATHS_CASE_CHECK}" \\
|
|
|
|
|
--env.bazel_in_dir="{WP_IN_ESCAPED}" \\
|
2020-01-22 20:54:04 +03:00
|
|
|
|
--env.bazel_out_dir="{WP_OUT_ESCAPED}"
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
2019-04-16 11:00:58 +03:00
|
|
|
|
# Package result (.TGZ)
|
2020-03-31 11:09:52 +03:00
|
|
|
|
# To debug, change 'c' to 'cv'.
|
2019-04-04 11:33:38 +03:00
|
|
|
|
echo "Packaging result from $$OUT to $(@D)/frontend.tgz"
|
2020-08-05 17:27:14 +03:00
|
|
|
|
$(execpath //bazel_tools/sh:mktgz) $(@D)/frontend.tgz -C $$OUT .
|
2019-04-04 11:33:38 +03:00
|
|
|
|
|
2019-04-16 11:00:58 +03:00
|
|
|
|
# Package result (.JAR)
|
2019-04-04 11:33:38 +03:00
|
|
|
|
echo "Packaging result from $$OUT to $(@D)/frontend.jar"
|
2020-08-12 16:49:32 +03:00
|
|
|
|
$(rootpath @bazel_tools//tools/zip:zipper) c "$(@D)/frontend.jar" \\
|
|
|
|
|
$$($(POSIX_FIND) $$OUT -type f -printf "%P=%p\\n" | $(POSIX_SORT))
|
2019-04-16 11:00:58 +03:00
|
|
|
|
""".format(
|
|
|
|
|
PATHS_CASE_CHECK = "false" if is_windows else "true",
|
2020-01-22 20:54:04 +03:00
|
|
|
|
WP_IN = "$$(cygpath -w $$IN)" if is_windows else "$$IN",
|
|
|
|
|
WP_IN_ESCAPED = "'$$WP_IN'" if is_windows else "$$WP_IN",
|
|
|
|
|
WP_OUT = "$$(cygpath -w $$OUT/frontend)" if is_windows else "$$OUT/frontend",
|
|
|
|
|
WP_OUT_ESCAPED = "'$$WP_OUT'" if is_windows else "$$WP_OUT",
|
2019-04-16 11:00:58 +03:00
|
|
|
|
),
|
2020-08-12 16:49:32 +03:00
|
|
|
|
toolchains = ["@rules_sh//sh/posix:make_variables"],
|
2020-08-05 17:27:14 +03:00
|
|
|
|
tools = [
|
|
|
|
|
":webpack",
|
|
|
|
|
"//bazel_tools/sh:mktgz",
|
2020-08-12 16:49:32 +03:00
|
|
|
|
"@bazel_tools//tools/zip:zipper",
|
2020-08-05 17:27:14 +03:00
|
|
|
|
],
|
2019-04-12 14:10:16 +03:00
|
|
|
|
visibility = [
|
|
|
|
|
"//navigator:__subpackages__",
|
|
|
|
|
],
|
2019-04-04 11:33:38 +03:00
|
|
|
|
)
|