Skip to content

Commit

Permalink
feat(@angular/cli): Update command runner.
Browse files Browse the repository at this point in the history
This change removes the dependency of the ember-cli command structure.
  • Loading branch information
Brocco authored and clydin committed Mar 6, 2018
1 parent 9c4f9e9 commit 9f77c86
Show file tree
Hide file tree
Showing 71 changed files with 1,184 additions and 3,051 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<details>
<summary>lint-fix</summary>
<p>
<code>--lint-fix</code> (aliases: <code>-lf</code>)
<code>--lint-fix</code> (aliases: <code>-l</code>)
</p>
<p>
Use lint to fix files after generation.
Expand Down
8 changes: 4 additions & 4 deletions docs/documentation/generate/component.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<details>
<summary>change-detection</summary>
<p>
<code>--change-detection</code> (aliases: <code>-cd</code>)
<code>--change-detection</code> (aliases: <code>-c</code>)
</p>
<p>
Specifies the change detection strategy.
Expand Down Expand Up @@ -49,7 +49,7 @@
<details>
<summary>inline-style</summary>
<p>
<code>--inline-style</code> (aliases: <code>-is</code>) <em>default value: false</em>
<code>--inline-style</code> (aliases: <code>-s</code>) <em>default value: false</em>
</p>
<p>
Specifies if the style will be in the ts file.
Expand All @@ -59,7 +59,7 @@
<details>
<summary>inline-template</summary>
<p>
<code>--inline-template</code> (aliases: <code>-it</code>) <em>default value: false</em>
<code>--inline-template</code> (aliases: <code>-t</code>) <em>default value: false</em>
</p>
<p>
Specifies if the template will be in the ts file.
Expand Down Expand Up @@ -109,7 +109,7 @@
<details>
<summary>view-encapsulation</summary>
<p>
<code>--view-encapsulation</code> (aliases: <code>-ve</code>)
<code>--view-encapsulation</code> (aliases: <code>-v</code>)
</p>
<p>
Specifies the view encapsulation strategy.
Expand Down
12 changes: 6 additions & 6 deletions docs/documentation/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>directory</summary>
<p>
<code>--directory</code> (alias: <code>-dir</code>) <em>default value: dir</em>
<code>--directory</code> (alias: <code>-d</code>) <em>default value: dir</em>
</p>
<p>
The directory name to create the app in.
Expand All @@ -31,7 +31,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>inline-style</summary>
<p>
<code>--inline-style</code> (alias: <code>-is</code>) <em>default value: false</em>
<code>--inline-style</code> (alias: <code>-s</code>) <em>default value: false</em>
</p>
<p>
Should have an inline style.
Expand All @@ -41,7 +41,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>inline-template</summary>
<p>
<code>--inline-template</code> (alias: <code>-it</code>) <em>default value: false</em>
<code>--inline-template</code> (alias: <code>-t</code>) <em>default value: false</em>
</p>
<p>
Should have an inline template.
Expand Down Expand Up @@ -94,7 +94,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>skip-git</summary>
<p>
<code>--skip-git</code> (alias: <code>-sg</code>) <em>default value: false</em>
<code>--skip-git</code> (alias: <code>-g</code>) <em>default value: false</em>
</p>
<p>
Skip initializing a git repository.
Expand All @@ -114,7 +114,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>skip-tests</summary>
<p>
<code>--skip-tests (aliases: </code>-st) <em>default value: false</em>
<code>--skip-tests (aliases: </code>-S) <em>default value: false</em>
</p>
<p>
Skip creating spec files.
Expand All @@ -127,7 +127,7 @@ Default applications are created in a directory of the same name, with an initia
<details>
<summary>source-dir</summary>
<p>
<code>--source-dir</code> (alias: <code>-sd</code>) <em>default value: src</em>
<code>--source-dir</code> (alias: <code>-D</code>) <em>default value: src</em>
</p>
<p>
The name of the source directory.
Expand Down
46 changes: 30 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"webpack-dev-server": "^3.0.1-beta.0",
"webpack-merge": "^4.1.2",
"webpack-sources": "^1.1.0",
"webpack-subresource-integrity": "^1.0.1"
"webpack-subresource-integrity": "^1.0.1",
"yargs-parser": "^9.0.2"
},
"devDependencies": {
"@angular/common": "^5.2.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/@angular/cli/bin/ng
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ resolve('@angular/cli', { basedir: process.cwd() },
cliArgs: process.argv.slice(2),
inputStream: standardInput,
outputStream: process.stdout
}).then(function (result) {
process.exit(typeof result === 'object' ? result.exitCode : result);
}).then(function (exitCode) {
process.exit(exitCode);
}).catch(function(err) {
console.log('Unknown error: ' + err.toString());
process.exit(127);
});
});
91 changes: 43 additions & 48 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Command, Option, CommandScope } from '../models/command';
import { CliConfig } from '../models/config';
import { BuildOptions } from '../models/build-options';
import { Version } from '../upgrade/version';
Expand All @@ -6,7 +7,6 @@ import { getAppFromConfig } from '../utilities/app-utils';
import { join } from 'path';
import { RenderUniversalTaskOptions } from '../tasks/render-universal';

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

