build(aio): change examples to CLI (#19248)

PR Close #19248
This commit is contained in:
Jesus Rodriguez
2017-08-22 21:31:15 +02:00
committed by Igor Minar
parent 344a5ca545
commit 9bbf009dff
377 changed files with 2339 additions and 1748 deletions

View File

@ -9,12 +9,14 @@ 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';
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.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 gpathPlnkr = path.join(sourceDirName, '**/*plnkr.json');
@ -43,14 +45,22 @@ class ExampleZipper {
return archive;
}
_getExampleType(sourceFolder) {
const filePath = path.join(sourceFolder, EXAMPLE_CONFIG_NAME);
try {
return require(filePath, 'utf-8').projectType || 'cli';
} catch (err) { // empty file, so it is cli
return 'cli';
}
}
_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;
const exampleType = this._getExampleType(path.join(sourceDirName, relativeDirName));
if (relativeDirName.indexOf('/') !== -1) { // Special example
exampleZipName = relativeDirName.split('/')[0];
} else {
@ -60,7 +70,20 @@ class ExampleZipper {
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'];
let alwaysIncludes = [
'bs-config.json',
'protractor.conf.js',
'.angular-cli.json',
'.editorconfig',
'.gitignore',
'tslint.json',
'karma-test-shim.js',
'karma.conf.js',
'src/testing/**/*',
'src/.babelrc',
'src/favicon.ico',
'src/typings.d.ts'
];
var defaultExcludes = [
'!**/bs-config.e2e.json',
'!**/*plnkr.*',
@ -70,7 +93,6 @@ class ExampleZipper {
'!**/package.json',
'!**/example-config.json',
'!**/wallaby.js',
'!**/tsconfig.json',
'!**/package.webpack.json',
// AoT related files
'!**/aot/**/*.*',
@ -129,13 +151,13 @@ class ExampleZipper {
// 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) {
if (exampleType === 'systemjs') {
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'});
}
// a modified tsconfig
let tsconfig = fs.readFileSync(this.exampleTsconfig, 'utf8');
zip.append(this._changeTypeRoots(tsconfig), {name: 'src/tsconfig.json'});
zip.finalize();
}