Paul Gschwendtner 444d838905 build: wire up new CLDR generation tool within Bazel (#42230)
Introduces a few Starlark macros for running the new Bazel
CLDR generation tool. Wires up the new tool so that locales
are generated properly. Also updates the existing
`closure-locale` file to match the new output generated by the Bazel tool.

This commit also re-adds a few locale files that aren't
generated by CLDR 37, but have been accidentally left in
the repository as the Gulp script never removed old locales
from previous CLDR versions. This problem is solved with the
Bazel generation of locale files, but for now we re-add these
old CLDR 33 locale files to not break developers relying on these
(even though the locale data indicies are incorrect; but there might
be users accessing the data directly)

PR Close #42230
2021-07-16 12:44:59 -07:00

61 lines
2.3 KiB
Python

load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("//packages/common/locales:index.bzl", "LOCALES", "generate_all_locale_files", "generate_closure_locales_file")
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
package(default_visibility = ["//visibility:public"])
# This generates the `closure-locale.ts` file through the `generate-locales` tool. Since
# the `closure-locale.ts` file is checked-in for Google3, we add a `generated_file_test` to
# ensure the checked-in file is up-to-date. To disambiguate from the test, we use a more
# precise target name here.
generate_closure_locales_file(
name = "closure_locales_file_generated",
output_file = "closure_locales_generated.ts",
)
generated_file_test(
name = "closure_locale_file",
src = "closure-locale.ts",
generated = ":closure_locales_file_generated",
)
generate_all_locale_files(
name = "locale_files",
)
ts_library(
name = "locales",
# TODO(devversion): Remove glob for checked-in legacy locale files that haven't been
# removed in the past (when CLDR has been updated). These can be removed in a major.
srcs = [file for l in LOCALES for file in [
"%s.ts" % l,
"extra/%s.ts" % l,
]] + glob(
[
"*.ts",
"extra/*.ts",
],
exclude = ["closure-locale.ts"],
),
)
pkg_npm(
name = "package",
srcs = ["package.json"],
substitutions = {
# Workaround for `.d.ts`` containing `/// <amd-module .../>`
# which are generated in TypeScript v2.9, but not before.
"/// <amd-module name=.*/>": "",
# Workaround for https://github.com/angular/angular/issues/23217
# Webpack will detect that the UMD outputs from TypeScript pass the
# `require` function into the module, and cannot accurately track
# dependencies in case require was called.
# We don't actually import anything in the locale code so we can
# null out the require reference passed into the module.
"factory\\(require, exports\\)": "factory(null, exports)",
},
# TODO(devversion): Remove glob for checked-in legacy locale files that haven't been
# removed in the past (when CLDR has been updated). These can be removed in a major.
deps = ["global/%s.js" % l for l in LOCALES] + [":locales"] + glob(["global/*.js"]),
)