@@ -18,8 +18,16 @@ import {
18
18
virtualFs ,
19
19
} from '@angular-devkit/core' ;
20
20
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' ;
23
31
import * as minimist from 'minimist' ;
24
32
25
33
@@ -36,21 +44,26 @@ function usage(exitCode = 0): never {
36
44
Options:
37
45
--debug Debug mode. This is true by default if the collection is a relative
38
46
path (in that case, turn off with --debug=false).
47
+
39
48
--allowPrivate Allow private schematics to be run from the command line. Default to
40
49
false.
50
+
41
51
--dry-run Do not output anything, but instead just show what actions would be
42
52
performed. Default to true if debug is also true.
53
+
43
54
--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
+
45
59
--verbose Show more information.
46
60
47
61
--help Show this message.
48
62
49
63
Any additional option is passed to the Schematics depending on
50
64
` ) ;
51
65
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 ) ;
54
67
}
55
68
56
69
@@ -68,20 +81,12 @@ function usage(exitCode = 0): never {
68
81
* @param str The argument to parse.
69
82
* @return {{collection: string, schematic: (string)} }
70
83
*/
71
- function parseSchematicName ( str : string | null ) : { collection : string , schematic : string } {
84
+ function parseSchematicName ( str : string | null ) : { collection : string , schematic : string | null } {
72
85
let collection = '@schematics/schematics' ;
73
86
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 ) {
80
89
[ collection , schematic ] = schematic . split ( ':' , 2 ) ;
81
-
82
- if ( ! schematic ) {
83
- usage ( 2 ) ;
84
- }
85
90
}
86
91
87
92
return { collection, schematic } ;
@@ -124,11 +129,21 @@ const isLocalCollection = collectionName.startsWith('.') || collectionName.start
124
129
125
130
/** If the user wants to list schematics, we simply show all the schematic names. */
126
131
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
+
128
140
process . exit ( 0 ) ;
129
- throw 0 ; // TypeScript doesn't know that process.exit() never returns.
130
141
}
131
142
143
+ if ( ! schematicName ) {
144
+ usage ( 1 ) ;
145
+ throw 0 ; // TypeScript doesn't know that process.exit() never returns.
146
+ }
132
147
133
148
/** Gather the arguments for later use. */
134
149
const debug : boolean = argv . debug === null ? isLocalCollection : argv . debug ;
0 commit comments