From 3db9d57de394308cb03205b99ac5027a8cbb5af6 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 27 Jun 2018 10:20:09 -0500 Subject: [PATCH] fix(docs-infra): use clean package.json template when generating zips (#24691) Closes #24689 PR Close #24691 --- .../customizer/package-json/cli.json | 2 +- .../customizer/package-json/i18n.json | 2 +- .../package-json/packageJsonCustomizer.js | 20 +++++++++++++------ .../customizer/package-json/testing.json | 1 + .../customizer/package-json/universal.json | 1 + 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/aio/tools/example-zipper/customizer/package-json/cli.json b/aio/tools/example-zipper/customizer/package-json/cli.json index 9dd7cce54c..965bd82407 100644 --- a/aio/tools/example-zipper/customizer/package-json/cli.json +++ b/aio/tools/example-zipper/customizer/package-json/cli.json @@ -9,8 +9,8 @@ ], "dependencies": [], "devDependencies": [ - "@angular/cli", "@angular-devkit/build-angular", + "@angular/cli", "@types/jasminewd2", "jasmine-spec-reporter", "karma-coverage-istanbul-reporter", diff --git a/aio/tools/example-zipper/customizer/package-json/i18n.json b/aio/tools/example-zipper/customizer/package-json/i18n.json index d257e96c1d..57320e769e 100644 --- a/aio/tools/example-zipper/customizer/package-json/i18n.json +++ b/aio/tools/example-zipper/customizer/package-json/i18n.json @@ -11,8 +11,8 @@ ], "dependencies": [], "devDependencies": [ - "@angular/cli", "@angular-devkit/build-angular", + "@angular/cli", "@types/jasminewd2", "jasmine-spec-reporter", "karma-coverage-istanbul-reporter", diff --git a/aio/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js b/aio/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js index 02858dacf0..2255244dcc 100644 --- a/aio/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js +++ b/aio/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js @@ -1,19 +1,21 @@ 'use strict'; const path = require('canonical-path'); +const fs = require('fs'); const examplesPath = path.resolve(__dirname, '../../../examples'); const packageFolder = path.resolve(__dirname); class PackageJsonCustomizer { constructor() { - this.dependenciesPackageJson = require(path.join(examplesPath, '/shared/package.json')); - this.scriptsPackageJson = require(path.join(examplesPath, '/shared/boilerplate/systemjs/package.json')); - this.basePackageJson = require(`${packageFolder}/base.json`); + this.dependenciesPackageJson = this.readJson(path.join(examplesPath, '/shared/package.json')); + this.scriptsPackageJson = this.readJson(path.join(examplesPath, '/shared/boilerplate/systemjs/package.json')); + this.basePackageJson = this.readJson(`${packageFolder}/base.json`); + this.templatePackageJson = this.readJson(`${packageFolder}/package.json`, false); } generate(type = 'systemjs') { - let packageJson = require(`${packageFolder}/package.json`); + let packageJson = JSON.parse(this.templatePackageJson); let rules = require(`${packageFolder}/${type}.json`); this._mergeJSON(rules, this.basePackageJson); @@ -39,8 +41,8 @@ class PackageJsonCustomizer { return JSON.stringify(packageJson, null, 2); } - _mergeJSON(json1,json2) { - var result = json1 ; + _mergeJSON(json1, json2) { + var result = json1; for (var prop in json2) { if (json2.hasOwnProperty(prop)) @@ -50,6 +52,12 @@ class PackageJsonCustomizer { } return result; } + + readJson(jsonFile, parse = true) { + const contents = fs.readFileSync(jsonFile, 'utf8'); + + return parse ? JSON.parse(contents) : contents; + } } module.exports = PackageJsonCustomizer; diff --git a/aio/tools/example-zipper/customizer/package-json/testing.json b/aio/tools/example-zipper/customizer/package-json/testing.json index 5ce4c4788f..37c304b4cc 100644 --- a/aio/tools/example-zipper/customizer/package-json/testing.json +++ b/aio/tools/example-zipper/customizer/package-json/testing.json @@ -9,6 +9,7 @@ ], "dependencies": [], "devDependencies": [ + "@angular-devkit/build-angular", "@angular/cli", "@types/jasminewd2", "jasmine-marbles", diff --git a/aio/tools/example-zipper/customizer/package-json/universal.json b/aio/tools/example-zipper/customizer/package-json/universal.json index 2abfbcdd19..c3f649d529 100644 --- a/aio/tools/example-zipper/customizer/package-json/universal.json +++ b/aio/tools/example-zipper/customizer/package-json/universal.json @@ -15,6 +15,7 @@ "@nguniversal/module-map-ngfactory-loader" ], "devDependencies": [ + "@angular-devkit/build-angular", "@angular/cli", "@types/jasminewd2", "jasmine-spec-reporter",