66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { Rule , Tree , SchematicContext , TaskId } from '@angular-devkit/schematics' ;
9+ import { Rule , SchematicContext , Tree } from '@angular-devkit/schematics' ;
1010import { NodePackageInstallTask , RunSchematicTask } from '@angular-devkit/schematics/tasks' ;
11- import { addPackageToPackageJson , getPackageVersionFromPackageJson } from './package-json ' ;
11+ import { addPackageToPackageJson , getPackageVersionFromPackageJson } from './package-config ' ;
1212import { Schema } from './schema' ;
1313import { hammerjsVersion , materialVersion , requiredAngularVersionRange } from './version-names' ;
1414
@@ -21,32 +21,24 @@ import {hammerjsVersion, materialVersion, requiredAngularVersionRange} from './v
2121 */
2222export default function ( options : Schema ) : Rule {
2323 return ( host : Tree , context : SchematicContext ) => {
24- // Since the Angular Material schematics depend on the schematic utility functions from the
25- // CDK, we need to install the CDK before loading the schematic files that import from the CDK.
26- let installTaskId : TaskId ;
27-
28- if ( ! options . skipPackageJson ) {
29- // Version tag of the `@angular/core` dependency that has been loaded from the `package.json`
30- // of the CLI project. This tag should be preferred because all Angular dependencies should
31- // have the same version tag if possible.
32- const ngCoreVersionTag = getPackageVersionFromPackageJson ( host , '@angular/core' ) ;
33-
34- addPackageToPackageJson ( host , '@angular/cdk' , `^${ materialVersion } ` ) ;
35- addPackageToPackageJson ( host , '@angular/material' , `^${ materialVersion } ` ) ;
36- addPackageToPackageJson ( host , '@angular/animations' ,
37- ngCoreVersionTag || requiredAngularVersionRange ) ;
24+ // Version tag of the `@angular/core` dependency that has been loaded from the `package.json`
25+ // of the CLI project. This tag should be preferred because all Angular dependencies should
26+ // have the same version tag if possible.
27+ const ngCoreVersionTag = getPackageVersionFromPackageJson ( host , '@angular/core' ) ;
3828
39- if ( options . gestures ) {
40- addPackageToPackageJson ( host , 'hammerjs' , hammerjsVersion ) ;
41- }
29+ addPackageToPackageJson ( host , '@angular/cdk' , `^${ materialVersion } ` ) ;
30+ addPackageToPackageJson ( host , '@angular/material' , `^${ materialVersion } ` ) ;
31+ addPackageToPackageJson ( host , '@angular/animations' ,
32+ ngCoreVersionTag || requiredAngularVersionRange ) ;
4233
43- installTaskId = context . addTask ( new NodePackageInstallTask ( ) ) ;
44- } else {
45- installTaskId = context . addTask ( new NodePackageInstallTask ( {
46- packageName : `@angular/cdk@^${ materialVersion } `
47- } ) ) ;
34+ if ( options . gestures ) {
35+ addPackageToPackageJson ( host , 'hammerjs' , hammerjsVersion ) ;
4836 }
4937
38+ // Since the Angular Material schematics depend on the schematic utility functions from the
39+ // CDK, we need to install the CDK before loading the schematic files that import from the CDK.
40+ const installTaskId = context . addTask ( new NodePackageInstallTask ( ) ) ;
41+
5042 context . addTask ( new RunSchematicTask ( 'ng-add-setup-project' , options ) , [ installTaskId ] ) ;
5143 } ;
5244}
0 commit comments