Skip to content

Commit

Permalink
feat(@angular/cli): use environmentSource key for environments
Browse files Browse the repository at this point in the history
Heavily based on @jsanchezgarcia work in angular#4476.

Fix angular#3857

BREAKING CHANGE:

A new environmentSource 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"
}
```
  • Loading branch information
filipesilva committed Feb 14, 2017
1 parent 4543be9 commit 3bd4ed2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,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"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"styles.<%= styleExt %>"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
},
"additionalProperties": false
},
"environmentSource":{
"description": "Source file for environment config.",
"type": "string"
},
"environments": {
"description": "Name and corresponding file for environment config.",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/webpack-configs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const getTestConfig = function (projectRoot, environment, appConfig, testConfig)
// 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])
),
Expand Down
7 changes: 4 additions & 3 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
let hostOverrideFileSystem: any = {};
// process environment file replacement
if (appConfig.environments) {
if (!('source' in appConfig.environments)) {
throw new SilentError(`Environment configuration does not contain "source" entry.`);
if (appConfig.environmentSource) {
throw new SilentError(
'Environment configuration does not contain "environmentSource" entry.');
}
if (!(buildOptions.environment in appConfig.environments)) {
throw new SilentError(`Environment "${buildOptions.environment}" does not exist.`);
}

const appRoot = path.resolve(projectRoot, appConfig.root);
const sourcePath = appConfig.environments['source'];
const sourcePath = appConfig.environmentSource;
const envFile = appConfig.environments[buildOptions.environment];
const environmentContent = fs.readFileSync(path.join(appRoot, envFile)).toString();

Expand Down

0 comments on commit 3bd4ed2

Please sign in to comment.