Skip to content

Commit 8fac6a7

Browse files
alan-agius4hansl
authored andcommitted
fix(@angular-devkit/schematics-cli): fix list-schematics is not printing anything
Usage: ``` $ schematics @schematics/angular: --list-schematics $ schematics --list-schematics ``` When no colon is specified, it means that that you are passing a schematic name to be looked up in the default collection. Closes #12220
1 parent 84533e2 commit 8fac6a7

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

packages/angular_devkit/schematics/src/engine/engine.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
329329
}
330330

331331
// remove duplicates
332-
return [...new Set(names)];
332+
return [...new Set(names)].sort();
333333
}
334334

335335
transformOptions<OptionT extends object, ResultT extends object>(

packages/angular_devkit/schematics_cli/bin/schematics.ts

+33-18
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ import {
1818
virtualFs,
1919
} from '@angular-devkit/core';
2020
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
21-
import { DryRunEvent, UnsuccessfulWorkflowExecution } from '@angular-devkit/schematics';
22-
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
21+
import {
22+
DryRunEvent,
23+
SchematicEngine,
24+
UnsuccessfulWorkflowExecution,
25+
} from '@angular-devkit/schematics';
26+
import {
27+
FileSystemEngineHost,
28+
NodeModulesEngineHost,
29+
NodeWorkflow,
30+
} from '@angular-devkit/schematics/tools';
2331
import * as minimist from 'minimist';
2432

2533

@@ -36,21 +44,26 @@ function usage(exitCode = 0): never {
3644
Options:
3745
--debug Debug mode. This is true by default if the collection is a relative
3846
path (in that case, turn off with --debug=false).
47+
3948
--allowPrivate Allow private schematics to be run from the command line. Default to
4049
false.
50+
4151
--dry-run Do not output anything, but instead just show what actions would be
4252
performed. Default to true if debug is also true.
53+
4354
--force Force overwriting files that would otherwise be an error.
44-
--list-schematics List all schematics from the collection, by name.
55+
56+
--list-schematics List all schematics from the collection, by name. A collection name
57+
should be suffixed by a colon. Example: '@schematics/schematics:'.
58+
4559
--verbose Show more information.
4660
4761
--help Show this message.
4862
4963
Any additional option is passed to the Schematics depending on
5064
`);
5165

52-
process.exit(exitCode);
53-
throw 0; // The node typing sometimes don't have a never type for process.exit().
66+
return process.exit(exitCode);
5467
}
5568

5669

@@ -68,20 +81,12 @@ function usage(exitCode = 0): never {
6881
* @param str The argument to parse.
6982
* @return {{collection: string, schematic: (string)}}
7083
*/
71-
function parseSchematicName(str: string | null): { collection: string, schematic: string } {
84+
function parseSchematicName(str: string | null): { collection: string, schematic: string | null} {
7285
let collection = '@schematics/schematics';
7386

74-
if (!str || str === null) {
75-
usage(1);
76-
}
77-
78-
let schematic: string = str as string;
79-
if (schematic.indexOf(':') != -1) {
87+
let schematic = str;
88+
if (schematic && schematic.indexOf(':') != -1) {
8089
[collection, schematic] = schematic.split(':', 2);
81-
82-
if (!schematic) {
83-
usage(2);
84-
}
8590
}
8691

8792
return { collection, schematic };
@@ -124,11 +129,21 @@ const isLocalCollection = collectionName.startsWith('.') || collectionName.start
124129

125130
/** If the user wants to list schematics, we simply show all the schematic names. */
126131
if (argv['list-schematics']) {
127-
// logger.info(engine.listSchematicNames(collection).join('\n'));
132+
const engineHost = isLocalCollection
133+
? new FileSystemEngineHost(normalize(process.cwd()))
134+
: new NodeModulesEngineHost();
135+
136+
const engine = new SchematicEngine(engineHost);
137+
const collection = engine.createCollection(collectionName);
138+
logger.info(engine.listSchematicNames(collection).join('\n'));
139+
128140
process.exit(0);
129-
throw 0; // TypeScript doesn't know that process.exit() never returns.
130141
}
131142

143+
if (!schematicName) {
144+
usage(1);
145+
throw 0; // TypeScript doesn't know that process.exit() never returns.
146+
}
132147

133148
/** Gather the arguments for later use. */
134149
const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug;

0 commit comments

Comments
 (0)