@@ -26,30 +26,41 @@ import { getWorkspace, updateWorkspace } from '../utility/config';
26
26
import { addPackageJsonDependency , getPackageJsonDependency } from '../utility/dependencies' ;
27
27
import { getAppModulePath } from '../utility/ng-ast-utils' ;
28
28
import { getProjectTargets , targetBuildNotFoundError } from '../utility/project-targets' ;
29
- import { BrowserBuilderOptions , BrowserBuilderTarget } from '../utility/workspace-models' ;
29
+ import {
30
+ BrowserBuilderOptions ,
31
+ BrowserBuilderTarget ,
32
+ WorkspaceSchema ,
33
+ } from '../utility/workspace-models' ;
30
34
import { Schema as ServiceWorkerOptions } from './schema' ;
31
35
32
- function updateConfigFile ( options : ServiceWorkerOptions ) : Rule {
33
- return ( host : Tree , context : SchematicContext ) => {
34
- context . logger . debug ( 'updating config file.' ) ;
35
- const workspace = getWorkspace ( host ) ;
36
+ function getProjectConfiguration (
37
+ workspace : WorkspaceSchema ,
38
+ options : ServiceWorkerOptions ,
39
+ ) : BrowserBuilderOptions {
40
+ const projectTargets = getProjectTargets ( workspace , options . project ) ;
41
+ if ( ! projectTargets [ options . target ] ) {
42
+ throw new Error ( `Target is not defined for this project.` ) ;
43
+ }
36
44
37
- const projectTargets = getProjectTargets ( workspace , options . project ) ;
45
+ const target = projectTargets [ options . target ] as BrowserBuilderTarget ;
46
+ let applyTo = target . options ;
38
47
39
- if ( ! projectTargets [ options . target ] ) {
40
- throw new Error ( `Target is not defined for this project.` ) ;
41
- }
48
+ if ( options . configuration &&
49
+ target . configurations &&
50
+ target . configurations [ options . configuration ] ) {
51
+ applyTo = target . configurations [ options . configuration ] as BrowserBuilderOptions ;
52
+ }
42
53
43
- const target = projectTargets [ options . target ] as BrowserBuilderTarget ;
44
- let applyTo = target . options ;
54
+ return applyTo ;
55
+ }
45
56
46
- if ( options . configuration &&
47
- target . configurations &&
48
- target . configurations [ options . configuration ] ) {
49
- applyTo = target . configurations [ options . configuration ] as BrowserBuilderOptions ;
50
- }
57
+ function updateConfigFile ( options : ServiceWorkerOptions ) : Rule {
58
+ return ( host : Tree , context : SchematicContext ) => {
59
+ context . logger . debug ( 'updating config file.' ) ;
60
+ const workspace = getWorkspace ( host ) ;
51
61
52
- applyTo . serviceWorker = true ;
62
+ const config = getProjectConfiguration ( workspace , options ) ;
63
+ config . serviceWorker = true ;
53
64
54
65
return updateWorkspace ( workspace ) ;
55
66
} ;
@@ -160,8 +171,13 @@ export default function (options: ServiceWorkerOptions): Rule {
160
171
throw new SchematicsException ( `Service worker requires a project type of "application".` ) ;
161
172
}
162
173
174
+ let { resourcesOutputPath = '' } = getProjectConfiguration ( workspace , options ) ;
175
+ if ( resourcesOutputPath ) {
176
+ resourcesOutputPath = '/' + resourcesOutputPath . split ( '/' ) . filter ( x => ! ! x ) . join ( '/' ) ;
177
+ }
178
+
163
179
const templateSource = apply ( url ( './files' ) , [
164
- template ( { ...options } ) ,
180
+ template ( { ...options , resourcesOutputPath } ) ,
165
181
move ( project . root ) ,
166
182
] ) ;
167
183
0 commit comments