Skip to content

Commit

Permalink
feat(@angular/cli): Clean up generate options
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Removed collection and lint-fix options
  • Loading branch information
Brocco committed Mar 9, 2018
1 parent a9bbe2a commit 12e10e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
27 changes: 7 additions & 20 deletions docs/documentation/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,26 @@
<code>--dry-run</code> (aliases: <code>-d</code>) <em>default value: false</em>
</p>
<p>
Run through without making any changes. Will list all files that would have been created when running <code>ng generate</code>.
Run through without making any changes.
</p>
</details>

<details>
<summary>lint-fix</summary>
<summary>force</summary>
<p>
<code>--lint-fix</code> (aliases: <code>-l</code>)
<code>--force</code> (aliases: <code>-f</code>) <em>default value: false</em>
</p>
<p>
Use lint to fix files after generation.
</p>
<p>
You can also set default true to use lint every time after generation. To do this, change the value in <em>.angular-cli.json</em> (<code>defaults.lintFix</code>).
</p>
</details>

<details>
<summary>verbose</summary>
<p>
<code>--verbose</code> (aliases: <code>-v</code>) <em>default value: false</em>
</p>
<p>
Adds more details to output logging.
Forces overwriting of files.
</p>
</details>

<details>
<summary>collection</summary>
<summary>app</summary>
<p>
<code>--collection</code> (aliases: <code>-c</code>) <em>default value: @schematics/angular</em>
<code>--app</code>
</p>
<p>
Schematics collection to use.
Specifies app name to use.
</p>
</details>
35 changes: 15 additions & 20 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, CommandScope } from '../models/command';
import { Command, CommandScope, Option } from '../models/command';
import chalk from 'chalk';
const stringUtils = require('ember-cli-string-utils');
import { CliConfig } from '../models/config';
Expand All @@ -21,7 +21,7 @@ export default class GenerateCommand extends Command {
public static aliases = ['g'];
public readonly scope = CommandScope.inProject;
public arguments = ['schematic'];
public options = [
public options: Option[] = [
{
name: 'dry-run',
type: Boolean,
Expand All @@ -39,20 +39,7 @@ export default class GenerateCommand extends Command {
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
},
{
name: 'collection',
type: String,
aliases: ['c'],
description: 'Schematics collection to use.'
},
{
name: 'lint-fix',
type: Boolean,
aliases: ['l'],
description: 'Use lint to fix files after generation.'
}
];

Expand Down Expand Up @@ -170,19 +157,19 @@ export default class GenerateCommand extends Command {
options.type = options.type;
}

const schematicOptions = this.stripLocalOptions(options);
return schematicRunTask.run({
taskOptions: options,
taskOptions: schematicOptions,
dryRun: options.dryRun,
force: options.force,
workingDir: cwd,
collectionName,
schematicName
});
}

private parseSchematicInfo(options: any) {
let collectionName: string =
options.collection ||
options.c ||
CliConfig.getValue('defaults.schematics.collection');
let collectionName: string = CliConfig.getValue('defaults.schematics.collection');

let schematicName = options.schematic;

Expand Down Expand Up @@ -213,4 +200,12 @@ export default class GenerateCommand extends Command {
this.logger.info(cyan(` ng generate <schematic> --help`));
}
}

private stripLocalOptions(options: any): any {
const opts = Object.assign({}, options);
delete opts.dryRun;
delete opts.force;
delete opts.app;
return opts;
}
}
24 changes: 16 additions & 8 deletions packages/@angular/cli/tasks/schematic-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const SilentError = require('silent-error');
const Task = require('../ember-cli/lib/models/task');

export interface SchematicRunOptions {
dryRun: boolean;
force: boolean;
taskOptions: SchematicOptions;
workingDir: string;
emptyHost: boolean;
Expand All @@ -29,8 +31,6 @@ export interface SchematicRunOptions {
}

export interface SchematicOptions {
dryRun: boolean;
force: boolean;
[key: string]: any;
}

Expand All @@ -46,7 +46,15 @@ interface OutputLogging {

export default Task.extend({
run: function (options: SchematicRunOptions): Promise<SchematicOutput> {
const { taskOptions, workingDir, emptyHost, collectionName, schematicName } = options;
const {
taskOptions,
force,
dryRun,
workingDir,
emptyHost,
collectionName,
schematicName
} = options;

const ui = this.ui;

Expand Down Expand Up @@ -75,8 +83,8 @@ export default Task.extend({
const tree = emptyHost ? new EmptyTree() : new FileSystemTree(new FileSystemHost(workingDir));
const host = observableOf(tree);

const dryRunSink = new DryRunSink(workingDir, opts.force);
const fsSink = new FileSystemSink(workingDir, opts.force);
const dryRunSink = new DryRunSink(workingDir, force);
const fsSink = new FileSystemSink(workingDir, force);

let error = false;
const loggingQueue: OutputLogging[] = [];
Expand Down Expand Up @@ -140,23 +148,23 @@ export default Task.extend({
throw new SilentError();
}

if (opts.dryRun) {
if (dryRun) {
return observableOf(tree);
}
return fsSink.commit(tree).pipe(
ignoreElements(),
concat(observableOf(tree)));
}),
concatMap(() => {
if (!opts.dryRun) {
if (!dryRun) {
return getEngine().executePostTasks();
} else {
return [];
}
}))
.toPromise()
.then(() => {
if (opts.dryRun) {
if (dryRun) {
ui.writeLine(yellow(`\nNOTE: Run with "dry run" no changes were made.`));
}
return {modifiedFiles};
Expand Down

0 comments on commit 12e10e3

Please sign in to comment.