10
10
11
11
import { JsonAstObject , parseJsonAst } from '@angular-devkit/core' ;
12
12
import { Rule , SchematicContext , SchematicsException , Tree , apply , applyTemplates , chain , mergeWith , url } from '@angular-devkit/schematics' ;
13
+ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
13
14
import { getWorkspacePath } from '@schematics/angular/utility/config' ;
14
15
import { findPropertyInAstObject , insertPropertyInAstObjectInOrder } from '@schematics/angular/utility/json-utils' ;
15
16
import { validateProjectName } from '@schematics/angular/utility/validation' ;
@@ -54,7 +55,10 @@ function addDevDependenciesToPackageJson(options: Schema) {
54
55
} ;
55
56
56
57
const recorder = host . beginUpdate ( packageJson ) ;
57
- for ( const packageName of Object . keys ( devDependencies ) ) {
58
+ const depsToInstall = Object . keys ( devDependencies ) . filter ( ( name ) => {
59
+ return ! findPropertyInAstObject ( devDeps , name ) ;
60
+ } ) ;
61
+ for ( const packageName of depsToInstall ) {
58
62
const version = devDependencies [ packageName ] ;
59
63
const indent = 4 ;
60
64
insertPropertyInAstObjectInOrder ( recorder , devDeps , packageName , version , indent ) ;
@@ -346,6 +350,17 @@ function addPostinstallToGenerateNgSummaries() {
346
350
} ;
347
351
}
348
352
353
+ /**
354
+ * Schedule a task to perform npm / yarn install.
355
+ */
356
+ function installNodeModules ( options : Schema ) : Rule {
357
+ return ( host : Tree , context : SchematicContext ) => {
358
+ if ( ! options . skipInstall ) {
359
+ context . addTask ( new NodePackageInstallTask ( ) ) ;
360
+ }
361
+ } ;
362
+ }
363
+
349
364
export default function ( options : Schema ) : Rule {
350
365
return ( host : Tree ) => {
351
366
validateProjectName ( options . name ) ;
@@ -360,6 +375,7 @@ export default function(options: Schema): Rule {
360
375
updateGitignore ( ) ,
361
376
updateTsconfigJson ( ) ,
362
377
upgradeRxjs ( ) ,
378
+ installNodeModules ( options ) ,
363
379
] ) ;
364
380
} ;
365
381
}
0 commit comments