angular-cn/tools/gulp-tasks
Paul Gschwendtner 7a3a453072 build: convert CLDR locale extraction from Gulp to Bazel tool (#42230)
Converts the CLDR locale extraction script to a Bazel tool.
This allows us to generate locale files within Bazel, so that
locales don't need to live as sources within the repo. Also
it allows us to get rid of the legacy Gulp tooling.

The migration of the Gulp script to a Bazel tool involved the
following things:

  1. Basic conversion of the `extract.js` script to TypeScript.
     This mostly was about adding explicit types. e.g. adding `locale:
     string` or `localeData: CldrStatic`.

  2. Split-up into separate files. Instead of keeping the large
     `extract.js` file, the tool has been split into separate files.
     The logic remains the same, just that code is more readable and
     maintainable.

  3. Introduction of a new `index.ts` file that is the entry-point
     for the Bazel tool. Previously the Gulp tool just generated
     all locale files, the default locale and base currency files
     at once. The new entry-point accepts a mode to be passed as
     first process argument. based on that argument, either locales
     are generated into a specified directory, or the default locale,
     base currencies or closure file is generated.

     This allows us to generate files with a Bazel genrule where
     we simply run the tool and specify the outputs. Note: It's
     necessary to have multiple modes because files live in separate
     locations. e.g. the default locale in `@angular/core`, but the
     rest in `@angular/common`.

  4. Removal of the `cldr-data-downloader` and custom CLDR resolution
     logic. Within Bazel we cannot run a downloader using network.

     We switch this to something more Bazel idiomatic with better
     caching. For this a new repository rule is introduced that
     downloads the CLDR JSON repository and extracts it. Within
     that rule we determine the supported locales so that they
     can be used to pre-declare outputs (for the locales) within
     Bazel analysis phase. This allows us to add the generated locale
     files to a `ts_library` (which we want to have for better testing,
     and consistent JS transpilation).

     Note that the removal of `cldr-data-downloader` also requires us to
     add logic for detecting locales without data. The CLDR data
     downloader overwrote the `availableLocales.json` file with a file
     that only lists locales that CLDR provides data for. We use the
     official `availableLocales` file CLDR provides, but filter out
     locales for which no data is available. This is needed until we
     update to CLDR 39 where data is available for all such locales
     listed in `availableLocales.json`.

PR Close #42230
2021-07-16 12:44:59 -07:00
..
README.md build: migrate from gulp to ng-dev for running formatting (#36726) 2020-04-24 12:32:18 -07:00
changelog-zonejs.js build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
platform-script-path.js build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
source-map-test.js build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00

README.md

Gulp Tasks folder

This folder contains one file for each task (or group of related tasks) for the project's gulpfile. The dependencies between the tasks is kept in the gulpfile.

Task File Structure

Each task is defined by a factory function that accepts gulp as a parameter. Each file exports either one factory or an object of factories.

E.g. The build.js file contains only one task:

module.exports = (gulp) => (done) => {
  ...
};

Loading Tasks

The tasks are loaded in the gulp file, by requiring them. There is a helper called loadTask(fileName, taskName) will do this for us, where the taskName is optional if the file only exports one task.

E.g. Loading the task that will run the build, from a task file that contains only one task.

gulp.task('build.sh', loadTask('build'));