build(docs-infra): simplify ExampleZipper by removing PackageJsonCustomizer (#38192)

Previously, `ExampleZipper` (the tool used for creating ZIP archives
from our docs examples) used the `PackageJsonCustomizer` to generate
`package.json` files for each example type. This had the following
drawbacks:
- The generated files had to be kept up-to-date with the corresponding
  boilerplate files in `aio/tools/examples/shared/boilerplate/` and
  there was no easy way to find out when the files got out-of-sync.
- The `PackageJsonCustomizer` logic was non-trivial and difficult to
  reason about.
- The same information was duplicated in the boilerplate files and the
  customizer configuration files.

This setup was useful when we used a single `package.json` file for all
docs examples. Now, however, each example type can have its own
boilerplate `package.json` file, including scripts and dependencies
relevant to the example type. Therefore, it is no longer necessary to
generate `package.json` files for ZIP archives.

This commit eliminates the drawbacks mentioned above and simplifies the
`ExampleZipper` tool by removing `PackageJsonCustomizer` and re-using
the boilerplate `package.json` files for ZIP archives.

The changes in this commit also fix some ZIP archives that were
previously broken (for example due to missing dependencies).

PR Close #38192
This commit is contained in:
George Kalpakas
2020-07-22 22:23:55 +03:00
committed by Misko Hevery
parent 7f455e6eec
commit f411c9e5b9
22 changed files with 32 additions and 409 deletions

View File

@ -6,7 +6,6 @@ const archiver = require('archiver');
const fs = require('fs-extra');
const globby = require('globby');
const PackageJsonCustomizer = require('./customizer/package-json/packageJsonCustomizer');
const regionExtractor = require('../transforms/examples-package/services/region-parser');
const EXAMPLE_CONFIG_NAME = 'example-config.json';
@ -17,7 +16,6 @@ class ExampleZipper {
this.examplesSystemjsConfig = path.join(__dirname, '../examples/shared/boilerplate/systemjs/src/systemjs.config.js');
this.examplesSystemjsLoaderConfig = path.join(__dirname, '../examples/shared/boilerplate/systemjs/src/systemjs-angular-loader.js');
this.exampleTsconfig = path.join(__dirname, '../examples/shared/boilerplate/systemjs/src/tsconfig.json');
this.customizer = new PackageJsonCustomizer();
let gpathStackblitz = path.join(sourceDirName, '**/*stackblitz.json');
let gpathZipper = path.join(sourceDirName, '**/zipper.json');
@ -91,6 +89,7 @@ class ExampleZipper {
'bs-config.json',
'karma.conf.js',
'karma-test-shim.js',
'package.json',
'tsconfig.*',
'tslint.*',
'e2e/protractor.conf.js',
@ -100,8 +99,6 @@ class ExampleZipper {
'src/test.ts',
'src/environments/**/*',
'src/testing/**/*',
// Only ignore root package.json
'!package.json'
];
var alwaysExcludes = [
'!**/bs-config.e2e.json',
@ -167,8 +164,6 @@ class ExampleZipper {
zip.append(output, { name: relativePath } );
});
// we need the package.json from _examples root, not the _boilerplate one
zip.append(this.customizer.generate(exampleType), { name: 'package.json' });
// also a systemjs config
if (exampleType === 'systemjs') {
zip.append(fs.readFileSync(this.examplesSystemjsConfig, 'utf8'), { name: 'src/systemjs.config.js' });