Skip to content

Commit 12e10e3

Browse files
committed
feat(@angular/cli): Clean up generate options
BREAKING CHANGE: Removed collection and lint-fix options
1 parent a9bbe2a commit 12e10e3

File tree

3 files changed

+38
-48
lines changed

3 files changed

+38
-48
lines changed

docs/documentation/generate.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,26 @@
2323
<code>--dry-run</code> (aliases: <code>-d</code>) <em>default value: false</em>
2424
</p>
2525
<p>
26-
Run through without making any changes. Will list all files that would have been created when running <code>ng generate</code>.
26+
Run through without making any changes.
2727
</p>
2828
</details>
2929

3030
<details>
31-
<summary>lint-fix</summary>
31+
<summary>force</summary>
3232
<p>
33-
<code>--lint-fix</code> (aliases: <code>-l</code>)
33+
<code>--force</code> (aliases: <code>-f</code>) <em>default value: false</em>
3434
</p>
3535
<p>
36-
Use lint to fix files after generation.
37-
</p>
38-
<p>
39-
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>).
40-
</p>
41-
</details>
42-
43-
<details>
44-
<summary>verbose</summary>
45-
<p>
46-
<code>--verbose</code> (aliases: <code>-v</code>) <em>default value: false</em>
47-
</p>
48-
<p>
49-
Adds more details to output logging.
36+
Forces overwriting of files.
5037
</p>
5138
</details>
5239

5340
<details>
54-
<summary>collection</summary>
41+
<summary>app</summary>
5542
<p>
56-
<code>--collection</code> (aliases: <code>-c</code>) <em>default value: @schematics/angular</em>
43+
<code>--app</code>
5744
</p>
5845
<p>
59-
Schematics collection to use.
46+
Specifies app name to use.
6047
</p>
6148
</details>

packages/@angular/cli/commands/generate.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command, CommandScope } from '../models/command';
1+
import { Command, CommandScope, Option } from '../models/command';
22
import chalk from 'chalk';
33
const stringUtils = require('ember-cli-string-utils');
44
import { CliConfig } from '../models/config';
@@ -21,7 +21,7 @@ export default class GenerateCommand extends Command {
2121
public static aliases = ['g'];
2222
public readonly scope = CommandScope.inProject;
2323
public arguments = ['schematic'];
24-
public options = [
24+
public options: Option[] = [
2525
{
2626
name: 'dry-run',
2727
type: Boolean,
@@ -39,20 +39,7 @@ export default class GenerateCommand extends Command {
3939
{
4040
name: 'app',
4141
type: String,
42-
aliases: ['a'],
4342
description: 'Specifies app name to use.'
44-
},
45-
{
46-
name: 'collection',
47-
type: String,
48-
aliases: ['c'],
49-
description: 'Schematics collection to use.'
50-
},
51-
{
52-
name: 'lint-fix',
53-
type: Boolean,
54-
aliases: ['l'],
55-
description: 'Use lint to fix files after generation.'
5643
}
5744
];
5845

@@ -170,19 +157,19 @@ export default class GenerateCommand extends Command {
170157
options.type = options.type;
171158
}
172159

160+
const schematicOptions = this.stripLocalOptions(options);
173161
return schematicRunTask.run({
174-
taskOptions: options,
162+
taskOptions: schematicOptions,
163+
dryRun: options.dryRun,
164+
force: options.force,
175165
workingDir: cwd,
176166
collectionName,
177167
schematicName
178168
});
179169
}
180170

181171
private parseSchematicInfo(options: any) {
182-
let collectionName: string =
183-
options.collection ||
184-
options.c ||
185-
CliConfig.getValue('defaults.schematics.collection');
172+
let collectionName: string = CliConfig.getValue('defaults.schematics.collection');
186173

187174
let schematicName = options.schematic;
188175

@@ -213,4 +200,12 @@ export default class GenerateCommand extends Command {
213200
this.logger.info(cyan(` ng generate <schematic> --help`));
214201
}
215202
}
203+
204+
private stripLocalOptions(options: any): any {
205+
const opts = Object.assign({}, options);
206+
delete opts.dryRun;
207+
delete opts.force;
208+
delete opts.app;
209+
return opts;
210+
}
216211
}

packages/@angular/cli/tasks/schematic-run.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const SilentError = require('silent-error');
2121
const Task = require('../ember-cli/lib/models/task');
2222

2323
export interface SchematicRunOptions {
24+
dryRun: boolean;
25+
force: boolean;
2426
taskOptions: SchematicOptions;
2527
workingDir: string;
2628
emptyHost: boolean;
@@ -29,8 +31,6 @@ export interface SchematicRunOptions {
2931
}
3032

3133
export interface SchematicOptions {
32-
dryRun: boolean;
33-
force: boolean;
3434
[key: string]: any;
3535
}
3636

@@ -46,7 +46,15 @@ interface OutputLogging {
4646

4747
export default Task.extend({
4848
run: function (options: SchematicRunOptions): Promise<SchematicOutput> {
49-
const { taskOptions, workingDir, emptyHost, collectionName, schematicName } = options;
49+
const {
50+
taskOptions,
51+
force,
52+
dryRun,
53+
workingDir,
54+
emptyHost,
55+
collectionName,
56+
schematicName
57+
} = options;
5058

5159
const ui = this.ui;
5260

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

78-
const dryRunSink = new DryRunSink(workingDir, opts.force);
79-
const fsSink = new FileSystemSink(workingDir, opts.force);
86+
const dryRunSink = new DryRunSink(workingDir, force);
87+
const fsSink = new FileSystemSink(workingDir, force);
8088

8189
let error = false;
8290
const loggingQueue: OutputLogging[] = [];
@@ -140,23 +148,23 @@ export default Task.extend({
140148
throw new SilentError();
141149
}
142150

143-
if (opts.dryRun) {
151+
if (dryRun) {
144152
return observableOf(tree);
145153
}
146154
return fsSink.commit(tree).pipe(
147155
ignoreElements(),
148156
concat(observableOf(tree)));
149157
}),
150158
concatMap(() => {
151-
if (!opts.dryRun) {
159+
if (!dryRun) {
152160
return getEngine().executePostTasks();
153161
} else {
154162
return [];
155163
}
156164
}))
157165
.toPromise()
158166
.then(() => {
159-
if (opts.dryRun) {
167+
if (dryRun) {
160168
ui.writeLine(yellow(`\nNOTE: Run with "dry run" no changes were made.`));
161169
}
162170
return {modifiedFiles};

0 commit comments

Comments
 (0)