File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
packages/schematics/angular/service-worker Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,12 @@ import {
11
11
SchematicsException ,
12
12
Tree ,
13
13
UpdateRecorder ,
14
+ apply ,
14
15
chain ,
16
+ mergeWith ,
17
+ move ,
18
+ template ,
19
+ url ,
15
20
} from '@angular-devkit/schematics' ;
16
21
import * as ts from 'typescript' ;
17
22
import { addSymbolToNgModuleMetadata , isImported } from '../utility/ast-utils' ;
@@ -158,7 +163,19 @@ function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
158
163
159
164
export default function ( options : ServiceWorkerOptions ) : Rule {
160
165
return ( host : Tree , context : SchematicContext ) => {
166
+ const workspace = getWorkspace ( host ) ;
167
+ const project = workspace . projects [ options . project ] ;
168
+ if ( ! project ) {
169
+ throw new SchematicsException ( `Invalid project name (${ options . project } )` ) ;
170
+ }
171
+
172
+ const templateSource = apply ( url ( './files' ) , [
173
+ template ( { ...options } ) ,
174
+ move ( project . root ) ,
175
+ ] ) ;
176
+
161
177
return chain ( [
178
+ mergeWith ( templateSource ) ,
162
179
updateConfigFile ( options ) ,
163
180
addDependencies ( ) ,
164
181
updateAppModule ( options ) ,
Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ describe('Service Worker Schematic', () => {
90
90
// tslint:disable-next-line:max-line-length
91
91
const regex = / S e r v i c e W o r k e r M o d u l e \. r e g i s t e r \( ' \/ n g s w - w o r k e r .j s \' , { e n a b l e d : e n v i r o n m e n t .p r o d u c t i o n } \) / ;
92
92
expect ( pkgText ) . toMatch ( regex ) ;
93
+ } ) ;
93
94
95
+ it ( 'should put the ngsw-config.json file in the project root' , ( ) => {
96
+ const tree = schematicRunner . runSchematic ( 'service-worker' , defaultOptions , appTree ) ;
97
+ const path = '/projects/bar/ngsw-config.json' ;
98
+ expect ( tree . exists ( path ) ) . toEqual ( true ) ;
94
99
} ) ;
95
100
} ) ;
You can’t perform that action at this time.
0 commit comments