@@ -5,7 +5,7 @@ import { SchematicsException, Tree } from '@angular-devkit/schematics';
5
5
import ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript' ;
6
6
import { findNode , addImportToModule , insertImport } from '@schematics/angular/utility/ast-utils' ;
7
7
import { InsertChange , ReplaceChange , applyToUpdateRecorder , Change } from '@schematics/angular/utility/change' ;
8
- import { findModuleFromOptions , buildRelativePath } from '@schematics/angular/utility/find-module' ;
8
+ import { buildRelativePath } from '@schematics/angular/utility/find-module' ;
9
9
import { overwriteIfExists } from './common' ;
10
10
11
11
// We consider a project to be a universal project if it has a `server` architect
@@ -151,17 +151,36 @@ export function addEnvironmentEntry(
151
151
return host ;
152
152
}
153
153
154
- export function addToNgModule ( host : Tree , options : { sourcePath : string , features : FEATURES [ ] } ) {
155
-
156
- const modulePath = findModuleFromOptions ( host , {
157
- name : 'app' ,
158
- path : options . sourcePath ,
159
- } ) ;
154
+ // TODO rewrite using typescript
155
+ export function addFixesToServer ( host : Tree , options : { sourcePath : string , features : FEATURES [ ] } ) {
156
+ const serverPath = `/server.ts` ;
160
157
161
- if ( ! modulePath ) {
158
+ if ( ! host . exists ( serverPath ) ) {
162
159
return host ;
163
160
}
164
161
162
+ const text = host . read ( serverPath ) ;
163
+ if ( text === null ) {
164
+ throw new SchematicsException ( `File ${ serverPath } does not exist.` ) ;
165
+ }
166
+ const sourceText = text . toString ( 'utf-8' ) ;
167
+ const addZonePatch = ! sourceText . includes ( 'import \'zone.js/dist/zone-patch-rxjs\';' ) ;
168
+ const addFirestorePatch = options . features . includes ( FEATURES . Firestore ) &&
169
+ ! sourceText . includes ( 'import \'@angular/fire/firestore-protos\';' ) ;
170
+
171
+ if ( addZonePatch || addFirestorePatch ) {
172
+ overwriteIfExists ( host , serverPath , sourceText . replace ( 'import \'zone.js/dist/zone-node\';' , `import 'zone.js/dist/zone-node';
173
+ ${ addZonePatch ? 'import \'zone.js/dist/zone-patch-rxjs\';' : '' }
174
+ ${ addFirestorePatch ? 'import \'@angular/fire/firestore-protos\';' : '' } `) ) ;
175
+ }
176
+
177
+ return host ;
178
+ }
179
+
180
+ export function addToNgModule ( host : Tree , options : { sourcePath : string , features : FEATURES [ ] } ) {
181
+
182
+ const modulePath = `/${ options . sourcePath } /app/app.module.ts` ;
183
+
165
184
if ( ! host . exists ( modulePath ) ) {
166
185
throw new Error ( `Specified module path ${ modulePath } does not exist` ) ;
167
186
}
0 commit comments