Skip to content

Commit

Permalink
feat(@angular/cli): use workspace for architect commands
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Mar 19, 2018
1 parent 5716621 commit 41320bf
Show file tree
Hide file tree
Showing 60 changed files with 565 additions and 937 deletions.
188 changes: 92 additions & 96 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
"@angular-devkit/architect": "0.0.7",
"@angular-devkit/build-webpack": "0.0.7",
"@angular-devkit/core": "0.4.6",
"@angular-devkit/schematics": "0.4.6",
"@schematics/angular": "0.4.6",
"@schematics/package-update": "0.4.6",
"@angular-devkit/architect": "angular/angular-devkit-architect-builds#9fa382c",
"@angular-devkit/build-webpack": "angular/angular-devkit-build-webpack-builds#9fa382c",
"@angular-devkit/core": "angular/angular-devkit-core-builds#9fa382c",
"@angular-devkit/schematics": "angular/angular-devkit-schematics-builds#9fa382c",
"@schematics/angular": "angular/schematics-angular-builds#9fa382c",
"@schematics/package-update": "angular/schematics-package-update-builds#9fa382c",
"ajv": "^6.1.1",
"chalk": "~2.2.0",
"common-tags": "^1.3.1",
Expand Down
20 changes: 11 additions & 9 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ import { Option, CommandScope } from '../models/command';
import { Version } from '../upgrade/version';

export interface Options {
app?: string;
project?: string;
configuration?: string;
prod: boolean;
}

