mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +08:00
feat(@schematics/angular): relocate ng g service-worker
files
This is a follow up on https://github.com/angular/angular-cli/pull/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.
This commit is contained in:
parent
f06493cb8a
commit
64b83e2a55
@ -60,7 +60,7 @@ function updateConfigFile(options: ServiceWorkerOptions, root: string): Rule {
|
|||||||
|
|
||||||
const config = getProjectConfiguration(workspace, options);
|
const config = getProjectConfiguration(workspace, options);
|
||||||
config.serviceWorker = true;
|
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);
|
return updateWorkspace(workspace);
|
||||||
};
|
};
|
||||||
@ -174,17 +174,16 @@ export default function (options: ServiceWorkerOptions): Rule {
|
|||||||
resourcesOutputPath = '/' + resourcesOutputPath.split('/').filter(x => !!x).join('/');
|
resourcesOutputPath = '/' + resourcesOutputPath.split('/').filter(x => !!x).join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = project.root || project.sourceRoot || '';
|
|
||||||
const templateSource = apply(url('./files'), [
|
const templateSource = apply(url('./files'), [
|
||||||
applyTemplates({ ...options, resourcesOutputPath }),
|
applyTemplates({ ...options, resourcesOutputPath }),
|
||||||
move(root),
|
move(project.root),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
context.addTask(new NodePackageInstallTask());
|
context.addTask(new NodePackageInstallTask());
|
||||||
|
|
||||||
return chain([
|
return chain([
|
||||||
mergeWith(templateSource),
|
mergeWith(templateSource),
|
||||||
updateConfigFile(options, root),
|
updateConfigFile(options, project.root),
|
||||||
addDependencies(),
|
addDependencies(),
|
||||||
updateAppModule(options),
|
updateAppModule(options),
|
||||||
]);
|
]);
|
||||||
|
@ -120,7 +120,7 @@ describe('Service Worker Schematic', () => {
|
|||||||
.toContain('/outDir/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)');
|
.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 name = 'foo';
|
||||||
const rootAppOptions: ApplicationOptions = {
|
const rootAppOptions: ApplicationOptions = {
|
||||||
...appOptions,
|
...appOptions,
|
||||||
@ -134,11 +134,11 @@ describe('Service Worker Schematic', () => {
|
|||||||
|
|
||||||
let tree = schematicRunner.runSchematic('application', rootAppOptions, appTree);
|
let tree = schematicRunner.runSchematic('application', rootAppOptions, appTree);
|
||||||
tree = schematicRunner.runSchematic('service-worker', rootSWOptions, tree);
|
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'));
|
const { projects } = JSON.parse(tree.readContent('/angular.json'));
|
||||||
expect(projects.foo.architect.build.configurations.production.ngswConfigPath)
|
expect(projects.foo.architect.build.configurations.production.ngswConfigPath)
|
||||||
.toBe('src/ngsw-config.json');
|
.toBe('ngsw-config.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user