Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@angular/cli): use environmentSource key for environments #4705

Merged
merged 3 commits into from Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/documentation/build.md
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
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
Expand Up @@ -147,6 +147,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
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
35 changes: 32 additions & 3 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { stripIndent } from 'common-tags';
import {AotPlugin, AotPluginOptions} from '@ngtools/webpack';
import { WebpackConfigOptions } from '../webpack-config';

Expand All @@ -19,15 +20,43 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify if environment.source is set here and explain to the user the change s/he needs to make.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let migrationMessage = '';
if ('source' in appConfig.environments) {
migrationMessage = '\n\n' + stripIndent`
A new environmentSource entry replaces the previous source entry inside environments.

To migrate angular-cli.json 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"
}
`;
}
throw new SilentError(
`Environment configuration does not contain "environmentSource" entry.${migrationMessage}`
);

}
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