@@ -21,26 +21,27 @@ import {
2121 url ,
2222} from '@angular-devkit/schematics' ;
2323import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
24+ import {
25+ DependencyType ,
26+ addDependency ,
27+ readWorkspace ,
28+ updateWorkspace ,
29+ } from '@schematics/angular/utility' ;
2430import {
2531 addImportToModule ,
2632 findNode ,
2733 getDecoratorMetadata ,
2834} from '@schematics/angular/utility/ast-utils' ;
2935import { InsertChange , applyToUpdateRecorder } from '@schematics/angular/utility/change' ;
30- import {
31- NodeDependencyType ,
32- addPackageJsonDependency ,
33- } from '@schematics/angular/utility/dependencies' ;
3436import { findBootstrapModulePath } from '@schematics/angular/utility/ng-ast-utils' ;
35- import { getWorkspace , updateWorkspace } from '@schematics/angular/utility/workspace' ;
3637import { posix } from 'path' ;
3738import * as ts from 'typescript' ;
3839
3940import { Schema as NgAddOptions } from './schema' ;
4041
4142export default function ( options : NgAddOptions ) : Rule {
4243 return async ( host , context ) => {
43- const workspace = await getWorkspace ( host ) ;
44+ const workspace = await readWorkspace ( host ) ;
4445 const project = workspace . projects . get ( options . project ) ;
4546
4647 if ( project . extensions . projectType !== 'application' ) {
@@ -59,37 +60,19 @@ export default function (options: NgAddOptions): Rule {
5960 return chain ( [
6061 augmentAppModuleRule ( project , clientBuildTarget , options ) ,
6162 options . ssr ? addSSRRule ( project , clientBuildTarget ) : noop ( ) ,
62- options . prerender ? addPreRenderRule ( ) : noop ( ) ,
63+ options . prerender
64+ ? addDependency ( '@nguniversal/builders' , '~0.0.0-PLACEHOLDER' , {
65+ type : DependencyType . Dev ,
66+ } )
67+ : noop ( ) ,
6368 addScriptsRule ( options ) ,
6469 updateWorkspaceRule ( options ) ,
6570 ] ) ;
6671 } ;
6772}
6873
69- function addPreRenderRule ( ) : Rule {
70- return async ( host ) => {
71- addPackageJsonDependency ( host , {
72- name : '@nguniversal/builders' ,
73- type : NodeDependencyType . Dev ,
74- version : '~0.0.0-PLACEHOLDER' ,
75- } ) ;
76- } ;
77- }
78-
7974function addSSRRule ( project : ProjectDefinition , buildTarget : TargetDefinition ) : Rule {
80- return async ( host ) => {
81- addPackageJsonDependency ( host , {
82- type : NodeDependencyType . Default ,
83- name : 'express' ,
84- version : 'EXPRESS_VERSION' ,
85- } ) ;
86-
87- addPackageJsonDependency ( host , {
88- type : NodeDependencyType . Dev ,
89- name : '@types/express' ,
90- version : 'EXPRESS_TYPES_VERSION' ,
91- } ) ;
92-
75+ return async ( ) => {
9376 const templateSource = apply ( url ( './files/src' ) , [
9477 applyTemplates ( { } ) ,
9578 move ( project . sourceRoot ?? '/src' ) ,
@@ -102,7 +85,17 @@ function addSSRRule(project: ProjectDefinition, buildTarget: TargetDefinition):
10285 move ( project . root ) ,
10386 ] ) ;
10487
105- return chain ( [ mergeWith ( templateSource ) , mergeWith ( rootSource ) ] ) ;
88+ return chain ( [
89+ addDependency ( 'express' , 'EXPRESS_VERSION' , {
90+ type : DependencyType . Default ,
91+ } ) ,
92+
93+ addDependency ( '@types/express' , 'EXPRESS_TYPES_VERSION' , {
94+ type : DependencyType . Dev ,
95+ } ) ,
96+ mergeWith ( templateSource ) ,
97+ mergeWith ( rootSource ) ,
98+ ] ) ;
10699 } ;
107100}
108101
0 commit comments