chore: better package.json for zipper (#3344)

This commit is contained in:
Jesús Rodríguez 2017-03-24 00:12:19 +01:00 committed by GitHub
parent 6df8bea575
commit 38f823e357
10 changed files with 221 additions and 38 deletions

View File

@ -6,5 +6,6 @@
".angular-cli.json",
"protractor.conf.js"
],
"removeSystemJsConfig": true
"removeSystemJsConfig": true,
"type": "cli"
}

View File

@ -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": "",

View File

@ -7,5 +7,6 @@
"webpack.config.js",
"karma.webpack.conf.js"
],
"removeSystemJsConfig": true
"removeSystemJsConfig": true,
"type": "webpack"
}

View File

@ -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"
]
}

View File

@ -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"
]
}

View File

@ -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": {}
}

View File

@ -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;

View File

@ -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"
]
}

View File

@ -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"
]
}

View File

@ -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();