Skip to content

Commit

Permalink
feat(@schematics/angular): relocate ng g service-worker files
Browse files Browse the repository at this point in the history
This is a follow up on #13811, with this now all application have the same structure and hence `ng g service-worker` should follow suit and have the same folder strucute if generated in a root app, or an app inside the projects.
  • Loading branch information
Alan authored and hansl committed Mar 6, 2019
1 parent f06493c commit 64b83e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions packages/schematics/angular/service-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function updateConfigFile(options: ServiceWorkerOptions, root: string): Rule {

const config = getProjectConfiguration(workspace, options);
config.serviceWorker = true;
config.ngswConfigPath = `${root.endsWith('/') ? root : root + '/'}ngsw-config.json`;
config.ngswConfigPath = `${root && !root.endsWith('/') ? root + '/' : root}ngsw-config.json`;

return updateWorkspace(workspace);
};
Expand Down Expand Up @@ -174,17 +174,16 @@ export default function (options: ServiceWorkerOptions): Rule {
resourcesOutputPath = '/' + resourcesOutputPath.split('/').filter(x => !!x).join('/');
}

const root = project.root || project.sourceRoot || '';
const templateSource = apply(url('./files'), [
applyTemplates({ ...options, resourcesOutputPath }),
move(root),
move(project.root),
]);

context.addTask(new NodePackageInstallTask());

return chain([
mergeWith(templateSource),
updateConfigFile(options, root),
updateConfigFile(options, project.root),
addDependencies(),
updateAppModule(options),
]);
Expand Down
6 changes: 3 additions & 3 deletions packages/schematics/angular/service-worker/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Service Worker Schematic', () => {
.toContain('/outDir/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)');
});

it('should generate ngsw-config.json in src when the application is at root level', () => {
it('should generate ngsw-config.json in root when the application is at root level', () => {
const name = 'foo';
const rootAppOptions: ApplicationOptions = {
...appOptions,
Expand All @@ -134,11 +134,11 @@ describe('Service Worker Schematic', () => {

let tree = schematicRunner.runSchematic('application', rootAppOptions, appTree);
tree = schematicRunner.runSchematic('service-worker', rootSWOptions, tree);
expect(tree.exists('/src/ngsw-config.json')).toBe(true);
expect(tree.exists('/ngsw-config.json')).toBe(true);

const { projects } = JSON.parse(tree.readContent('/angular.json'));
expect(projects.foo.architect.build.configurations.production.ngswConfigPath)
.toBe('src/ngsw-config.json');
.toBe('ngsw-config.json');
});

});

0 comments on commit 64b83e2

Please sign in to comment.