export default class BuildCommand extends ArchitectCommand {
public readonly name = 'build';
public readonly target = 'browser';
public readonly target = '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[] = ['app'];
public options: Option[] = [
this.prodOption,
this.configurationOption
];

public validate(_options: Options) {
public validate(options: Options) {
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
Version.assertTypescriptVersion(this.project.root);
return true;
return super.validate(options);
}

public async run(options: Options) {
let configuration = options.configuration;
if (!configuration && options.prod) {
configuration = 'production';
}
const overrides = {...options};
delete overrides.app;

const overrides = { ...options };
delete overrides.project;
delete overrides.prod;
return this.runArchitect({
app: options.app,

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
});
Expand Down
20 changes: 11 additions & 9 deletions packages/@angular/cli/commands/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';

export interface RunOptions {
app?: string;
export interface Options {
project?: string;
configuration?: string;
prod: boolean;
}

export default class E2eCommand extends ArchitectCommand {
public readonly name = 'e2e';
public readonly target = 'protractor';
public readonly target = 'e2e';
public readonly description = 'Run e2e tests in existing project.';
public static aliases: string[] = ['e'];
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = ['app'];
public readonly options: Option[] = [
this.prodOption,
this.configurationOption
];

public run(options: RunOptions) {
public run(options: Options) {
let configuration = options.configuration;
if (!configuration && options.prod) {
configuration = 'production';
}
const overrides = {...options};
delete overrides.app;

const overrides = { ...options };
delete overrides.project;
delete overrides.prod;
return this.runArchitect({
app: options.app,

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
});
Expand Down
18 changes: 9 additions & 9 deletions packages/@angular/cli/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';

export interface RunOptions {
app?: string;
export interface Options {
project?: string;
configuration?: string;
}

export default class LintCommand extends ArchitectCommand {
public readonly name = 'lint';
public readonly target = 'tslint';
public readonly target = 'lint';
public readonly description = 'Lints code in existing project.';
public static aliases = ['l'];
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = ['app'];
public readonly options: Option[] = [
this.configurationOption
];

public async run(options: RunOptions) {
const overrides = {...options};
delete overrides.app;
return this.runArchitect({
app: options.app,
public async run(options: Options) {
const overrides = { ...options };
delete overrides.project;
return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration: options.configuration,
overrides
});
Expand Down
37 changes: 26 additions & 11 deletions packages/@angular/cli/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import { Command, Option } from '../models/command';
import { runTarget } from '../utilities/architect';
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';

export default class RunCommand extends Command {
export interface RunOptions {
target: string;
}

export default class RunCommand extends ArchitectCommand {
public readonly name = 'run';
public readonly description = 'Runs an architect configuration.';
public readonly arguments: string[] = ['config'];
public readonly options: Option[] = [];
public readonly description = 'Runs Architect targets.';
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = ['target'];
public readonly options: Option[] = [
this.configurationOption
];

public async run(options: any) {
const buildEvent = await runTarget(this.project.root, options.config, options)
.toPromise();
if (!buildEvent.success) {
throw new Error('');
public async run(options: RunOptions) {
if (options.target) {
const [project, target, configuration] = options.target.split(':');
const overrides = { ...options };
delete overrides.target;
return this.runArchitectTarget({
project,
target,
configuration,
overrides
});
} else {
throw new Error('Invalid architect target.');
}
}
}
16 changes: 9 additions & 7 deletions packages/@angular/cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import { ArchitectCommand } from '../models/architect-command';
export const baseServeCommandOptions: any = [];

export interface Options {
app?: string;
project?: string;
configuration?: string;
prod: boolean;
}

export default class ServeCommand extends ArchitectCommand {
public readonly name = 'serve';
public readonly target = 'dev-server';
public readonly target = 'serve';
public readonly description = 'Builds and serves your app, rebuilding on file changes.';
public static aliases = ['server', 's'];
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = [];
public readonly options: Option[] = [
this.prodOption,
this.configurationOption
Expand All @@ -35,11 +34,14 @@ export default class ServeCommand extends ArchitectCommand {
if (options.prod) {
configuration = 'production';
}
const overrides = {...options};
delete overrides.app;

const overrides = { ...options };
delete overrides.project;
delete overrides.prod;
return this.runArchitect({
app: options.app,

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
});
Expand Down
22 changes: 8 additions & 14 deletions packages/@angular/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@ import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';

export interface Options {
app?: string;
project?: string;
configuration?: string;
prod: boolean;
}

export default class TestCommand extends ArchitectCommand {
public readonly name = 'test';
public readonly target = 'karma';
public readonly target = 'test';
public readonly description = 'Run unit tests in existing project.';
public static aliases = ['t'];
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = [];
public readonly options: Option[] = [
this.prodOption,
this.configurationOption
];

public async run(options: Options) {
let configuration = options.configuration;
if (!configuration && options.prod) {
configuration = 'production';
}
const overrides = {...options};
delete overrides.app;
delete overrides.prod;
return this.runArchitect({
app: options.app,
configuration,
const overrides = { ...options };
delete overrides.project;
return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration: options.configuration,
overrides
});
}
Expand Down
39 changes: 19 additions & 20 deletions packages/@angular/cli/commands/xi18n.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { Command, CommandScope, Option } from '../models/command';
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';

export interface Xi18nOptions {
outputPath?: string;
verbose?: boolean;
i18nFormat?: string;
locale?: string;
outFile?: string;
export interface Options {
project?: string;
configuration?: string;
}

export default class Xi18nCommand extends Command {
public readonly name = 'xi18n';
export default class Xi18nCommand extends ArchitectCommand {
public readonly name = 'xi81n';
public readonly target = 'extract-i18n';
public readonly description = 'Extracts i18n messages from source code.';
public static aliases: string[] = [];
public readonly scope = CommandScope.inProject;
public readonly arguments: string[] = [];
public readonly options: Option[] = [];
public readonly options: Option[] = [
this.configurationOption
];

public async run(options: any) {
const {Extracti18nTask} = require('../tasks/extract-i18n');

const xi18nTask = new Extracti18nTask({
ui: this.ui,
project: this.project
public async run(options: Options) {
const overrides = { ...options };
delete overrides.project;
return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration: options.configuration,
overrides
});

return await xi18nTask.run(options);
}
}
1 change: 1 addition & 0 deletions packages/@angular/cli/lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function loadCommands() {
'doc': require('../../commands/doc').default,
'xi18n': require('../../commands/xi18n').default,
'update': require('../../commands/update').default,
'run': require('../../commands/run').default,

// Easter eggs.
'make-this-awesome': require('../../commands/easter-egg').default,
Expand Down

0 comments on commit 41320bf

Please sign in to comment.