build(aio): ability to generate zips

This commit is contained in:
Jesus Rodriguez 2017-04-16 23:40:47 +02:00 committed by Pete Bacon Darwin
parent 648de7dd86
commit 50174d9fb5
10 changed files with 435 additions and 6 deletions

View File

@ -27,7 +27,8 @@
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false",
"boilerplate:add": "node ./tools/examples/add-example-boilerplate add",
"boilerplate:remove": "node ./tools/examples/add-example-boilerplate remove",
"generate-plunkers": "node ./tools/plunker-builder/generatePlunkers"
"generate-plunkers": "node ./tools/plunker-builder/generatePlunkers",
"generate-zips": "node ./tools/example-zipper/generateZips"
},
"private": true,
"dependencies": {
@ -52,6 +53,7 @@
"@angular/compiler-cli": "next",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"archiver": "^1.3.0",
"canonical-path": "^0.0.2",
"codelyzer": "~2.0.0",
"concurrently": "^3.4.0",

View File

@ -0,0 +1,41 @@
{
"scripts": [
{ "name": "lint" }
],
"dependencies": [
"@angular/animations",
"@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,55 @@
'use strict';
const path = require('canonical-path');
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/package.json'));
this.basePackageJson = require(`${packageFolder}/base.json`);
}
generate(type = 'systemjs') {
let packageJson = require(`${packageFolder}/package.json`);
let rules = require(`${packageFolder}/${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

@ -0,0 +1,148 @@
'use strict';
// Canonical path provides a consistent path (i.e. always forward slashes) across different OSes
const path = require('canonical-path');
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');
class ExampleZipper {
constructor(sourceDirName, outputDirName) {
this.examplesPackageJson = path.join(__dirname, '../examples/shared/package.json');
this.examplesSystemjsConfig = path.join(__dirname, '../examples/shared/boilerplate/src/systemjs.config.js');
this.examplesSystemjsLoaderConfig = path.join(__dirname, '../examples/shared/boilerplate/src/systemjs-angular-loader.js');
this.exampleTsconfig = path.join(__dirname, '../examples/shared/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/**'] });
configFileNames.forEach((configFileName) => {
this._zipExample(configFileName, sourceDirName, outputDirName);
});
}
_changeTypeRoots(tsconfig) {
return tsconfig.replace('../../../', '../');
}
_createZipArchive(zipFileName) {
let dirName = path.dirname(zipFileName);
fs.ensureDirSync(dirName);
let output = fs.createWriteStream(zipFileName);
let archive = archiver('zip');
output.on('close', function () {
console.log('zip created: ' + zipFileName + ' (' + archive.pointer() + ' total bytes)');
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
return archive;
}
_zipExample(configFileName, sourceDirName, outputDirName) {
let json = require(configFileName, 'utf-8');
const exampleType = json.type || 'systemjs';
const basePath = json.basePath || '';
const jsonFileName = configFileName.replace(/^.*[\\\/]/, '');
let relativeDirName = path.dirname(path.relative(sourceDirName, configFileName));
let exampleZipName;
if (relativeDirName.indexOf('/') !== -1) { // Special example
[relativeDirName, exampleZipName] = relativeDirName.split('/');
} else {
exampleZipName = jsonFileName.replace(/(plnkr|zipper).json/, relativeDirName);
}
const exampleDirName = path.dirname(configFileName);
const outputFileName = path.join(outputDirName, relativeDirName, exampleZipName + '.zip');
let defaultIncludes = ['**/*.ts', '**/*.js', '**/*.es6', '**/*.css', '**/*.html', '**/*.md', '**/*.json', '**/*.png'];
let alwaysIncludes = ['bs-config.json', 'tslint.json', 'karma-test-shim.js', 'karma.conf.js', 'src/testing/**/*', 'src/.babelrc'];
var defaultExcludes = [
'!**/bs-config.e2e.json',
'!**/*plnkr.*',
'!**/*zipper.*',
'!**/systemjs.config.js',
'!**/npm-debug.log',
'!**/package.json',
'!**/example-config.json',
'!**/wallaby.js',
'!**/tsconfig.json',
'!**/package.webpack.json',
// AoT related files
'!**/aot/**/*.*',
'!**/*-aot.*'
];
if (json.files) {
if (json.files.length > 0) {
json.files = json.files.map(file => {
if (file.startsWith('!')) {
if (file.startsWith('!**')) {
return file;
}
return '!' + basePath + file.substr(1);
}
return basePath + file;
});
if (json.files[0].substr(0, 1) === '!') {
json.files = defaultIncludes.concat(json.files);
}
}
} else {
json.files = defaultIncludes;
}
json.files = json.files.concat(alwaysIncludes);
let gpaths = json.files.map((fileName) => {
fileName = fileName.trim();
if (fileName.substr(0, 1) === '!') {
return '!' + path.join(exampleDirName, fileName.substr(1));
} else {
return path.join(exampleDirName, fileName);
}
});
Array.prototype.push.apply(gpaths, defaultExcludes);
let fileNames = globby.sync(gpaths, { ignore: ['**/node_modules/**']});
let zip = this._createZipArchive(outputFileName);
fileNames.forEach((fileName) => {
let relativePath = path.relative(exampleDirName, fileName);
let content = fs.readFileSync(fileName, 'utf8');
let extn = path.extname(fileName).substr(1);
// if we don't need to clean up the file then we can do the following.
// zip.append(fs.createReadStream(fileName), { name: relativePath });
let output = regionExtractor()(content, extn).contents;
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 (!json.removeSystemJsConfig) {
zip.append(fs.readFileSync(this.examplesSystemjsConfig, 'utf8'), { name: 'src/systemjs.config.js' });
zip.append(fs.readFileSync(this.examplesSystemjsLoaderConfig, 'utf8'), { name: 'src/systemjs-angular-loader.js' });
}
// a modified tsconfig
let tsconfig = fs.readFileSync(this.exampleTsconfig, 'utf8');
zip.append(this._changeTypeRoots(tsconfig), {name: 'src/tsconfig.json'});
zip.finalize();
}
}
module.exports = ExampleZipper;

View File

@ -0,0 +1,7 @@
const ExampleZipper = require('./exampleZipper');
const path = require('canonical-path');
const EXAMPLES_PATH = path.join(__dirname, '../../content/examples');
const ZIPS_PATH = path.join(__dirname, '../../src/content/zips');
new ExampleZipper(EXAMPLES_PATH, ZIPS_PATH);

View File

@ -327,6 +327,17 @@ aproba@^1.0.3:
version "1.1.1"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.1.1.tgz#95d3600f07710aa0e9298c726ad5ecf2eacbabab"
archiver-utils@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/archiver-utils/-/archiver-utils-1.3.0.tgz#e50b4c09c70bf3d680e32ff1b7994e9f9d895174"
dependencies:
glob "^7.0.0"
graceful-fs "^4.1.0"
lazystream "^1.0.0"
lodash "^4.8.0"
normalize-path "^2.0.0"
readable-stream "^2.0.0"
archiver@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-0.16.0.tgz#bb570346899d0865eb77ed66727ab3c634fc1a50"
@ -340,6 +351,20 @@ archiver@^0.16.0:
tar-stream "~1.2.1"
zip-stream "~0.6.0"
archiver@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-1.3.0.tgz#4f2194d6d8f99df3f531e6881f14f15d55faaf22"
dependencies:
archiver-utils "^1.3.0"
async "^2.0.0"
buffer-crc32 "^0.2.1"
glob "^7.0.0"
lodash "^4.8.0"
readable-stream "^2.0.0"
tar-stream "^1.5.0"
walkdir "^0.0.11"
zip-stream "^1.1.0"
are-we-there-yet@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.2.tgz#80e470e95a084794fe1899262c5667c6e88de1b3"
@ -473,7 +498,7 @@ async@^1.3.0, async@^1.4.0, async@^1.4.2, async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@^2.0.1, async@^2.1.2, async@^2.1.4:
async@^2.0.0, async@^2.0.1, async@^2.1.2, async@^2.1.4:
version "2.1.5"
resolved "https://registry.yarnpkg.com/async/-/async-2.1.5.tgz#e587c68580994ac67fc56ff86d3ac56bdbe810bc"
dependencies:
@ -815,7 +840,7 @@ browserslist@^1.0.1, browserslist@^1.5.2, browserslist@^1.7.4:
caniuse-db "^1.0.30000624"
electron-to-chromium "^1.2.2"
buffer-crc32@~0.2.1:
buffer-crc32@^0.2.1, buffer-crc32@~0.2.1:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
@ -1238,6 +1263,15 @@ component-inherit@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/component-inherit/-/component-inherit-0.0.3.tgz#645fc4adf58b72b649d5cae65135619db26ff143"
compress-commons@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-1.2.0.tgz#58587092ef20d37cb58baf000112c9278ff73b9f"
dependencies:
buffer-crc32 "^0.2.1"
crc32-stream "^2.0.0"
normalize-path "^2.0.0"
readable-stream "^2.0.0"
compress-commons@~0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-0.3.0.tgz#97093e2e193f7567fa13203d4b8defcd5971a519"
@ -1403,6 +1437,13 @@ corser@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
crc32-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/crc32-stream/-/crc32-stream-2.0.0.tgz#e3cdd3b4df3168dd74e3de3fbbcb7b297fe908f4"
dependencies:
crc "^3.4.4"
readable-stream "^2.0.0"
crc32-stream@~0.3.1:
version "0.3.4"
resolved "https://registry.yarnpkg.com/crc32-stream/-/crc32-stream-0.3.4.tgz#73bc25b45fac1db6632231a7bfce8927e9f06552"
@ -1410,6 +1451,10 @@ crc32-stream@~0.3.1:
buffer-crc32 "~0.2.1"
readable-stream "~1.0.24"
crc@^3.4.4:
version "3.4.4"
resolved "https://registry.yarnpkg.com/crc/-/crc-3.4.4.tgz#9da1e980e3bd44fc5c93bf5ab3da3378d85e466b"
create-ecdh@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d"
@ -2866,7 +2911,7 @@ got@^6.7.1:
unzip-response "^2.0.1"
url-parse-lax "^1.0.0"
graceful-fs@*, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
graceful-fs@*, graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
@ -3933,6 +3978,12 @@ lazy-req@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/lazy-req/-/lazy-req-2.0.0.tgz#c9450a363ecdda2e6f0c70132ad4f37f8f06f2b4"
lazystream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lazystream/-/lazystream-1.0.0.tgz#f6995fe0f820392f61396be89462407bb77168e4"
dependencies:
readable-stream "^2.0.5"
lazystream@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/lazystream/-/lazystream-0.1.0.tgz#1b25d63c772a4c20f0a5ed0a9d77f484b6e16920"
@ -4102,7 +4153,7 @@ lodash@^3.10.0, lodash@^3.10.1, lodash@^3.8.0, lodash@~3.10.0, lodash@~3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
lodash@^4.0.0, lodash@^4.11.1, lodash@^4.11.2, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.5.1, lodash@^4.6.1:
lodash@^4.0.0, lodash@^4.11.1, lodash@^4.11.2, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.5.1, lodash@^4.6.1, lodash@^4.8.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@ -4546,7 +4597,7 @@ normalize-package-data@^2.3.2, normalize-package-data@^2.3.4:
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"
normalize-path@^2.0.1:
normalize-path@^2.0.0, normalize-path@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.0.1.tgz#47886ac1662760d4261b7d979d241709d3ce3f7a"
@ -6455,6 +6506,15 @@ tar-pack@~3.3.0:
tar "~2.2.1"
uid-number "~0.0.6"
tar-stream@^1.5.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-1.5.2.tgz#fbc6c6e83c1a19d4cb48c7d96171fc248effc7bf"
dependencies:
bl "^1.0.0"
end-of-stream "^1.0.0"
readable-stream "^2.0.0"
xtend "^4.0.0"
tar-stream@~1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-1.2.2.tgz#9632f23d98fd33d41661bbdec05489120dec6028"
@ -7093,6 +7153,10 @@ walk-sync@^0.3.1:
ensure-posix-path "^1.0.0"
matcher-collection "^1.0.0"
walkdir@^0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532"
watchpack@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.2.1.tgz#01efa80c5c29e5c56ba55d6f5470a35b6402f0b2"
@ -7511,6 +7575,15 @@ yn@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/yn/-/yn-1.2.0.tgz#d237a4c533f279b2b89d3acac2db4b8c795e4a63"
zip-stream@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-1.1.1.tgz#5216b48bbb4d2651f64d5c6e6f09eb4a7399d557"
dependencies:
archiver-utils "^1.3.0"
compress-commons "^1.1.0"
lodash "^4.8.0"
readable-stream "^2.0.0"
zip-stream@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-0.6.0.tgz#ee933aed996fb18b344a91ae3b5d264cec5e812b"