Skip to content

Commit

Permalink
Merge branch 'master' into live-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
hansl authored Feb 17, 2017
2 parents 3c79e5b + 121c390 commit ac25cf0
Show file tree
Hide file tree
Showing 56 changed files with 990 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ matrix:
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --glob=tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --eject --glob=tests/build/**"
- node_js: "6"
os: linux
env: NODE_SCRIPT="tests/run_e2e.js --ignore=**/tests/build/**"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ with NPM 3 or higher.

* [Installation](#installation)
* [Usage](#usage)
* [Generating a New Project](#generating-and-serving-an-angular2-project-via-a-development-server)
* [Generating a New Project](#generating-and-serving-an-angular-project-via-a-development-server)
* [Generating Components, Directives, Pipes and Services](#generating-components-directives-pipes-and-services)
* [Updating Angular CLI](#updating-angular-cli)
* [Development Hints for hacking on Angular CLI](#development-hints-for-hacking-on-angular-cli)
Expand All @@ -54,7 +54,7 @@ npm install -g @angular/cli
ng help
```

### Generating and serving an Angular2 project via a development server
### Generating and serving an Angular project via a development server

```bash
ng new PROJECT_NAME
Expand Down
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"@types/express": "^4.0.32",
"@types/fs-extra": "0.0.37",
"@types/glob": "^5.0.29",
"@types/jasmine": "^2.2.32",
"@types/jasmine": "~2.2.0",
"@types/lodash": "4.14.50",
"@types/mock-fs": "^3.6.30",
"@types/node": "^6.0.36",
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
return {
'build': require('../commands/build').default,
'serve': require('../commands/serve').default,
'eject': require('../commands/eject').default,
'new': require('../commands/new').default,
'generate': require('../commands/generate').default,
'destroy': require('../commands/destroy').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import 'core-js/es7/reflect';
/***************************************************************************************************
* Zone JS is required by Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular-CLI.
import 'zone.js/dist/zone'; // Included with Angular CLI.



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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ exports.config = {
defaultTimeoutInterval: 30000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
Expand Down
4 changes: 2 additions & 2 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const baseBuildCommandOptions: any = [
description: 'define the output filename cache-busting hashing mode',
aliases: ['oh']
},
{ name: 'stats-json', type: Boolean, default: false },
{
name: 'poll',
type: Number,
Expand All @@ -55,7 +54,8 @@ const BuildCommand = Command.extend({
aliases: ['b'],

availableOptions: baseBuildCommandOptions.concat([
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
{ name: 'stats-json', type: Boolean, default: false }
]),

run: function (commandOptions: BuildTaskOptions) {
Expand Down
37 changes: 37 additions & 0 deletions packages/@angular/cli/commands/eject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { BuildOptions } from '../models/build-options';
import { Version } from '../upgrade/version';
import {baseBuildCommandOptions} from './build';

const Command = require('../ember-cli/lib/models/command');

// defaults for BuildOptions
export const baseEjectCommandOptions: any = [
...baseBuildCommandOptions,
{ name: 'force', 'type': Boolean }
];

export interface EjectTaskOptions extends BuildOptions {
force?: boolean;
}


const EjectCommand = Command.extend({
name: 'eject',
description: 'Ejects your app and output the proper webpack configuration and scripts.',

availableOptions: baseEjectCommandOptions,

run: function (commandOptions: EjectTaskOptions) {
const project = this.project;
const EjectTask = require('../tasks/eject').default;
const ejectTask = new EjectTask({
cliProject: project,
ui: this.ui,
});

return ejectTask.run(commandOptions);
}
});


export default EjectCommand;
6 changes: 5 additions & 1 deletion packages/@angular/cli/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const HelpCommand = Command.extend({

if (rawArgs.length > 0) {
if (cmd === rawArgs[0]) {
this.ui.writeLine(command.printDetailedHelp(commandOptions));
if (command.printDetailedHelp(commandOptions)) {
this.ui.writeLine(command.printDetailedHelp(commandOptions));
} else {
this.ui.writeLine(command.printBasicHelp(commandOptions));
}
}
} else {
this.ui.writeLine(command.printBasicHelp(commandOptions));
Expand Down
25 changes: 19 additions & 6 deletions packages/@angular/cli/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const Command = require('../ember-cli/lib/models/command');
import * as path from 'path';
import * as child_process from 'child_process';
import * as chalk from 'chalk';
import { CliConfig } from '../models/config';


const VersionCommand = Command.extend({
name: 'version',
Expand Down Expand Up @@ -40,6 +42,13 @@ const VersionCommand = Command.extend({

ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
}
const config = CliConfig.fromProject();
if (config && config.config.project.version !== pkg.version) {
ngCliVersion += ` [${config.config.project.version}]`;
}
if (config && config.config.project.ejected) {
ngCliVersion += ' (e)';
}

if (projPkg) {
roots.forEach(root => {
Expand Down Expand Up @@ -76,12 +85,16 @@ const VersionCommand = Command.extend({
},

getVersion: function(moduleName: string): string {
const modulePkg = require(path.resolve(
this.project.root,
'node_modules',
moduleName,
'package.json'));
return modulePkg.version;
try {
const modulePkg = require(path.resolve(
this.project.root,
'node_modules',
moduleName,
'package.json'));
return modulePkg.version;
} catch (e) {
return 'error';
}
},

printVersion: function (module: string, version: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface BaseHrefWebpackPluginOptions {
}

export class BaseHrefWebpackPlugin {
constructor(private options: BaseHrefWebpackPluginOptions) { }
constructor(public readonly options: BaseHrefWebpackPluginOptions) { }

apply(compiler: any): void {
// Ignore if baseHref is not passed
Expand Down
9 changes: 9 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
},
"name": {
"type": "string"
},
"ejected": {
"description": "Whether or not this project was ejected.",
"type": "boolean",
"default": false
}
},
"additionalProperties": false
Expand Down Expand Up @@ -147,6 +152,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/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getUserHome() {

export class CliConfig extends CliConfigBase<ConfigInterface> {
static configFilePath(projectPath?: string): string {
// Find the configuration, either where specified, in the angular-cli project
// Find the configuration, either where specified, in the Angular CLI project
// (if it's in node_modules) or from the current process.
return (projectPath && _findUp(CLI_CONFIG_FILE_NAME, projectPath))
|| (projectPath && _findUp(CLI_CONFIG_FILE_NAME_ALT, projectPath))
Expand Down
3 changes: 1 addition & 2 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { WebpackConfigOptions } from '../webpack-config';
const autoprefixer = require('autoprefixer');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');


/**
* Enumerate loaders and their dependencies from this file to let the dependency validator
Expand Down Expand Up @@ -97,7 +97,6 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
path: path.resolve(projectRoot, buildOptions.outputPath),
publicPath: buildOptions.deployUrl,
filename: `[name]${hashFormat.chunk}.bundle.js`,
sourceMapFilename: `[name]${hashFormat.chunk}.bundle.map`,
chunkFilename: `[id]${hashFormat.chunk}.chunk.js`
},
module: {
Expand Down
15 changes: 11 additions & 4 deletions packages/@angular/cli/models/webpack-configs/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '../../plugins/suppress-entry-chunks-webpack-plugin';
import { extraEntryParser, getOutputHashFormat } from './utils';
import { WebpackConfigOptions } from '../webpack-config';
import { pluginArgs } from '../../tasks/eject';

const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
Expand Down Expand Up @@ -104,17 +105,23 @@ export function getStylesConfig(wco: WebpackConfigOptions) {

// load global css as css files
if (globalStylePaths.length > 0) {
rules.push(...baseRules.map(({test, loaders}) => ({
include: globalStylePaths, test, loaders: ExtractTextPlugin.extract({
rules.push(...baseRules.map(({test, loaders}) => {
const extractTextPlugin = {
use: [
...commonLoaders,
...loaders
],
fallback: 'style-loader',
// publicPath needed as a workaround https://github.com/angular/angular-cli/issues/4035
publicPath: ''
})
})));
};
const ret: any = {
include: globalStylePaths, test, loaders: ExtractTextPlugin.extract(extractTextPlugin)
};
// Save the original options as arguments for eject.
ret[pluginArgs] = extractTextPlugin;
return ret;
}));
}

// supress empty .js files in css only entry points
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
49 changes: 41 additions & 8 deletions packages/@angular/cli/models/webpack-configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -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 @@ -16,22 +17,51 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
const { appConfig, projectRoot, buildOptions } = wco;

// Read the environment, and set it in the compiler host.
let hostOverrideFileSystem: any = {};
let hostReplacementPaths: 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) {
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();

hostOverrideFileSystem = { [path.join(appRoot, sourcePath)]: environmentContent };
hostReplacementPaths = {
[path.join(appRoot, sourcePath)]: path.join(appRoot, envFile)
};
}

return new AotPlugin(Object.assign({}, {
Expand All @@ -40,15 +70,18 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
i18nFile: buildOptions.i18nFile,
i18nFormat: buildOptions.i18nFormat,
locale: buildOptions.locale,
hostOverrideFileSystem
hostReplacementPaths
}, options));
}


export const getNonAotConfig = function(wco: WebpackConfigOptions) {
const { projectRoot, appConfig } = wco;
let exclude = [ '**/*.spec.ts' ];
if (appConfig.test) { exclude.push(path.join(projectRoot, appConfig.root, appConfig.test)); };
if (appConfig.test) {
exclude.push(path.join(projectRoot, appConfig.root, appConfig.test));
}

return {
module: {
rules: [
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"keywords": [
"angular",
"angular-cli"
"angular-cli",
"Angular CLI"
],
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit ac25cf0

Please sign in to comment.