From ef62e6ae3480ae86febf316ae8517c82458a9fe3 Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Thu, 10 Nov 2016 10:26:37 +0100 Subject: [PATCH 1/6] Expose ngc i18n options --- packages/angular-cli/commands/build.ts | 8 +++++- packages/angular-cli/commands/serve.ts | 6 +++++ .../models/webpack-build-typescript.ts | 8 ++++-- packages/angular-cli/models/webpack-config.ts | 7 ++++-- .../angular-cli/tasks/build-webpack-watch.ts | 5 +++- packages/angular-cli/tasks/build-webpack.ts | 5 +++- packages/angular-cli/tasks/serve-webpack.ts | 5 +++- packages/angular-cli/utilities/completion.sh | 4 +-- packages/webpack/src/plugin.ts | 25 ++++++++++++++++--- 9 files changed, 60 insertions(+), 13 deletions(-) diff --git a/packages/angular-cli/commands/build.ts b/packages/angular-cli/commands/build.ts index a9ed8c3ee9cf..2f835a4a1a15 100644 --- a/packages/angular-cli/commands/build.ts +++ b/packages/angular-cli/commands/build.ts @@ -11,6 +11,9 @@ export interface BuildOptions { supressSizes: boolean; baseHref?: string; aot?: boolean; + i18nFile?: string; + i18nFormat?: string; + locale?: string; } const BuildCommand = Command.extend({ @@ -31,7 +34,10 @@ const BuildCommand = Command.extend({ { name: 'watcher', type: String }, { name: 'suppress-sizes', type: Boolean, default: false }, { name: 'base-href', type: String, default: null, aliases: ['bh'] }, - { name: 'aot', type: Boolean, default: false } + { name: 'aot', type: Boolean, default: false }, + { name: 'i18n-file', type: String, default: null }, + { name: 'i18n-format', type: String, default: null }, + { name: 'locale', type: String, default: null } ], run: function (commandOptions: BuildOptions) { diff --git a/packages/angular-cli/commands/serve.ts b/packages/angular-cli/commands/serve.ts index fc7d6ded01ff..d02fba48996b 100644 --- a/packages/angular-cli/commands/serve.ts +++ b/packages/angular-cli/commands/serve.ts @@ -27,6 +27,9 @@ export interface ServeTaskOptions { sslCert?: string; aot?: boolean; open?: boolean; + i18nFile?: string; + i18nFormat?: string; + locale?: string; } const ServeCommand = Command.extend({ @@ -88,6 +91,9 @@ const ServeCommand = Command.extend({ aliases: ['o'], description: 'Opens the url in default browser', }, + { name: 'i18n-file', type: String, default: null }, + { name: 'i18n-format', type: String, default: null }, + { name: 'locale', type: String, default: null } ], run: function(commandOptions: ServeTaskOptions) { diff --git a/packages/angular-cli/models/webpack-build-typescript.ts b/packages/angular-cli/models/webpack-build-typescript.ts index f1b511eca35a..e3e24f0c5e8b 100644 --- a/packages/angular-cli/models/webpack-build-typescript.ts +++ b/packages/angular-cli/models/webpack-build-typescript.ts @@ -47,7 +47,8 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo }; }; -export const getWebpackAotConfigPartial = function(projectRoot: string, appConfig: any) { +export const getWebpackAotConfigPartial = function(projectRoot: string, appConfig: any, + i18nFile: string, i18nFormat: string, locale:string) { return { module: { rules: [ @@ -61,7 +62,10 @@ export const getWebpackAotConfigPartial = function(projectRoot: string, appConfi plugins: [ new AotPlugin({ tsConfigPath: path.resolve(projectRoot, appConfig.root, appConfig.tsconfig), - mainPath: path.join(projectRoot, appConfig.root, appConfig.main) + mainPath: path.join(projectRoot, appConfig.root, appConfig.main), + i18nFile: i18nFile, + i18nFormat: i18nFormat, + locale: locale }), ] }; diff --git a/packages/angular-cli/models/webpack-config.ts b/packages/angular-cli/models/webpack-config.ts index 6317fef937a3..93cd5f6f373d 100644 --- a/packages/angular-cli/models/webpack-config.ts +++ b/packages/angular-cli/models/webpack-config.ts @@ -23,7 +23,10 @@ export class NgCliWebpackConfig { public environment: string, outputDir?: string, baseHref?: string, - isAoT = false + isAoT = false, + i18nFile?: string, + i18nFormat?: string, + locale?: string ) { const config: CliConfig = CliConfig.fromProject(); const appConfig = config.config.apps[0]; @@ -38,7 +41,7 @@ export class NgCliWebpackConfig { ); let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig); const typescriptConfigPartial = isAoT - ? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig) + ? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale) : getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig); if (appConfig.mobile) { diff --git a/packages/angular-cli/tasks/build-webpack-watch.ts b/packages/angular-cli/tasks/build-webpack-watch.ts index 45a1f6e55a55..466a8103e6a6 100644 --- a/packages/angular-cli/tasks/build-webpack-watch.ts +++ b/packages/angular-cli/tasks/build-webpack-watch.ts @@ -24,7 +24,10 @@ export default Task.extend({ runTaskOptions.environment, outputDir, runTaskOptions.baseHref, - runTaskOptions.aot + runTaskOptions.aot, + runTaskOptions.i18nFile, + runTaskOptions.i18nFormat, + runTaskOptions.locale ).config; const webpackCompiler: any = webpack(config); diff --git a/packages/angular-cli/tasks/build-webpack.ts b/packages/angular-cli/tasks/build-webpack.ts index e47564863eeb..830adc9c59b0 100644 --- a/packages/angular-cli/tasks/build-webpack.ts +++ b/packages/angular-cli/tasks/build-webpack.ts @@ -23,7 +23,10 @@ export default Task.extend({ runTaskOptions.environment, outputDir, runTaskOptions.baseHref, - runTaskOptions.aot + runTaskOptions.aot, + runTaskOptions.i18nFile, + runTaskOptions.i18nFormat, + runTaskOptions.locale ).config; const webpackCompiler: any = webpack(config); diff --git a/packages/angular-cli/tasks/serve-webpack.ts b/packages/angular-cli/tasks/serve-webpack.ts index 3f7d87849ee5..4c6184bb0e63 100644 --- a/packages/angular-cli/tasks/serve-webpack.ts +++ b/packages/angular-cli/tasks/serve-webpack.ts @@ -26,7 +26,10 @@ export default Task.extend({ commandOptions.environment, undefined, undefined, - commandOptions.aot + commandOptions.aot, + commandOptions.i18nFile, + commandOptions.i18nFormat, + commandOptions.locale ).config; // This allows for live reload of page when changes are made to repo. diff --git a/packages/angular-cli/utilities/completion.sh b/packages/angular-cli/utilities/completion.sh index 555233b7ec8f..e2e5489f3736 100644 --- a/packages/angular-cli/utilities/completion.sh +++ b/packages/angular-cli/utilities/completion.sh @@ -8,13 +8,13 @@ ng_opts='b build completion doc e2e g generate get github-pages:deploy gh-pages:deploy h help i init install lint make-this-awesome new s serve server set t test v version -h --help' -build_opts='--aot --base-href --environment --output-path --suppress-sizes --target --watch --watcher -bh -dev -e -o -prod -t -w' +build_opts='--aot --base-href --environment --i18n-file --i18n-format --locale --output-path --suppress-sizes --target --watch --watcher -bh -dev -e -o -prod -t -w' generate_opts='class component directive enum module pipe route service c cl d e m p r s --help' github_pages_deploy_opts='--base-href --environment --gh-token --gh-username --message --skip-build --target --user-page -bh -e -t' help_opts='--json --verbose -v' init_opts='--dry-run inline-style inline-template --link-cli --mobile --name --prefix --routing --skip-bower --skip-npm --source-dir --style --verbose -d -is -it -lc -n -p -sb -sd -sn -v' new_opts='--directory --dry-run inline-style inline-template --link-cli --mobile --prefix --routing --skip-bower --skip-git --skip-npm --source-dir --style --verbose -d -dir -is -it -lc -p -sb -sd -sg -sn -v' -serve_opts='--aot --environment --host --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --open --port --proxy-config --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -o -p -pc -t -w' +serve_opts='--aot --environment --host --i18n-file --i18n-format --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --locale --open --port --proxy-config --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -o -p -pc -t -w' set_opts='--global -g' test_opts='--browsers --build --code-coverage --colors --lint --log-level --port --reporters --watch -cc -l -w' diff --git a/packages/webpack/src/plugin.ts b/packages/webpack/src/plugin.ts index 4105c3f7cdbb..32a4f1f63b56 100644 --- a/packages/webpack/src/plugin.ts +++ b/packages/webpack/src/plugin.ts @@ -23,6 +23,9 @@ export interface AotPluginOptions { entryModule?: string; mainPath?: string; typeChecking?: boolean; + i18nFile?: string; + i18nFormat?: string; + locale?: string; } @@ -72,6 +75,9 @@ export class AotPlugin { private _basePath: string; private _genDir: string; + private _i18nFile: string; + private _i18nFormat: string; + private _locale: string; constructor(options: AotPluginOptions) { this._setupOptions(options); @@ -85,6 +91,9 @@ export class AotPlugin { get genDir() { return this._genDir; } get program() { return this._program; } get typeCheck() { return this._typeCheck; } + get i18nFile() { return this._i18nFile; } + get i18nFormat() { return this._i18nFormat; } + get locale() { return this._locale; } private _setupOptions(options: AotPluginOptions) { // Fill in the missing options. @@ -139,6 +148,16 @@ export class AotPlugin { this._reflectorHost = new ngCompiler.ReflectorHost( this._program, this._compilerHost, this._angularCompilerOptions); this._reflector = new ngCompiler.StaticReflector(this._reflectorHost); + + if (options.hasOwnProperty('i18nFile')) { + this._i18nFile = options.i18nFile; + } + if (options.hasOwnProperty('i18nFormat')) { + this._i18nFormat = options.i18nFormat; + } + if (options.hasOwnProperty('locale')) { + this._locale = options.locale; + } } // registration hook for webpack plugin @@ -202,9 +221,9 @@ export class AotPlugin { this._resourceLoader = new WebpackResourceLoader(compilation); const i18nOptions: ngCompiler.NgcCliOptions = { - i18nFile: undefined, - i18nFormat: undefined, - locale: undefined, + i18nFile: this.i18nFile, + i18nFormat: this.i18nFormat, + locale: this.locale, basePath: this.basePath }; From ee821ff88926f0c94084bccd0f94fb97465b36ae Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Thu, 10 Nov 2016 13:45:46 +0100 Subject: [PATCH 2/6] Add e2e test for i18n support --- tests/e2e/tests/build/aot-i18n.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/e2e/tests/build/aot-i18n.ts diff --git a/tests/e2e/tests/build/aot-i18n.ts b/tests/e2e/tests/build/aot-i18n.ts new file mode 100644 index 000000000000..7159e201f98f --- /dev/null +++ b/tests/e2e/tests/build/aot-i18n.ts @@ -0,0 +1,24 @@ +import {ng} from '../../utils/process'; +import {expectFileToMatch, writeFile, createDir, appendToFile} from '../../utils/fs'; + +export default function() { + return Promise.resolve() + .then(() => createDir('src/locale')) + .then(() => writeFile('src/locale/messages.fr.xlf', ` + + + + + + Hello i18n! + Bonjour i18n! + An introduction header for this sample + User welcome + + + + `)) + .then(() => appendToFile('src/app/app.component.html', '

Hello i18n!

')) + .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf' ,'--i18n-format', 'xlf', '--locale', 'fr')) + .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)); +} From 0b4b621c53a6fb5476ec0b4e0d6b96f18f032406 Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Thu, 10 Nov 2016 14:28:22 +0100 Subject: [PATCH 3/6] Fix tslint errors --- packages/angular-cli/models/webpack-build-typescript.ts | 2 +- tests/e2e/tests/build/aot-i18n.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/angular-cli/models/webpack-build-typescript.ts b/packages/angular-cli/models/webpack-build-typescript.ts index e3e24f0c5e8b..ca38d740ec0b 100644 --- a/packages/angular-cli/models/webpack-build-typescript.ts +++ b/packages/angular-cli/models/webpack-build-typescript.ts @@ -48,7 +48,7 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo }; export const getWebpackAotConfigPartial = function(projectRoot: string, appConfig: any, - i18nFile: string, i18nFormat: string, locale:string) { + i18nFile: string, i18nFormat: string, locale: string) { return { module: { rules: [ diff --git a/tests/e2e/tests/build/aot-i18n.ts b/tests/e2e/tests/build/aot-i18n.ts index 7159e201f98f..a9dedb1d8ef4 100644 --- a/tests/e2e/tests/build/aot-i18n.ts +++ b/tests/e2e/tests/build/aot-i18n.ts @@ -18,7 +18,9 @@ export default function() { `)) - .then(() => appendToFile('src/app/app.component.html', '

Hello i18n!

')) - .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf' ,'--i18n-format', 'xlf', '--locale', 'fr')) + .then(() => appendToFile('src/app/app.component.html', + '

Hello i18n!

')) + .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format', + 'xlf', '--locale', 'fr')) .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)); } From 5d4bfe02ed8632010a965a062c176d42a4ddad12 Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Fri, 11 Nov 2016 17:40:22 +0100 Subject: [PATCH 4/6] Remove meaning --- tests/e2e/tests/build/aot-i18n.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/e2e/tests/build/aot-i18n.ts b/tests/e2e/tests/build/aot-i18n.ts index a9dedb1d8ef4..cd21bac73c4f 100644 --- a/tests/e2e/tests/build/aot-i18n.ts +++ b/tests/e2e/tests/build/aot-i18n.ts @@ -9,17 +9,16 @@ export default function() { - + Hello i18n! Bonjour i18n! An introduction header for this sample - User welcome `)) .then(() => appendToFile('src/app/app.component.html', - '

Hello i18n!

')) + '

Hello i18n!

')) .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format', 'xlf', '--locale', 'fr')) .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)); From 935787abae8267ce410ecb871d595826d0df081c Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Fri, 11 Nov 2016 19:11:53 +0100 Subject: [PATCH 5/6] Add negative test --- tests/e2e/tests/build/aot-i18n.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/e2e/tests/build/aot-i18n.ts b/tests/e2e/tests/build/aot-i18n.ts index cd21bac73c4f..a4479ba7bb4d 100644 --- a/tests/e2e/tests/build/aot-i18n.ts +++ b/tests/e2e/tests/build/aot-i18n.ts @@ -1,5 +1,6 @@ import {ng} from '../../utils/process'; import {expectFileToMatch, writeFile, createDir, appendToFile} from '../../utils/fs'; +import {expectToFail} from '../../utils/utils'; export default function() { return Promise.resolve() @@ -21,5 +22,8 @@ export default function() { '

Hello i18n!

')) .then(() => ng('build', '--aot', '--i18n-file', 'src/locale/messages.fr.xlf', '--i18n-format', 'xlf', '--locale', 'fr')) - .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)); + .then(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/)) + .then(() => ng('build', '--aot')) + .then(() => expectToFail(() => expectFileToMatch('dist/main.bundle.js', /Bonjour i18n!/))) + .then(() => expectFileToMatch('dist/main.bundle.js', /Hello i18n!/)); } From 33be929ea544d4038d44f42465116a2ac17a8269 Mon Sep 17 00:00:00 2001 From: Tom De Smet Date: Wed, 14 Dec 2016 10:37:11 +0100 Subject: [PATCH 6/6] Remove .orig artifacts from kdiff3 --- packages/@ngtools/webpack/src/plugin.ts.orig | 456 ------------------ packages/angular-cli/commands/build.ts.orig | 91 ---- packages/angular-cli/commands/serve.ts.orig | 187 ------- .../angular-cli/models/webpack-config.ts.orig | 86 ---- .../tasks/build-webpack-watch.ts.orig | 58 --- .../angular-cli/tasks/build-webpack.ts.orig | 73 --- .../angular-cli/tasks/serve-webpack.ts.orig | 140 ------ .../angular-cli/utilities/completion.sh.orig | 93 ---- 8 files changed, 1184 deletions(-) delete mode 100644 packages/@ngtools/webpack/src/plugin.ts.orig delete mode 100644 packages/angular-cli/commands/build.ts.orig delete mode 100644 packages/angular-cli/commands/serve.ts.orig delete mode 100644 packages/angular-cli/models/webpack-config.ts.orig delete mode 100644 packages/angular-cli/tasks/build-webpack-watch.ts.orig delete mode 100644 packages/angular-cli/tasks/build-webpack.ts.orig delete mode 100644 packages/angular-cli/tasks/serve-webpack.ts.orig delete mode 100644 packages/angular-cli/utilities/completion.sh.orig diff --git a/packages/@ngtools/webpack/src/plugin.ts.orig b/packages/@ngtools/webpack/src/plugin.ts.orig deleted file mode 100644 index ca97d8a3f8e2..000000000000 --- a/packages/@ngtools/webpack/src/plugin.ts.orig +++ /dev/null @@ -1,456 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as ts from 'typescript'; - -import {NgModule} from '@angular/core'; -import * as ngCompiler from '@angular/compiler-cli'; -import {tsc} from '@angular/tsc-wrapped/src/tsc'; - -import {patchReflectorHost} from './reflector_host'; -import {WebpackResourceLoader} from './resource_loader'; -import {createResolveDependenciesFromContextMap} from './utils'; -import {WebpackCompilerHost} from './compiler_host'; -import {resolveEntryModuleFromMain} from './entry_resolver'; -import {StaticSymbol} from '@angular/compiler-cli'; -import {Tapable} from './webpack'; -import {PathsPlugin} from './paths-plugin'; - - -/** - * Option Constants - */ -export interface AotPluginOptions { - tsConfigPath: string; - basePath?: string; - entryModule?: string; - mainPath?: string; - typeChecking?: boolean; -<<<<<<< HEAD:packages/webpack/src/plugin.ts - i18nFile?: string; - i18nFormat?: string; - locale?: string; -======= - - skipCodeGeneration?: boolean; ->>>>>>> upstream/master:packages/@ngtools/webpack/src/plugin.ts -} - - -export interface LazyRoute { - moduleRoute: ModuleRoute; - absolutePath: string; - absoluteGenDirPath: string; -} - - -export interface LazyRouteMap { - [path: string]: LazyRoute; -} - - -export class ModuleRoute { - constructor(public readonly path: string, public readonly className: string = null) {} - - toString() { - return `${this.path}#${this.className}`; - } - - static fromString(entry: string): ModuleRoute { - const split = entry.split('#'); - return new ModuleRoute(split[0], split[1]); - } -} - - -export class AotPlugin implements Tapable { - private _entryModule: ModuleRoute; - private _compilerOptions: ts.CompilerOptions; - private _angularCompilerOptions: ngCompiler.AngularCompilerOptions; - private _program: ts.Program; - private _reflector: ngCompiler.StaticReflector; - private _reflectorHost: ngCompiler.ReflectorHost; - private _rootFilePath: string[]; - private _compilerHost: WebpackCompilerHost; - private _resourceLoader: WebpackResourceLoader; - private _lazyRoutes: { [route: string]: string }; - private _tsConfigPath: string; - - private _donePromise: Promise; - private _compiler: any = null; - private _compilation: any = null; - - private _typeCheck: boolean = true; - private _skipCodeGeneration: boolean = false; - private _basePath: string; - private _genDir: string; - - private _i18nFile: string; - private _i18nFormat: string; - private _locale: string; - - constructor(options: AotPluginOptions) { - this._setupOptions(options); - } - - get basePath() { return this._basePath; } - get compilation() { return this._compilation; } - get compilerHost() { return this._compilerHost; } - get compilerOptions() { return this._compilerOptions; } - get done() { return this._donePromise; } - get entryModule() { return this._entryModule; } - get genDir() { return this._genDir; } - get program() { return this._program; } - get skipCodeGeneration() { return this._skipCodeGeneration; } - get typeCheck() { return this._typeCheck; } - get i18nFile() { return this._i18nFile; } - get i18nFormat() { return this._i18nFormat; } - get locale() { return this._locale; } - - private _setupOptions(options: AotPluginOptions) { - // Fill in the missing options. - if (!options.hasOwnProperty('tsConfigPath')) { - throw new Error('Must specify "tsConfigPath" in the configuration of @ngtools/webpack.'); - } - this._tsConfigPath = options.tsConfigPath; - - // Check the base path. - const maybeBasePath = path.resolve(process.cwd(), this._tsConfigPath); - let basePath = maybeBasePath; - if (fs.statSync(maybeBasePath).isFile()) { - basePath = path.dirname(basePath); - } - if (options.hasOwnProperty('basePath')) { - basePath = path.resolve(process.cwd(), options.basePath); - } - - const tsConfig = tsc.readConfiguration(this._tsConfigPath, basePath); - this._rootFilePath = tsConfig.parsed.fileNames - .filter(fileName => !/\.spec\.ts$/.test(fileName)); - - // Check the genDir. - let genDir = basePath; - if (tsConfig.ngOptions.hasOwnProperty('genDir')) { - genDir = tsConfig.ngOptions.genDir; - } - - this._compilerOptions = tsConfig.parsed.options; - - this._angularCompilerOptions = Object.assign({}, tsConfig.ngOptions, { basePath, genDir }); - this._basePath = basePath; - this._genDir = genDir; - - if (options.hasOwnProperty('typeChecking')) { - this._typeCheck = options.typeChecking; - } - if (options.hasOwnProperty('skipCodeGeneration')) { - this._skipCodeGeneration = options.skipCodeGeneration; - } - - this._compilerHost = new WebpackCompilerHost(this._compilerOptions, this._basePath); - this._program = ts.createProgram( - this._rootFilePath, this._compilerOptions, this._compilerHost); - - if (options.entryModule) { - this._entryModule = ModuleRoute.fromString(options.entryModule); - } else { - if (options.mainPath) { - const entryModuleString = resolveEntryModuleFromMain(options.mainPath, this._compilerHost, - this._program); - this._entryModule = ModuleRoute.fromString(entryModuleString); - } else { - this._entryModule = ModuleRoute.fromString((tsConfig.ngOptions as any).entryModule); - } - } - - this._reflectorHost = new ngCompiler.ReflectorHost( - this._program, this._compilerHost, this._angularCompilerOptions); - this._reflector = new ngCompiler.StaticReflector(this._reflectorHost); - - if (options.hasOwnProperty('i18nFile')) { - this._i18nFile = options.i18nFile; - } - if (options.hasOwnProperty('i18nFormat')) { - this._i18nFormat = options.i18nFormat; - } - if (options.hasOwnProperty('locale')) { - this._locale = options.locale; - } - } - - // registration hook for webpack plugin - apply(compiler: any) { - this._compiler = compiler; - - compiler.plugin('context-module-factory', (cmf: any) => { - cmf.plugin('before-resolve', (request: any, callback: (err?: any, request?: any) => void) => { - if (!request) { - return callback(); - } - - request.request = this.skipCodeGeneration ? this.basePath : this.genDir; - request.recursive = true; - request.dependencies.forEach((d: any) => d.critical = false); - return callback(null, request); - }); - cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => { - if (!result) { - return callback(); - } - - this.done.then(() => { - result.resource = this.skipCodeGeneration ? this.basePath : this.genDir; - result.recursive = true; - result.dependencies.forEach((d: any) => d.critical = false); - result.resolveDependencies = createResolveDependenciesFromContextMap( - (_: any, cb: any) => cb(null, this._lazyRoutes)); - - return callback(null, result); - }).catch((err) => callback(err)); - }); - }); - - compiler.plugin('make', (compilation: any, cb: any) => this._make(compilation, cb)); - compiler.plugin('after-emit', (compilation: any, cb: any) => { - this._donePromise = null; - this._compilation = null; - compilation._ngToolsWebpackPluginInstance = null; - cb(); - }); - - // Virtual file system. - compiler.resolvers.normal.plugin('resolve', (request: any, cb?: (err?: any) => void) => { - if (request.request.match(/\.ts$/)) { - this.done - .then(() => cb()) - .catch((err) => cb(err)); - } else { - cb(); - } - }); - compiler.resolvers.normal.apply(new PathsPlugin({ - tsConfigPath: this._tsConfigPath, - compilerOptions: this._compilerOptions, - compilerHost: this._compilerHost - })); - } - - private _make(compilation: any, cb: (err?: any, request?: any) => void) { - this._compilation = compilation; - if (this._compilation._ngToolsWebpackPluginInstance) { - return cb(new Error('An @ngtools/webpack plugin already exist for this compilation.')); - } - this._compilation._ngToolsWebpackPluginInstance = this; - - this._resourceLoader = new WebpackResourceLoader(compilation); - - const i18nOptions: ngCompiler.NgcCliOptions = { - i18nFile: this.i18nFile, - i18nFormat: this.i18nFormat, - locale: this.locale, - basePath: this.basePath - }; - - this._donePromise = Promise.resolve() - .then(() => { - if (this._skipCodeGeneration) { - return; - } - - // Create the Code Generator. - const codeGenerator = ngCompiler.CodeGenerator.create( - this._angularCompilerOptions, - i18nOptions, - this._program, - this._compilerHost, - new ngCompiler.NodeReflectorHostContext(this._compilerHost), - this._resourceLoader - ); - - // We need to temporarily patch the CodeGenerator until either it's patched or allows us - // to pass in our own ReflectorHost. - // TODO: remove this. - patchReflectorHost(codeGenerator); - return codeGenerator.codegen({ transitiveModules: true }); - }) - .then(() => { - // Create a new Program, based on the old one. This will trigger a resolution of all - // transitive modules, which include files that might just have been generated. - // This needs to happen after the code generator has been created for generated files - // to be properly resolved. - this._program = ts.createProgram( - this._rootFilePath, this._compilerOptions, this._compilerHost, this._program); - }) - .then(() => { - const diagnostics = this._program.getGlobalDiagnostics(); - if (diagnostics.length > 0) { - const message = diagnostics - .map(diagnostic => { - const {line, character} = diagnostic.file.getLineAndCharacterOfPosition( - diagnostic.start); - const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - return `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message})`; - }) - .join('\n'); - - throw new Error(message); - } - }) - .then(() => { - // Populate the file system cache with the virtual module. - this._compilerHost.populateWebpackResolver(this._compiler.resolvers.normal); - }) - .then(() => { - // Process the lazy routes - this._lazyRoutes = {}; - const allLazyRoutes = this._processNgModule(this._entryModule, null); - Object.keys(allLazyRoutes) - .forEach(k => { - const lazyRoute = allLazyRoutes[k]; - if (this.skipCodeGeneration) { - this._lazyRoutes[k] = lazyRoute.absolutePath + '.ts'; - } else { - this._lazyRoutes[k + '.ngfactory'] = lazyRoute.absoluteGenDirPath + '.ngfactory.ts'; - } - }); - }) - .then(() => cb(), (err: any) => { cb(err); }); - } - - private _resolveModulePath(module: ModuleRoute, containingFile: string) { - if (module.path.startsWith('.')) { - return path.join(path.dirname(containingFile), module.path); - } - return module.path; - } - - private _processNgModule(module: ModuleRoute, containingFile: string | null): LazyRouteMap { - const modulePath = containingFile ? module.path : ('./' + path.basename(module.path)); - if (containingFile === null) { - containingFile = module.path + '.ts'; - } - const relativeModulePath = this._resolveModulePath(module, containingFile); - - const staticSymbol = this._reflectorHost - .findDeclaration(modulePath, module.className, containingFile); - const entryNgModuleMetadata = this.getNgModuleMetadata(staticSymbol); - const loadChildrenRoute: LazyRoute[] = this.extractLoadChildren(entryNgModuleMetadata) - .map(route => { - const moduleRoute = ModuleRoute.fromString(route); - const resolvedModule = ts.resolveModuleName(moduleRoute.path, - relativeModulePath, this._compilerOptions, this._compilerHost); - - if (!resolvedModule.resolvedModule) { - throw new Error(`Could not resolve route "${route}" from file "${relativeModulePath}".`); - } - - const relativePath = path.relative(this.basePath, - resolvedModule.resolvedModule.resolvedFileName).replace(/\.ts$/, ''); - - const absolutePath = path.join(this.basePath, relativePath); - const absoluteGenDirPath = path.join(this._genDir, relativePath); - - return { - moduleRoute, - absoluteGenDirPath, - absolutePath - }; - }); - const resultMap: LazyRouteMap = loadChildrenRoute - .reduce((acc: LazyRouteMap, curr: LazyRoute) => { - const key = curr.moduleRoute.path; - if (acc[key]) { - if (acc[key].absolutePath != curr.absolutePath) { - throw new Error(`Duplicated path in loadChildren detected: "${key}" is used in 2 ` + - 'loadChildren, but they point to different modules. Webpack cannot distinguish ' + - 'between the two based on context and would fail to load the proper one.'); - } - } else { - acc[key] = curr; - } - return acc; - }, {}); - - // Also concatenate every child of child modules. - for (const lazyRoute of loadChildrenRoute) { - const mr = lazyRoute.moduleRoute; - const children = this._processNgModule(mr, relativeModulePath); - Object.keys(children).forEach(p => { - const child = children[p]; - const key = child.moduleRoute.path; - if (resultMap[key]) { - if (resultMap[key].absolutePath != child.absolutePath) { - throw new Error(`Duplicated path in loadChildren detected: "${key}" is used in 2 ` + - 'loadChildren, but they point to different modules. Webpack cannot distinguish ' + - 'between the two based on context and would fail to load the proper one.'); - } - } else { - resultMap[key] = child; - } - }); - } - return resultMap; - } - - private getNgModuleMetadata(staticSymbol: ngCompiler.StaticSymbol) { - const ngModules = this._reflector.annotations(staticSymbol).filter(s => s instanceof NgModule); - if (ngModules.length === 0) { - throw new Error(`${staticSymbol.name} is not an NgModule`); - } - return ngModules[0]; - } - - private extractLoadChildren(ngModuleDecorator: any): any[] { - const routes = (ngModuleDecorator.imports || []).reduce((mem: any[], m: any) => { - return mem.concat(this.collectRoutes(m.providers)); - }, this.collectRoutes(ngModuleDecorator.providers)); - return this.collectLoadChildren(routes) - .concat((ngModuleDecorator.imports || []) - // Also recursively extractLoadChildren of modules we import. - .map((staticSymbol: any) => { - if (staticSymbol instanceof StaticSymbol) { - const entryNgModuleMetadata = this.getNgModuleMetadata(staticSymbol); - return this.extractLoadChildren(entryNgModuleMetadata); - } else { - return []; - } - }) - // Poor man's flat map. - .reduce((acc: any[], i: any) => acc.concat(i), [])) - .filter(x => !!x); - } - - private collectRoutes(providers: any[]): any[] { - if (!providers) { - return []; - } - const ROUTES = this._reflectorHost.findDeclaration( - '@angular/router/src/router_config_loader', 'ROUTES', undefined); - - return providers.reduce((m, p) => { - if (p.provide === ROUTES) { - return m.concat(p.useValue); - } else if (Array.isArray(p)) { - return m.concat(this.collectRoutes(p)); - } else { - return m; - } - }, []); - } - - private collectLoadChildren(routes: any[]): any[] { - if (!routes) { - return []; - } - return routes.reduce((m, r) => { - if (r.loadChildren) { - return m.concat(r.loadChildren); - } else if (Array.isArray(r)) { - return m.concat(this.collectLoadChildren(r)); - } else if (r.children) { - return m.concat(this.collectLoadChildren(r.children)); - } else { - return m; - } - }, []); - } -} diff --git a/packages/angular-cli/commands/build.ts.orig b/packages/angular-cli/commands/build.ts.orig deleted file mode 100644 index 7321479c762c..000000000000 --- a/packages/angular-cli/commands/build.ts.orig +++ /dev/null @@ -1,91 +0,0 @@ -const Command = require('../ember-cli/lib/models/command'); -import WebpackBuild from '../tasks/build-webpack'; -import WebpackBuildWatch from '../tasks/build-webpack-watch'; - -export interface BuildOptions { - target?: string; - environment?: string; - outputPath?: string; - watch?: boolean; - watcher?: string; - supressSizes: boolean; - baseHref?: string; - aot?: boolean; -<<<<<<< HEAD - i18nFile?: string; - i18nFormat?: string; - locale?: string; -======= - sourcemap?: boolean; - vendorChunk?: boolean; - verbose?: boolean; - progress?: boolean; ->>>>>>> upstream/master -} - -const BuildCommand = Command.extend({ - name: 'build', - description: 'Builds your app and places it into the output path (dist/ by default).', - aliases: ['b'], - - availableOptions: [ - { - name: 'target', - type: String, - default: 'development', - aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] - }, - { name: 'environment', type: String, default: '', aliases: ['e'] }, - { name: 'output-path', type: 'Path', default: null, aliases: ['o'] }, - { name: 'watch', type: Boolean, default: false, aliases: ['w'] }, - { name: 'watcher', type: String }, - { name: 'suppress-sizes', type: Boolean, default: false }, - { name: 'base-href', type: String, default: null, aliases: ['bh'] }, - { name: 'aot', type: Boolean, default: false }, -<<<<<<< HEAD - { name: 'i18n-file', type: String, default: null }, - { name: 'i18n-format', type: String, default: null }, - { name: 'locale', type: String, default: null } -======= - { name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] }, - { name: 'vendor-chunk', type: Boolean, default: true }, - { name: 'verbose', type: Boolean, default: false }, - { name: 'progress', type: Boolean, default: true } ->>>>>>> upstream/master - ], - - run: function (commandOptions: BuildOptions) { - if (commandOptions.environment === '') { - if (commandOptions.target === 'development') { - commandOptions.environment = 'dev'; - } - if (commandOptions.target === 'production') { - commandOptions.environment = 'prod'; - } - } - - const project = this.project; - const ui = this.ui; - const buildTask = commandOptions.watch ? - new WebpackBuildWatch({ - cliProject: project, - ui: ui, - outputPath: commandOptions.outputPath, - target: commandOptions.target, - environment: commandOptions.environment - }) : - new WebpackBuild({ - cliProject: project, - ui: ui, - outputPath: commandOptions.outputPath, - target: commandOptions.target, - environment: commandOptions.environment, - }); - - return buildTask.run(commandOptions); - } -}); - - -BuildCommand.overrideCore = true; -export default BuildCommand; diff --git a/packages/angular-cli/commands/serve.ts.orig b/packages/angular-cli/commands/serve.ts.orig deleted file mode 100644 index 1df70d5bc4c7..000000000000 --- a/packages/angular-cli/commands/serve.ts.orig +++ /dev/null @@ -1,187 +0,0 @@ -import * as assign from 'lodash/assign'; -import * as denodeify from 'denodeify'; -const Command = require('../ember-cli/lib/models/command'); -const SilentError = require('silent-error'); -const PortFinder = require('portfinder'); -import ServeWebpackTask from '../tasks/serve-webpack'; - -PortFinder.basePort = 49152; - -const getPort = denodeify(PortFinder.getPort); -const defaultPort = process.env.PORT || 4200; - -export interface ServeTaskOptions { - port?: number; - host?: string; - proxyConfig?: string; - watcher?: string; - liveReload?: boolean; - liveReloadHost?: string; - liveReloadPort?: number; - liveReloadBaseUrl?: string; - liveReloadLiveCss?: boolean; - target?: string; - environment?: string; - ssl?: boolean; - sslKey?: string; - sslCert?: string; - aot?: boolean; - sourcemap?: boolean; - verbose?: boolean; - progress?: boolean; - open?: boolean; -<<<<<<< HEAD - i18nFile?: string; - i18nFormat?: string; - locale?: string; -======= - vendorChunk?: boolean; - hmr?: boolean; ->>>>>>> upstream/master -} - -const ServeCommand = Command.extend({ - name: 'serve', - description: 'Builds and serves your app, rebuilding on file changes.', - aliases: ['server', 's'], - - availableOptions: [ - { name: 'port', type: Number, default: defaultPort, aliases: ['p'] }, - { - name: 'host', - type: String, - default: 'localhost', - aliases: ['H'], - description: 'Listens only on localhost by default' - }, - { name: 'proxy-config', type: 'Path', aliases: ['pc'] }, - { name: 'watcher', type: String, default: 'events', aliases: ['w'] }, - { name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] }, - { - name: 'live-reload-host', - type: String, - aliases: ['lrh'], - description: 'Defaults to host' - }, - { - name: 'live-reload-base-url', - type: String, - aliases: ['lrbu'], - description: 'Defaults to baseURL' - }, - { - name: 'live-reload-port', - type: Number, - aliases: ['lrp'], - description: '(Defaults to port number within [49152...65535])' - }, - { - name: 'live-reload-live-css', - type: Boolean, - default: true, - description: 'Whether to live reload CSS (default true)' - }, - { - name: 'target', - type: String, - default: 'development', - aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] - }, - { name: 'environment', type: String, default: '', aliases: ['e'] }, - { name: 'ssl', type: Boolean, default: false }, - { name: 'ssl-key', type: String, default: 'ssl/server.key' }, - { name: 'ssl-cert', type: String, default: 'ssl/server.crt' }, - { name: 'aot', type: Boolean, default: false }, - { name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] }, - { name: 'vendor-chunk', type: Boolean, default: true }, - { name: 'verbose', type: Boolean, default: false }, - { name: 'progress', type: Boolean, default: true }, - { - name: 'open', - type: Boolean, - default: false, - aliases: ['o'], - description: 'Opens the url in default browser', - }, -<<<<<<< HEAD - { name: 'i18n-file', type: String, default: null }, - { name: 'i18n-format', type: String, default: null }, - { name: 'locale', type: String, default: null } -======= - { - name: 'hmr', - type: Boolean, - default: false, - description: 'Enable hot module replacement', - }, ->>>>>>> upstream/master - ], - - run: function(commandOptions: ServeTaskOptions) { - if (commandOptions.environment === '') { - if (commandOptions.target === 'development') { - commandOptions.environment = 'dev'; - } - if (commandOptions.target === 'production') { - commandOptions.environment = 'prod'; - } - } - - commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host; - - return this._checkExpressPort(commandOptions) - .then(this._autoFindLiveReloadPort.bind(this)) - .then((opts: ServeTaskOptions) => { - commandOptions = assign({}, opts, { - baseURL: this.project.config(commandOptions.target).baseURL || '/' - }); - - const serve = new ServeWebpackTask({ - ui: this.ui, - analytics: this.analytics, - project: this.project, - }); - - return serve.run(commandOptions); - }); - }, - - _checkExpressPort: function(commandOptions: ServeTaskOptions) { - return getPort({ port: commandOptions.port, host: commandOptions.host }) - .then((foundPort: number) => { - - if (commandOptions.port !== foundPort && commandOptions.port !== 0) { - throw new SilentError(`Port ${commandOptions.port} is already in use.`); - } - - // otherwise, our found port is good - commandOptions.port = foundPort; - return commandOptions; - - }); - }, - - _autoFindLiveReloadPort: function(commandOptions: ServeTaskOptions) { - return getPort({ port: commandOptions.liveReloadPort, host: commandOptions.liveReloadHost }) - .then((foundPort: number) => { - - // if live reload port matches express port, try one higher - if (foundPort === commandOptions.port) { - commandOptions.liveReloadPort = foundPort + 1; - return this._autoFindLiveReloadPort(commandOptions); - } - - // port was already open - if (foundPort === commandOptions.liveReloadPort) { - return commandOptions; - } - - // use found port as live reload port - commandOptions.liveReloadPort = foundPort; - return commandOptions; - - }); - } -}); - -export default ServeCommand; diff --git a/packages/angular-cli/models/webpack-config.ts.orig b/packages/angular-cli/models/webpack-config.ts.orig deleted file mode 100644 index 830672b95f64..000000000000 --- a/packages/angular-cli/models/webpack-config.ts.orig +++ /dev/null @@ -1,86 +0,0 @@ -import { - getWebpackAotConfigPartial, - getWebpackNonAotConfigPartial -} from './webpack-build-typescript'; -const webpackMerge = require('webpack-merge'); -import { CliConfig } from './config'; -import { getWebpackCommonConfig } from './webpack-build-common'; -import { getWebpackDevConfigPartial } from './webpack-build-development'; -import { getWebpackProdConfigPartial } from './webpack-build-production'; -import { - getWebpackMobileConfigPartial, - getWebpackMobileProdConfigPartial -} from './webpack-build-mobile'; - - -export class NgCliWebpackConfig { - // TODO: When webpack2 types are finished lets replace all these any types - // so this is more maintainable in the future for devs - public config: any; - - constructor( - public ngCliProject: any, - public target: string, - public environment: string, - outputDir?: string, - baseHref?: string, - isAoT = false, -<<<<<<< HEAD - i18nFile?: string, - i18nFormat?: string, - locale?: string -======= - sourcemap = true, - vendorChunk = false, - verbose = false, - progress = true ->>>>>>> upstream/master - ) { - const config: CliConfig = CliConfig.fromProject(); - const appConfig = config.config.apps[0]; - - appConfig.outDir = outputDir || appConfig.outDir; - - let baseConfig = getWebpackCommonConfig( - this.ngCliProject.root, - environment, - appConfig, - baseHref, - sourcemap, - vendorChunk, - verbose, - progress - ); - let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig, verbose); - const typescriptConfigPartial = isAoT - ? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale) - : getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig); - - if (appConfig.mobile) { - let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig); - let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root, - appConfig); - baseConfig = webpackMerge(baseConfig, mobileConfigPartial); - if (this.target == 'production') { - targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial); - } - } - - this.config = webpackMerge( - baseConfig, - targetConfigPartial, - typescriptConfigPartial - ); - } - - getTargetConfig(projectRoot: string, appConfig: any, verbose: boolean): any { - switch (this.target) { - case 'development': - return getWebpackDevConfigPartial(projectRoot, appConfig); - case 'production': - return getWebpackProdConfigPartial(projectRoot, appConfig, verbose); - default: - throw new Error("Invalid build target. Only 'development' and 'production' are available."); - } - } -} diff --git a/packages/angular-cli/tasks/build-webpack-watch.ts.orig b/packages/angular-cli/tasks/build-webpack-watch.ts.orig deleted file mode 100644 index 182f4996ee0b..000000000000 --- a/packages/angular-cli/tasks/build-webpack-watch.ts.orig +++ /dev/null @@ -1,58 +0,0 @@ -import * as rimraf from 'rimraf'; -import * as path from 'path'; -const Task = require('../ember-cli/lib/models/task'); -import * as webpack from 'webpack'; -import { NgCliWebpackConfig } from '../models/webpack-config'; -import { getWebpackStatsConfig } from '../models/'; -import { BuildOptions } from '../commands/build'; -import { CliConfig } from '../models/config'; - -let lastHash: any = null; - -export default Task.extend({ - run: function(runTaskOptions: BuildOptions) { - - const project = this.cliProject; - - const outputDir = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir; - rimraf.sync(path.resolve(project.root, outputDir)); - - const config = new NgCliWebpackConfig( - project, - runTaskOptions.target, - runTaskOptions.environment, - outputDir, - runTaskOptions.baseHref, - runTaskOptions.aot, -<<<<<<< HEAD - runTaskOptions.i18nFile, - runTaskOptions.i18nFormat, - runTaskOptions.locale -======= - runTaskOptions.sourcemap, - runTaskOptions.vendorChunk, - runTaskOptions.verbose, - runTaskOptions.progress ->>>>>>> upstream/master - ).config; - const webpackCompiler: any = webpack(config); - - const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose); - - return new Promise((resolve, reject) => { - webpackCompiler.watch({}, (err: any, stats: any) => { - if (err) { - lastHash = null; - console.error(err.stack || err); - if (err.details) { console.error(err.details); } - reject(err.details); - } - - if (stats.hash !== lastHash) { - lastHash = stats.hash; - process.stdout.write(stats.toString(statsConfig) + '\n'); - } - }); - }); - } -}); diff --git a/packages/angular-cli/tasks/build-webpack.ts.orig b/packages/angular-cli/tasks/build-webpack.ts.orig deleted file mode 100644 index 8517f92bd334..000000000000 --- a/packages/angular-cli/tasks/build-webpack.ts.orig +++ /dev/null @@ -1,73 +0,0 @@ -import * as rimraf from 'rimraf'; -import * as path from 'path'; -const Task = require('../ember-cli/lib/models/task'); -import * as webpack from 'webpack'; -import { BuildOptions } from '../commands/build'; -import { NgCliWebpackConfig } from '../models/webpack-config'; -import { getWebpackStatsConfig } from '../models/'; -import { CliConfig } from '../models/config'; - - -// Configure build and output; -let lastHash: any = null; - -export default Task.extend({ - run: function (runTaskOptions: BuildOptions) { - - const project = this.cliProject; - - const outputDir = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir; - rimraf.sync(path.resolve(project.root, outputDir)); - const config = new NgCliWebpackConfig( - project, - runTaskOptions.target, - runTaskOptions.environment, - outputDir, - runTaskOptions.baseHref, - runTaskOptions.aot, -<<<<<<< HEAD - runTaskOptions.i18nFile, - runTaskOptions.i18nFormat, - runTaskOptions.locale -======= - runTaskOptions.sourcemap, - runTaskOptions.vendorChunk, - runTaskOptions.verbose, - runTaskOptions.progress ->>>>>>> upstream/master - ).config; - - const webpackCompiler: any = webpack(config); - - const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose); - - return new Promise((resolve, reject) => { - webpackCompiler.run((err: any, stats: any) => { - if (err) { - return reject(err); - } - - // Don't keep cache - // TODO: Make conditional if using --watch - webpackCompiler.purgeInputFileSystem(); - - if (stats.hash !== lastHash) { - lastHash = stats.hash; - process.stdout.write(stats.toString(statsConfig) + '\n'); - } - - if (stats.hasErrors()) { - reject(); - } else { - resolve(); - } - }); - }) - .catch((err: Error) => { - if (err) { - this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err)); - } - throw err; - }); - } -}); diff --git a/packages/angular-cli/tasks/serve-webpack.ts.orig b/packages/angular-cli/tasks/serve-webpack.ts.orig deleted file mode 100644 index 60fca2753852..000000000000 --- a/packages/angular-cli/tasks/serve-webpack.ts.orig +++ /dev/null @@ -1,140 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as chalk from 'chalk'; -const SilentError = require('silent-error'); -const Task = require('../ember-cli/lib/models/task'); -import * as webpack from 'webpack'; -const WebpackDevServer = require('webpack-dev-server'); -import { getWebpackStatsConfig } from '../models/'; -import { NgCliWebpackConfig } from '../models/webpack-config'; -import { ServeTaskOptions } from '../commands/serve'; -import { CliConfig } from '../models/config'; -import { oneLine } from 'common-tags'; -import * as url from 'url'; -const opn = require('opn'); - -export default Task.extend({ - run: function(serveTaskOptions: ServeTaskOptions) { - const ui = this.ui; - - let webpackCompiler: any; - - let config = new NgCliWebpackConfig( - this.project, - serveTaskOptions.target, - serveTaskOptions.environment, - undefined, - undefined, -<<<<<<< HEAD - commandOptions.aot, - commandOptions.i18nFile, - commandOptions.i18nFormat, - commandOptions.locale -======= - serveTaskOptions.aot, - serveTaskOptions.sourcemap, - serveTaskOptions.vendorChunk, - serveTaskOptions.verbose, - serveTaskOptions.progress ->>>>>>> upstream/master - ).config; - - // This allows for live reload of page when changes are made to repo. - // https://webpack.github.io/docs/webpack-dev-server.html#inline-mode - let entryPoints = [ - `webpack-dev-server/client?http://${serveTaskOptions.host}:${serveTaskOptions.port}/` - ]; - if (serveTaskOptions.hmr) { - const webpackHmrLink = 'https://webpack.github.io/docs/hot-module-replacement.html'; - ui.writeLine(oneLine` - ${chalk.yellow('NOTICE')} Hot Module Replacement (HMR) is enabled for the dev server. - `); - ui.writeLine(' The project will still live reload when HMR is enabled,'); - ui.writeLine(' but to take advantage of HMR additional application code is required'); - ui.writeLine(' (not included in an angular-cli project by default).'); - ui.writeLine(` See ${chalk.blue(webpackHmrLink)}`); - ui.writeLine(' for information on working with HMR for Webpack.'); - entryPoints.push('webpack/hot/dev-server'); - config.plugins.push(new webpack.HotModuleReplacementPlugin()); - } - config.entry.main.unshift(...entryPoints); - webpackCompiler = webpack(config); - - const statsConfig = getWebpackStatsConfig(serveTaskOptions.verbose); - - let proxyConfig = {}; - if (serveTaskOptions.proxyConfig) { - const proxyPath = path.resolve(this.project.root, serveTaskOptions.proxyConfig); - if (fs.existsSync(proxyPath)) { - proxyConfig = require(proxyPath); - } else { - const message = 'Proxy config file ' + proxyPath + ' does not exist.'; - return Promise.reject(new SilentError(message)); - } - } - - let sslKey: string = null; - let sslCert: string = null; - if (serveTaskOptions.ssl) { - const keyPath = path.resolve(this.project.root, serveTaskOptions.sslKey); - if (fs.existsSync(keyPath)) { - sslKey = fs.readFileSync(keyPath, 'utf-8'); - } - const certPath = path.resolve(this.project.root, serveTaskOptions.sslCert); - if (fs.existsSync(certPath)) { - sslCert = fs.readFileSync(certPath, 'utf-8'); - } - } - - const webpackDevServerConfiguration: IWebpackDevServerConfigurationOptions = { - contentBase: path.resolve( - this.project.root, - `./${CliConfig.fromProject().config.apps[0].root}` - ), - headers: { 'Access-Control-Allow-Origin': '*' }, - historyApiFallback: { - disableDotRule: true, - htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'] - }, - stats: statsConfig, - inline: true, - proxy: proxyConfig, - compress: serveTaskOptions.target === 'production', - watchOptions: { - poll: CliConfig.fromProject().config.defaults.poll - }, - https: serveTaskOptions.ssl - }; - - if (sslKey != null && sslCert != null) { - webpackDevServerConfiguration.key = sslKey; - webpackDevServerConfiguration.cert = sslCert; - } - - webpackDevServerConfiguration.hot = serveTaskOptions.hmr; - - ui.writeLine(chalk.green(oneLine` - ** - NG Live Development Server is running on - http${serveTaskOptions.ssl ? 's' : ''}://${serveTaskOptions.host}:${serveTaskOptions.port}. - ** - `)); - - const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration); - return new Promise((resolve, reject) => { - server.listen(serveTaskOptions.port, `${serveTaskOptions.host}`, (err: any, stats: any) => { - if (err) { - console.error(err.stack || err); - if (err.details) { console.error(err.details); } - reject(err.details); - } else { - const { open, ssl, host, port } = serveTaskOptions; - if (open) { - let protocol = ssl ? 'https' : 'http'; - opn(url.format({ protocol: protocol, hostname: host, port: port.toString() })); - } - } - }); - }); - } -}); diff --git a/packages/angular-cli/utilities/completion.sh.orig b/packages/angular-cli/utilities/completion.sh.orig deleted file mode 100644 index e54e97646eba..000000000000 --- a/packages/angular-cli/utilities/completion.sh.orig +++ /dev/null @@ -1,93 +0,0 @@ -###-begin-ng-completion### -# -# ng command completion script -# -# Installation: ng completion 1>> ~/.bashrc 2>>&1 -# or ng completion 1>> ~/.zshrc 2>>&1 -# - -ng_opts='b build completion doc e2e g generate get github-pages:deploy gh-pages:deploy h help i init install lint make-this-awesome new s serve server set t test v version' - -<<<<<<< HEAD -build_opts='--aot --base-href --environment --i18n-file --i18n-format --locale --output-path --suppress-sizes --target --watch --watcher -bh -dev -e -o -prod -t -w' -======= -build_opts='--aot --base-href --environment --output-path --progress --sourcemap --suppress-sizes --target --vendor-chunk --verbose --watch --watcher -bh -dev -e -o -prod -sm -t -w' ->>>>>>> upstream/master -generate_opts='class component directive enum module pipe route service c cl d e m p r s --help' -github_pages_deploy_opts='--base-href --environment --gh-token --gh-username --message --skip-build --target --user-page -bh -e -t' -help_opts='--json --verbose -v' -init_opts='--dry-run inline-style inline-template --link-cli --mobile --name --prefix --routing --skip-bower --skip-npm --source-dir --style --verbose -d -is -it -lc -n -p -sb -sd -sn -v' -new_opts='--directory --dry-run inline-style inline-template --link-cli --mobile --prefix --routing --skip-bower --skip-git --skip-npm --source-dir --style --verbose -d -dir -is -it -lc -p -sb -sd -sg -sn -v' -<<<<<<< HEAD -serve_opts='--aot --environment --host --i18n-file --i18n-format --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --locale --open --port --proxy-config --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -o -p -pc -t -w' -======= -serve_opts='--aot --environment --hmr --host --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --open --port --proxy-config --sourcemap --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -o -p -pc -sm -t -w' ->>>>>>> upstream/master -set_opts='--global -g' -test_opts='--browsers --build --code-coverage --colors --lint --log-level --port --reporters --single-run --sourcemap --watch -cc -l -sm -sr -w' - -version_opts='--verbose' - -if test ".$(type -t complete 2>/dev/null || true)" = ".builtin"; then - _ng_completion() { - local cword pword opts - - COMPREPLY=() - cword=${COMP_WORDS[COMP_CWORD]} - pword=${COMP_WORDS[COMP_CWORD - 1]} - - case ${pword} in - ng) opts=$ng_opts ;; - b|build) opts=$build_opts ;; - g|generate) opts=$generate_opts ;; - gh-pages:deploy|github-pages:deploy) opts=$github_pages_deploy_opts ;; - h|help|-h|--help) opts=$help_opts ;; - init) opts=$init_opts ;; - new) opts=$new_opts ;; - s|serve|server) opts=$serve_opts ;; - set) opts=$set_opts ;; - t|test) opts=$test_opts ;; - v|version) opts=$version_opts ;; - *) opts='' ;; - esac - - COMPREPLY=( $(compgen -W '${opts}' -- $cword) ) - - return 0 - } - - complete -o default -F _ng_completion ng -elif test ".$(type -w compctl 2>/dev/null || true)" = ".compctl: builtin" ; then - _ng_completion () { - local words cword opts - read -Ac words - read -cn cword - let cword-=1 - - case $words[cword] in - ng) opts=$ng_opts ;; - b|build) opts=$build_opts ;; - g|generate) opts=$generate_opts ;; - gh-pages:deploy|github-pages:deploy) opts=$github_pages_deploy_opts ;; - h|help|-h|--help) opts=$help_opts ;; - init) opts=$init_opts ;; - new) opts=$new_opts ;; - s|serve|server) opts=$serve_opts ;; - set) opts=$set_opts ;; - t|test) opts=$test_opts ;; - v|version) opts=$version_opts ;; - *) opts='' ;; - esac - - setopt shwordsplit - reply=($opts) - unset shwordsplit - } - - compctl -K _ng_completion ng -else - echo "Shell builtin command 'complete' or 'compctl' is redefined; cannot perform ng completion." - return 1 -fi - -###-end-ng-completion###