This repository was archived by the owner on Apr 4, 2025. It is now read-only.
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 {
1111 SchematicsException ,
1212 Tree ,
1313 UpdateRecorder ,
14+ apply ,
1415 chain ,
16+ mergeWith ,
17+ move ,
18+ template ,
19+ url ,
1520} from '@angular-devkit/schematics' ;
1621import * as ts from 'typescript' ;
1722import { addSymbolToNgModuleMetadata , isImported } from '../utility/ast-utils' ;
@@ -158,7 +163,19 @@ function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
158163
159164export default function ( options : ServiceWorkerOptions ) : Rule {
160165 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+
161177 return chain ( [
178+ mergeWith ( templateSource ) ,
162179 updateConfigFile ( options ) ,
163180 addDependencies ( ) ,
164181 updateAppModule ( options ) ,
Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ describe('Service Worker Schematic', () => {
9090 // tslint:disable-next-line:max-line-length
9191 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 } \) / ;
9292 expect ( pkgText ) . toMatch ( regex ) ;
93+ } ) ;
9394
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 ) ;
9499 } ) ;
95100} ) ;
You can’t perform that action at this time.
0 commit comments