From 38f823e357e5ea5ef40520a8e89bc619ec0afffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Rodr=C3=ADguez?= Date: Fri, 24 Mar 2017 00:12:19 +0100 Subject: [PATCH] chore: better package.json for zipper (#3344) --- .../_examples/cli-quickstart/ts/zipper.json | 3 +- public/docs/_examples/package.json | 27 +--------- public/docs/_examples/webpack/ts/zipper.json | 3 +- .../customizer/package-json/base.json | 40 ++++++++++++++ .../customizer/package-json/cli.json | 14 +++++ .../customizer/package-json/package.json | 19 +++++++ .../package-json/packageJsonCustomizer.js | 52 +++++++++++++++++++ .../customizer/package-json/systemjs.json | 44 ++++++++++++++++ .../customizer/package-json/webpack.json | 26 ++++++++++ tools/example-zipper/exampleZipper.js | 31 +++++++---- 10 files changed, 221 insertions(+), 38 deletions(-) create mode 100644 tools/example-zipper/customizer/package-json/base.json create mode 100644 tools/example-zipper/customizer/package-json/cli.json create mode 100644 tools/example-zipper/customizer/package-json/package.json create mode 100644 tools/example-zipper/customizer/package-json/packageJsonCustomizer.js create mode 100644 tools/example-zipper/customizer/package-json/systemjs.json create mode 100644 tools/example-zipper/customizer/package-json/webpack.json diff --git a/public/docs/_examples/cli-quickstart/ts/zipper.json b/public/docs/_examples/cli-quickstart/ts/zipper.json index c5248e5015..70bf41659e 100644 --- a/public/docs/_examples/cli-quickstart/ts/zipper.json +++ b/public/docs/_examples/cli-quickstart/ts/zipper.json @@ -6,5 +6,6 @@ ".angular-cli.json", "protractor.conf.js" ], - "removeSystemJsConfig": true + "removeSystemJsConfig": true, + "type": "cli" } diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json index 5826623364..ae481f7415 100644 --- a/public/docs/_examples/package.json +++ b/public/docs/_examples/package.json @@ -4,32 +4,9 @@ "private": true, "description": "Master package.json, the superset of all dependencies for all of the _example package.json files. See _boilerplate/package.json for example npm scripts.", "scripts": { - "build": "tsc -p src/", - "build:watch": "tsc -p src/ -w", - "build:e2e": "tsc -p e2e/", - "serve": "lite-server -c=bs-config.json", - "prestart": "npm run build", - "start": "concurrently \"npm run build:watch\" \"npm run serve\"", + "http-server": "http-server", "protractor": "protractor", - "webdriver:update": "webdriver-manager update --standalone false --gecko false", - "pretest": "npm run build", - "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"", - "pretest:once": "npm run build", - "test:once": "karma start karma.conf.js --single-run", - "lint": "tslint ./src/**/*.ts -t verbose", - - "build:upgrade": "tsc", - "serve:upgrade": "http-server", - "build:cli": "ng build --no-progress", - "serve:cli": "http-server dist/", - "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js", - "serve:aot": "lite-server -c bs-config.aot.json", - "start:webpack": "webpack-dev-server --inline --progress --port 8080", - "test:webpack": "karma start karma.webpack.conf.js", - "build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail", - "build:babel": "babel src -d src --extensions \".es6\" --source-maps", - "copy-dist-files": "node ./copy-dist-files.js", - "i18n": "ng-xi18n" + "webdriver:update": "webdriver-manager update --standalone false --gecko false" }, "keywords": [], "author": "", diff --git a/public/docs/_examples/webpack/ts/zipper.json b/public/docs/_examples/webpack/ts/zipper.json index f429363aa3..73ea46a406 100644 --- a/public/docs/_examples/webpack/ts/zipper.json +++ b/public/docs/_examples/webpack/ts/zipper.json @@ -7,5 +7,6 @@ "webpack.config.js", "karma.webpack.conf.js" ], - "removeSystemJsConfig": true + "removeSystemJsConfig": true, + "type": "webpack" } diff --git a/tools/example-zipper/customizer/package-json/base.json b/tools/example-zipper/customizer/package-json/base.json new file mode 100644 index 0000000000..718f9f2eb9 --- /dev/null +++ b/tools/example-zipper/customizer/package-json/base.json @@ -0,0 +1,40 @@ +{ + "scripts": [ + { "name": "lint" } + ], + "dependencies": [ + "@angular/common", + "@angular/compiler", + "@angular/compiler-cli", + "@angular/core", + "@angular/forms", + "@angular/http", + "@angular/platform-browser", + "@angular/platform-browser-dynamic", + "@angular/platform-server", + "@angular/router", + "@angular/tsc-wrapped", + "@angular/upgrade", + "angular-in-memory-web-api", + "core-js", + "rxjs", + "zone.js" + ], + "devDependencies": [ + "@types/jasmine", + "@types/node", + "jasmine", + "jasmine-core", + "karma", + "karma-chrome-launcher", + "karma-cli", + "karma-jasmine", + "karma-jasmine-html-reporter", + "karma-phantomjs-launcher", + "lodash", + "phantomjs-prebuilt", + "protractor", + "tslint", + "typescript" + ] +} diff --git a/tools/example-zipper/customizer/package-json/cli.json b/tools/example-zipper/customizer/package-json/cli.json new file mode 100644 index 0000000000..8c367c67d6 --- /dev/null +++ b/tools/example-zipper/customizer/package-json/cli.json @@ -0,0 +1,14 @@ +{ + "scripts": [ + { "name": "ng", "command": "ng" }, + { "name": "start", "command": "ng serve" }, + { "name": "test", "command": "ng test" }, + { "name": "lint", "command": "ng lint" }, + { "name": "e2e", "command": "ng e2e" } + ], + "dependencies": [], + "devDependencies": [ + "@angular/cli", + "ts-node" + ] +} diff --git a/tools/example-zipper/customizer/package-json/package.json b/tools/example-zipper/customizer/package-json/package.json new file mode 100644 index 0000000000..a4afa9a41e --- /dev/null +++ b/tools/example-zipper/customizer/package-json/package.json @@ -0,0 +1,19 @@ +{ + "name": "angular-io-example", + "version": "1.0.0", + "private": true, + "description": "Example project from an angular.io guide.", + "scripts": { + + }, + "keywords": [], + "author": "", + "license": "MIT", + "dependencies": { + + }, + "devDependencies": { + + }, + "repository": {} +} diff --git a/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js b/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js new file mode 100644 index 0000000000..4908da1a12 --- /dev/null +++ b/tools/example-zipper/customizer/package-json/packageJsonCustomizer.js @@ -0,0 +1,52 @@ +'use strict'; + +const fs = require('fs'); + +class PackageJsonCustomizer { + constructor() { + this.dependenciesPackageJson = JSON.parse(fs.readFileSync('public/docs/_examples/package.json')); + this.scriptsPackageJson = JSON.parse(fs.readFileSync('public/docs/_examples/_boilerplate/package.json')); + this.basePackageJson = JSON.parse(fs.readFileSync(`${__dirname}/base.json`)); + } + + generate(type = 'systemjs') { + let packageJson = JSON.parse(fs.readFileSync(`${__dirname}//package.json`)); + let rules = JSON.parse(fs.readFileSync(`${__dirname}/${type}.json`)); + + this._mergeJSON(rules, this.basePackageJson); + + rules.scripts.forEach((r) => { + const scriptName = r.name; + const script = this.scriptsPackageJson.scripts[scriptName]; + const finalName = r.rename ? r.rename : r.name; + const finalScript = r.command ? r.command : script; + packageJson.scripts[finalName] = finalScript; + }); + + rules.dependencies.forEach((name) => { + const version = this.dependenciesPackageJson.dependencies[name]; + packageJson.dependencies[name] = version; + }); + + rules.devDependencies.forEach((name) => { + const version = this.dependenciesPackageJson.devDependencies[name]; + packageJson.devDependencies[name] = version; + }); + + return JSON.stringify(packageJson, null, 2); + } + + _mergeJSON(json1,json2) { + var result = json1 ; + for (var prop in json2) + { + if (json2.hasOwnProperty(prop)) + { + result[prop] = (result[prop].concat(json2[prop])).sort(); + } + } + return result; + } +} + +module.exports = PackageJsonCustomizer; diff --git a/tools/example-zipper/customizer/package-json/systemjs.json b/tools/example-zipper/customizer/package-json/systemjs.json new file mode 100644 index 0000000000..535bf0cc52 --- /dev/null +++ b/tools/example-zipper/customizer/package-json/systemjs.json @@ -0,0 +1,44 @@ +{ + "scripts": [ + { "name": "build" }, + { "name": "build:watch" }, + { "name": "serve" }, + { "name": "prestart" }, + { "name": "start" }, + { "name": "pretest" }, + { "name": "test" }, + { "name": "pretest:once" }, + { "name": "test:once" }, + { "name": "build:upgrade" }, + { "name": "serve:upgrade" }, + { "name": "build:aot" }, + { "name": "serve:aot" }, + { "name": "build:babel" }, + { "name": "copy-dist-files" }, + { "name": "i18n" } + ], + "dependencies": [ + "systemjs" + ], + "devDependencies": [ + "@types/angular", + "@types/angular-animate", + "@types/angular-cookies", + "@types/angular-mocks", + "@types/angular-resource", + "@types/angular-route", + "@types/angular-sanitize", + "babel-cli", + "babel-preset-angular2", + "babel-preset-es2015", + "canonical-path", + "http-server", + "concurrently", + "lite-server", + "rollup", + "rollup-plugin-commonjs", + "rollup-plugin-node-resolve", + "rollup-plugin-uglify", + "source-map-explorer" + ] +} diff --git a/tools/example-zipper/customizer/package-json/webpack.json b/tools/example-zipper/customizer/package-json/webpack.json new file mode 100644 index 0000000000..377d549e74 --- /dev/null +++ b/tools/example-zipper/customizer/package-json/webpack.json @@ -0,0 +1,26 @@ +{ + "scripts": [ + { "name": "start:webpack", "rename": "start" }, + { "name": "test:webpack", "rename": "test" }, + { "name": "build:webpack", "rename": "build" } + ], + "dependencies": [], + "devDependencies": [ + "angular2-template-loader", + "awesome-typescript-loader", + "css-loader", + "extract-text-webpack-plugin", + "file-loader", + "html-loader", + "html-webpack-plugin", + "karma-sourcemap-loader", + "karma-webpack", + "null-loader", + "raw-loader", + "rimraf", + "style-loader", + "webpack", + "webpack-dev-server", + "webpack-merge" + ] +} diff --git a/tools/example-zipper/exampleZipper.js b/tools/example-zipper/exampleZipper.js index d46eba45a2..cb1ab9c041 100644 --- a/tools/example-zipper/exampleZipper.js +++ b/tools/example-zipper/exampleZipper.js @@ -1,21 +1,26 @@ 'use strict'; // Canonical path provides a consistent path (i.e. always forward slashes) across different OSes -var path = require('canonical-path'); -var jsonfile = require('jsonfile'); -var assert = require('assert-plus'); +const path = require('canonical-path'); +const jsonfile = require('jsonfile'); +const assert = require('assert-plus'); // adm-zip does not work properly on Windows -// var Zip = require('adm-zip'); -var archiver = require('archiver'); +// const Zip = require('adm-zip'); +const archiver = require('archiver'); -var fs = require('fs'); -var mkdirp = require('mkdirp'); -var globby = require('globby'); +const fs = require('fs'); +const mkdirp = require('mkdirp'); +const globby = require('globby'); -var regionExtractor = require('../doc-shredder/regionExtractor'); +const PackageJsonCustomizer = require('./customizer/package-json/packageJsonCustomizer'); +const regionExtractor = require('../doc-shredder/regionExtractor'); class ExampleZipper { constructor(sourceDirName, outputDirName) { + this.examplesSystemjsConfig = 'public/docs/_examples/_boilerplate/src/systemjs.config.js'; + this.exampleTsconfig = 'public/docs/_examples/_boilerplate/src/tsconfig.json'; + this.customizer = new PackageJsonCustomizer(); + let gpathPlnkr = path.join(sourceDirName, '**/*plnkr.json'); let gpathZipper = path.join(sourceDirName, '**/zipper.json'); let configFileNames = globby.sync([gpathPlnkr, gpathZipper], { ignore: ['**/node_modules/**'] }); @@ -55,14 +60,18 @@ class ExampleZipper { _zipExample(configFileName, sourceDirName, outputDirName) { let json = JSON.parse(fs.readFileSync(configFileName, 'utf-8')); + const exampleType = json.type || 'systemjs'; const basePath = json.basePath || ''; const jsonFileName = configFileName.replace(/^.*[\\\/]/, ''); const relativeDirName = path.dirname(path.dirname(path.relative(sourceDirName, configFileName))); const exampleDirName = path.dirname(configFileName); +<<<<<<< 6df8bea575824951ad80a82cb2e1310d4535f085 const examplesPackageJson = 'public/docs/_examples/package.json'; const examplesSystemjsConfig = 'public/docs/_examples/_boilerplate/src/systemjs.config.js'; const examplesSystemjsLoaderConfig = 'public/docs/_examples/_boilerplate/src/systemjs-angular-loader.js'; const exampleTsconfig = 'public/docs/_examples/_boilerplate/src/tsconfig.json'; +======= +>>>>>>> chore: better package.json for zipper let exampleZipName = jsonFileName.replace(/(plnkr|zipper).json/, relativeDirName); const outputFileName = path.join(outputDirName, relativeDirName, exampleZipName + '.zip'); let defaultIncludes = ['**/*.ts', '**/*.js', '**/*.css', '**/*.html', '**/*.md', '**/*.json', '**/*.png']; @@ -133,14 +142,14 @@ class ExampleZipper { }); // we need the package.json from _examples root, not the _boilerplate one - zip.append(fs.readFileSync(examplesPackageJson, 'utf8'), { name: 'package.json' }); + zip.append(this.customizer.generate(exampleType), { name: 'package.json' }); // also a systemjs config if (!json.removeSystemJsConfig) { zip.append(fs.readFileSync(examplesSystemjsConfig, 'utf8'), { name: 'src/systemjs.config.js' }); zip.append(fs.readFileSync(examplesSystemjsLoaderConfig, 'utf8'), { name: 'src/systemjs-angular-loader.js' }); } // a modified tsconfig - let tsconfig = fs.readFileSync(exampleTsconfig, 'utf8'); + let tsconfig = fs.readFileSync(this.exampleTsconfig, 'utf8'); zip.append(this._changeTypeRoots(tsconfig), {name: 'src/tsconfig.json'}); zip.finalize();