Skip to content

Commit afa71a1

Browse files
committed
feat(@angular/cli): add help for ng-new schematics
Before it was missing because we need to load the schematics engine for it. I moved the ng update logic that did this to SchematicCommand.
1 parent 06d332b commit afa71a1

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

packages/angular/cli/commands/new-impl.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ import { Schema as NewCommandSchema } from './new';
1414

1515
export class NewCommand extends SchematicCommand<NewCommandSchema> {
1616
public readonly allowMissingWorkspace = true;
17-
private schematicName = 'ng-new';
17+
schematicName = 'ng-new';
1818

1919
public async run(options: NewCommandSchema & Arguments) {
20-
if (options.dryRun) {
21-
options.skipGit = true;
22-
}
23-
2420
let collectionName: string;
2521
if (options.collection) {
2622
collectionName = options.collection;

packages/angular/cli/commands/update-impl.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,13 @@ import { normalize } from '@angular-devkit/core';
99
import { Arguments, Option } from '../models/interface';
1010
import { SchematicCommand } from '../models/schematic-command';
1111
import { findUp } from '../utilities/find-up';
12-
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
1312
import { Schema as UpdateCommandSchema } from './update';
1413

1514
export class UpdateCommand extends SchematicCommand<UpdateCommandSchema> {
1615
public readonly allowMissingWorkspace = true;
1716

18-
private collectionName = '@schematics/update';
19-
private schematicName = 'update';
20-
21-
async initialize(input: UpdateCommandSchema & Arguments) {
22-
await super.initialize(input);
23-
24-
// Set the options.
25-
const collection = this.getCollection(this.collectionName);
26-
const schematic = this.getSchematic(collection, this.schematicName, true);
27-
const options = await parseJsonSchemaToOptions(
28-
this._workflow.registry,
29-
schematic.description.schemaJson || {},
30-
);
31-
32-
this.description.options.push(...options);
33-
}
17+
collectionName = '@schematics/update';
18+
schematicName = 'update';
3419

3520
async parseArguments(schematicOptions: string[], schema: Option[]): Promise<Arguments> {
3621
const args = await super.parseArguments(schematicOptions, schema);

packages/angular/cli/models/schematic-command.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export abstract class SchematicCommand<
8282
private readonly _engine: Engine<FileSystemCollectionDesc, FileSystemSchematicDesc>;
8383
protected _workflow: workflow.BaseWorkflow;
8484

85+
protected collectionName = '@schematics/angular';
86+
protected schematicName?: string;
87+
8588
constructor(
8689
context: CommandContext,
8790
description: CommandDescription,
@@ -95,6 +98,18 @@ export abstract class SchematicCommand<
9598
public async initialize(options: T & Arguments) {
9699
this._loadWorkspace();
97100
this.createWorkflow(options);
101+
102+
if (this.schematicName) {
103+
// Set the options.
104+
const collection = this.getCollection(this.collectionName);
105+
const schematic = this.getSchematic(collection, this.schematicName, true);
106+
const options = await parseJsonSchemaToOptions(
107+
this._workflow.registry,
108+
schematic.description.schemaJson || {},
109+
);
110+
111+
this.description.options.push(...options);
112+
}
98113
}
99114

100115
public async printHelp(options: T & Arguments) {
@@ -330,7 +345,7 @@ export abstract class SchematicCommand<
330345
}
331346
}
332347

333-
return '@schematics/angular';
348+
return this.collectionName;
334349
}
335350

336351
protected async runSchematic(options: RunSchematicOptions) {
@@ -357,7 +372,7 @@ export abstract class SchematicCommand<
357372
schematicName = schematic.description.name;
358373

359374
// TODO: Remove warning check when 'targets' is default
360-
if (collectionName !== '@schematics/angular') {
375+
if (collectionName !== this.collectionName) {
361376
const [ast, configPath] = getWorkspaceRaw('local');
362377
if (ast) {
363378
const projectsKeyValue = ast.properties.find(p => p.key.value === 'projects');

packages/angular/cli/utilities/json-schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export async function parseJsonSchemaToOptions(
158158
defaultValue = schema.default;
159159
}
160160
break;
161+
162+
default:
163+
console.log(types[0], schema);
161164
}
162165
}
163166

0 commit comments

Comments
 (0)