const config = CliConfig.fromProject() || CliConfig.fromGlobal();
Expand All @@ -16,12 +16,13 @@ const buildConfigDefaults = config.getPaths('defaults.build', [
]);

// defaults for BuildOptions
export const baseBuildCommandOptions: any = [
export const baseBuildCommandOptions: Option[] = [
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }],
// TODO: re-add support for `--prod`
aliases: ['t'],
description: 'Defines the build target.'
},
{
Expand Down Expand Up @@ -213,29 +214,33 @@ export interface BuildTaskOptions extends BuildOptions {
statsJson?: boolean;
}

const BuildCommand = Command.extend({
name: 'build',
description: 'Builds your app and places it into the output path (dist/ by default).',
aliases: ['b'],

availableOptions: baseBuildCommandOptions.concat([
export default class BuildCommand extends Command {
public readonly name = 'build';
public readonly description =
'Builds your app and places it into the output path (dist/ by default).';
public static aliases = ['b'];
public scope = CommandScope.inProject;
public arguments: string[];
public options = baseBuildCommandOptions.concat([
{
name: 'stats-json',
type: Boolean,
default: false,
description: oneLine`Generates a \`stats.json\` file which can be analyzed using tools
such as: \`webpack-bundle-analyzer\` or https://webpack.github.io/analyse.`
}
]),
]);

run: function (commandOptions: BuildTaskOptions) {
// Check Angular and TypeScript versions.
public validate(_options: BuildTaskOptions) {
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
Version.assertTypescriptVersion(this.project.root);
return true;
}

public async run(options: BuildTaskOptions) {
// Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295
if (commandOptions.deployUrl && commandOptions.deployUrl.substr(-1) !== '/') {
commandOptions.deployUrl += '/';
if (options.deployUrl && options.deployUrl.substr(-1) !== '/') {
options.deployUrl += '/';
}

const BuildTask = require('../tasks/build').default;
Expand All @@ -245,11 +250,11 @@ const BuildCommand = Command.extend({
ui: this.ui,
});

const clientApp = getAppFromConfig(commandOptions.app);
const clientApp = getAppFromConfig(options.app);

const doAppShell = commandOptions.target === 'production' &&
(commandOptions.aot === undefined || commandOptions.aot === true) &&
!commandOptions.skipAppShell;
const doAppShell = options.target === 'production' &&
(options.aot === undefined || options.aot === true) &&
!options.skipAppShell;

let serverApp: any = null;
if (clientApp.appShell && doAppShell) {
Expand All @@ -259,40 +264,30 @@ const BuildCommand = Command.extend({
}
}

const buildPromise = buildTask.run(commandOptions);

const buildTaskResult = await buildTask.run(options);
if (!clientApp.appShell || !doAppShell) {
return buildPromise;
return buildTaskResult;
}

return buildPromise
.then(() => {
const serverOptions = {
...options,
app: clientApp.appShell.app
};
await buildTask.run(serverOptions);

const serverOptions = {
...commandOptions,
app: clientApp.appShell.app
};
return buildTask.run(serverOptions);
})
.then(() => {
const RenderUniversalTask = require('../tasks/render-universal').default;
const RenderUniversalTask = require('../tasks/render-universal').default;

const renderUniversalTask = new RenderUniversalTask({
project: this.project,
ui: this.ui,
});
const renderUniversalOptions: RenderUniversalTaskOptions = {
inputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index),
route: clientApp.appShell.route,
serverOutDir: join(this.project.root, serverApp.outDir),
outputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index)
};
const renderUniversalTask = new RenderUniversalTask({
project: this.project,
ui: this.ui,
});
const renderUniversalOptions: RenderUniversalTaskOptions = {
inputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index),
route: clientApp.appShell.route,
serverOutDir: join(this.project.root, serverApp.outDir),
outputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index)
};

return renderUniversalTask.run(renderUniversalOptions);
});
return await renderUniversalTask.run(renderUniversalOptions);
}
});


BuildCommand.overrideCore = true;
export default BuildCommand;
}

0 comments on commit 9f77c86

Please sign in to comment.