Skip to content

Commit

Permalink
fix(@angular/cli): clean up architect options
Browse files Browse the repository at this point in the history
Fix #10699
  • Loading branch information
filipesilva authored and clydin committed May 10, 2018
1 parent 89242be commit c9a46eb
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 253 deletions.
184 changes: 95 additions & 89 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 4 additions & 25 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { ArchitectCommand } from '../models/architect-command';
import { Option, CommandScope } from '../models/command';
import { Version } from '../upgrade/version';

export interface Options {
project?: string;
configuration?: string;
prod: boolean;
}
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

export default class BuildCommand extends ArchitectCommand {
public readonly name = 'build';
Expand All @@ -20,29 +14,14 @@ export default class BuildCommand extends ArchitectCommand {
this.configurationOption
];

public validate(options: Options) {
public validate(options: ArchitectCommandOptions) {
// Check Angular and TypeScript versions.
Version.assertCompatibleAngularVersion(this.project.root);
Version.assertTypescriptVersion(this.project.root);
return super.validate(options);
}

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

const overrides = { ...options };
delete overrides.project;
delete overrides.configuration;
delete overrides.prod;

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
}, options);
public async run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
25 changes: 3 additions & 22 deletions packages/@angular/cli/commands/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

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

export default class E2eCommand extends ArchitectCommand {
public readonly name = 'e2e';
Expand All @@ -19,21 +14,7 @@ export default class E2eCommand extends ArchitectCommand {
this.configurationOption
];

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

const overrides = { ...options };
delete overrides.project;
delete overrides.prod;

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
}, options);
public run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
17 changes: 3 additions & 14 deletions packages/@angular/cli/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

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

export default class LintCommand extends ArchitectCommand {
public readonly name = 'lint';
Expand All @@ -17,14 +13,7 @@ export default class LintCommand extends ArchitectCommand {
this.configurationOption
];

public async run(options: Options) {
const overrides = { ...options };
delete overrides.project;
return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration: options.configuration,
overrides
}, options);
public async run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
17 changes: 3 additions & 14 deletions packages/@angular/cli/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

export interface RunOptions {
target: string;
}

export default class RunCommand extends ArchitectCommand {
public readonly name = 'run';
Expand All @@ -14,17 +11,9 @@ export default class RunCommand extends ArchitectCommand {
this.configurationOption
];

public async run(options: RunOptions) {
public async run(options: ArchitectCommandOptions) {
if (options.target) {
const [project, target, configuration] = options.target.split(':');
const overrides = { ...options };
delete overrides.target;
return this.runArchitectTarget({
project,
target,
configuration,
overrides
}, options);
return this.runArchitectTarget(options);
} else {
throw new Error('Invalid architect target.');
}
Expand Down
28 changes: 4 additions & 24 deletions packages/@angular/cli/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { CommandScope, Option } from '../models/command';
import { Version } from '../upgrade/version';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

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

export default class ServeCommand extends ArchitectCommand {
public readonly name = 'serve';
Expand All @@ -19,29 +14,14 @@ export default class ServeCommand extends ArchitectCommand {
this.configurationOption
];

public validate(_options: Options) {
public validate(_options: ArchitectCommandOptions) {
// Check Angular and TypeScript versions.
Version.assertCompatibleAngularVersion(this.project.root);
Version.assertTypescriptVersion(this.project.root);
return true;
}

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

const overrides = { ...options };
delete overrides.project;
delete overrides.configuration;
delete overrides.prod;

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
}, options);
public async run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
26 changes: 3 additions & 23 deletions packages/@angular/cli/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

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

export default class TestCommand extends ArchitectCommand {
public readonly name = 'test';
Expand All @@ -19,22 +14,7 @@ export default class TestCommand extends ArchitectCommand {
this.configurationOption
];

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

const overrides = { ...options };
delete overrides.project;
delete overrides.configuration;
delete overrides.prod;

return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration,
overrides
}, options);
public async run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
17 changes: 3 additions & 14 deletions packages/@angular/cli/commands/xi18n.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { CommandScope, Option } from '../models/command';
import { ArchitectCommand } from '../models/architect-command';
import { ArchitectCommand, ArchitectCommandOptions } from '../models/architect-command';

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

export default class Xi18nCommand extends ArchitectCommand {
public readonly name = 'xi18n';
Expand All @@ -16,14 +12,7 @@ export default class Xi18nCommand extends ArchitectCommand {
this.configurationOption
];

public async run(options: Options) {
const overrides = { ...options };
delete overrides.project;
return this.runArchitectTarget({
project: options.project,
target: this.target,
configuration: options.configuration,
overrides
}, options);
public async run(options: ArchitectCommandOptions) {
return this.runArchitectTarget(options);
}
}
Loading

0 comments on commit c9a46eb

Please sign in to comment.