99// tslint:disable:no-global-tslint-disable no-any
1010import { tags , terminal } from '@angular-devkit/core' ;
1111import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools' ;
12- import { parseOptions } from '../models/command-runner ' ;
13- import { SchematicCommand } from '../models/schematic-command' ;
12+ import { Arguments } from '../models/interface ' ;
13+ import { BaseSchematicOptions , SchematicCommand } from '../models/schematic-command' ;
1414import { NpmInstall } from '../tasks/npm-install' ;
1515import { getPackageManager } from '../utilities/config' ;
1616
17+ export interface AddCommandOptions extends BaseSchematicOptions {
18+ collection : string ;
19+ help ?: boolean ;
20+ help_json ?: boolean ;
21+ }
1722
18- export class AddCommand extends SchematicCommand {
23+ export class AddCommand <
24+ T extends AddCommandOptions = AddCommandOptions ,
25+ > extends SchematicCommand < T > {
1926 readonly allowPrivateSchematics = true ;
2027
21- private async _parseSchematicOptions ( collectionName : string ) : Promise < any > {
22- const schematicOptions = await this . getOptions ( {
23- schematicName : 'ng-add' ,
24- collectionName,
25- } ) ;
26- this . addOptions ( schematicOptions ) ;
27-
28- return parseOptions ( this . _rawArgs , this . options ) ;
29- }
30-
31- validate ( options : any ) {
32- const collectionName = options . _ [ 0 ] ;
33-
34- if ( ! collectionName ) {
35- this . logger . fatal (
36- `The "ng add" command requires a name argument to be specified eg. `
37- + `${ terminal . yellow ( 'ng add [name] ' ) } . For more details, use "ng help".` ,
38- ) ;
39-
40- return false ;
41- }
42-
43- return true ;
44- }
45-
46- async run ( options : any ) {
47- const firstArg = options . _ [ 0 ] ;
48-
49- if ( ! firstArg ) {
28+ async run ( options : AddCommandOptions & Arguments ) {
29+ if ( ! options . collection ) {
5030 this . logger . fatal (
5131 `The "ng add" command requires a name argument to be specified eg. `
5232 + `${ terminal . yellow ( 'ng add [name] ' ) } . For more details, use "ng help".` ,
@@ -59,16 +39,16 @@ export class AddCommand extends SchematicCommand {
5939
6040 const npmInstall : NpmInstall = require ( '../tasks/npm-install' ) . default ;
6141
62- const packageName = firstArg . startsWith ( '@' )
63- ? firstArg . split ( '/' , 2 ) . join ( '/' )
64- : firstArg . split ( '/' , 1 ) [ 0 ] ;
42+ const packageName = options . collection . startsWith ( '@' )
43+ ? options . collection . split ( '/' , 2 ) . join ( '/' )
44+ : options . collection . split ( '/' , 1 ) [ 0 ] ;
6545
6646 // Remove the tag/version from the package name.
6747 const collectionName = (
6848 packageName . startsWith ( '@' )
6949 ? packageName . split ( '@' , 2 ) . join ( '@' )
7050 : packageName . split ( '@' , 1 ) . join ( '@' )
71- ) + firstArg . slice ( packageName . length ) ;
51+ ) + options . collection . slice ( packageName . length ) ;
7252
7353 // We don't actually add the package to package.json, that would be the work of the package
7454 // itself.
@@ -79,11 +59,8 @@ export class AddCommand extends SchematicCommand {
7959 this . project . root ,
8060 ) ;
8161
82- // Reparse the options with the new schematic accessible.
83- options = await this . _parseSchematicOptions ( collectionName ) ;
84-
8562 const runOptions = {
86- schematicOptions : options ,
63+ schematicOptions : options [ '--' ] || [ ] ,
8764 workingDir : this . project . root ,
8865 collectionName,
8966 schematicName : 'ng-add' ,
0 commit comments