From 9d400b044bf87357977cde1185d0c5bc140fb6f0 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Garcia Date: Thu, 5 Jan 2017 13:12:12 -0800 Subject: [PATCH 1/3] refactor(build): replace `source` in environments with separate `environmentDefault` entry Replace `source` in environments with separate `environmentDefault` entry and updated docs to reflect this change BREAKING CHANGE: angular-cli.json has changed. A new `environmentDefault` entry replaces the previous `source` entry inside `environments`. To migrate the code follow the example below: Before: "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } After: "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } Closes #3857 --- README.md | 2 +- docs/documentation/overview.md | 2 +- packages/angular-cli/blueprints/ng2/files/angular-cli.json | 2 +- packages/angular-cli/lib/config/schema.d.ts | 4 ++++ packages/angular-cli/models/webpack-build-common.ts | 7 ++++--- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f387c805f9be..afda0db8c8be 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,8 @@ By default, the development build target and environment are used. The mapping used to determine which environment file is used can be found in `angular-cli.json`: ```json +"environmentSource": "environments/environment.ts", "environments": { - "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } diff --git a/docs/documentation/overview.md b/docs/documentation/overview.md index 6286a25678a8..3f7a0cffc570 100644 --- a/docs/documentation/overview.md +++ b/docs/documentation/overview.md @@ -27,8 +27,8 @@ By default, the development build target and environment are used. The mapping used to determine which environment file is used can be found in `angular-cli.json`: ```json +"environmentSource": "environments/environment.ts", "environments": { - "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } diff --git a/packages/angular-cli/blueprints/ng2/files/angular-cli.json b/packages/angular-cli/blueprints/ng2/files/angular-cli.json index 4fd88b98c1cf..9f5e8fc6e156 100644 --- a/packages/angular-cli/blueprints/ng2/files/angular-cli.json +++ b/packages/angular-cli/blueprints/ng2/files/angular-cli.json @@ -21,8 +21,8 @@ "styles.<%= styleExt %>" ], "scripts": [], + "environmentSource": "environments/environment.ts", "environments": { - "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } diff --git a/packages/angular-cli/lib/config/schema.d.ts b/packages/angular-cli/lib/config/schema.d.ts index d323223b5f36..8cc0bdd85095 100644 --- a/packages/angular-cli/lib/config/schema.d.ts +++ b/packages/angular-cli/lib/config/schema.d.ts @@ -28,6 +28,10 @@ export interface CliConfig { * Global scripts to be included in the build. */ scripts?: string[]; + /** + * Environment source file. + */ + environmentSource?: string, /** * Name and corresponding file for environment config. */ diff --git a/packages/angular-cli/models/webpack-build-common.ts b/packages/angular-cli/models/webpack-build-common.ts index 6130f887fbc0..1f94db6f828f 100644 --- a/packages/angular-cli/models/webpack-build-common.ts +++ b/packages/angular-cli/models/webpack-build-common.ts @@ -102,8 +102,9 @@ export function getWebpackCommonConfig( // process environment file replacement if (appConfig.environments) { - if (!('source' in appConfig.environments)) { - throw new SilentError(`Environment configuration does not contain "source" entry.`); + if (!('environmentSource' in appConfig.environments)) { + throw new SilentError(`Environment configuration does not contain + "environmentSource" entry.`); } if (!(environment in appConfig.environments)) { throw new SilentError(`Environment "${environment}" does not exist.`); @@ -113,7 +114,7 @@ export function getWebpackCommonConfig( // This plugin is responsible for swapping the environment files. // Since it takes a RegExp as first parameter, we need to escape the path. // See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin - new RegExp(path.resolve(appRoot, appConfig.environments['source']) + new RegExp(path.resolve(appRoot, appConfig['environmentSource']) .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')), path.resolve(appRoot, appConfig.environments[environment]) )); From 212daa3f805fe820a6c3e01a520212c513a21822 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Garcia Date: Thu, 5 Jan 2017 14:38:16 -0800 Subject: [PATCH 2/3] Modified webpack-build-test.ts with new environmentSource entry --- packages/angular-cli/models/webpack-build-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular-cli/models/webpack-build-test.js b/packages/angular-cli/models/webpack-build-test.js index a1b1dbe98ecd..a16891027d61 100644 --- a/packages/angular-cli/models/webpack-build-test.js +++ b/packages/angular-cli/models/webpack-build-test.js @@ -128,7 +128,7 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test // This plugin is responsible for swapping the environment files. // Since it takes a RegExp as first parameter, we need to escape the path. // See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin - new RegExp(path.resolve(appRoot, appConfig.environments['source']) + new RegExp(path.resolve(appRoot, appConfig['environmentSource']) .replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')), path.resolve(appRoot, appConfig.environments[environment]) ), From 49ce5f129e89f013f2d9d017e3be48179f2d7092 Mon Sep 17 00:00:00 2001 From: Juan Sanchez Garcia Date: Thu, 5 Jan 2017 16:04:48 -0800 Subject: [PATCH 3/3] refactor(build): replace `source` in environments with separate `environmentDefault` entry Replace `source` in environments with separate `environmentDefault` entry and updated docs to reflect this change BREAKING CHANGE: angular-cli.json has changed. A new `environmentDefault` entry replaces the previous `source` entry inside `environments`. To migrate the code follow the example below: Before: "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } After: "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } Closes #3857 --- packages/angular-cli/lib/config/schema.d.ts | 14 ++++++++++---- packages/angular-cli/lib/config/schema.json | 5 +++++ .../angular-cli/models/webpack-build-common.ts | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/angular-cli/lib/config/schema.d.ts b/packages/angular-cli/lib/config/schema.d.ts index 8cc0bdd85095..2068218b8b7a 100644 --- a/packages/angular-cli/lib/config/schema.d.ts +++ b/packages/angular-cli/lib/config/schema.d.ts @@ -12,7 +12,7 @@ export interface CliConfig { apps?: { root?: string; outDir?: string; - assets?: string; + assets?: string | string[]; deployUrl?: string; index?: string; main?: string; @@ -23,15 +23,21 @@ export interface CliConfig { /** * Global styles to be included in the build. */ - styles?: string[]; + styles?: (string | { + [name: string]: any; + input?: string; + })[]; /** * Global scripts to be included in the build. */ - scripts?: string[]; + scripts?: (string | { + [name: string]: any; + input?: string; + })[]; /** * Environment source file. */ - environmentSource?: string, + environmentSource?: string; /** * Name and corresponding file for environment config. */ diff --git a/packages/angular-cli/lib/config/schema.json b/packages/angular-cli/lib/config/schema.json index 3a2a1f02fcc9..63f39a8dd2f2 100644 --- a/packages/angular-cli/lib/config/schema.json +++ b/packages/angular-cli/lib/config/schema.json @@ -110,6 +110,11 @@ }, "additionalProperties": false }, + "environmentSource": { + "description": "Environment source file.", + "type": "string", + "additionalProperties": true + }, "environments": { "description": "Name and corresponding file for environment config.", "type": "object", diff --git a/packages/angular-cli/models/webpack-build-common.ts b/packages/angular-cli/models/webpack-build-common.ts index 1f94db6f828f..ee873c55d22e 100644 --- a/packages/angular-cli/models/webpack-build-common.ts +++ b/packages/angular-cli/models/webpack-build-common.ts @@ -102,7 +102,7 @@ export function getWebpackCommonConfig( // process environment file replacement if (appConfig.environments) { - if (!('environmentSource' in appConfig.environments)) { + if (!(appConfig.environmentSource)) { throw new SilentError(`Environment configuration does not contain "environmentSource" entry.`); }