Skip to content

Commit aae5e42

Browse files
cyrilletuzihansl
authored andcommitted
fix(@angular/pwa): use default project
1 parent fe477b6 commit aae5e42

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

packages/angular/pwa/pwa/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ function addServiceWorker(options: PwaOptions): Rule {
3636
export default function (options: PwaOptions): Rule {
3737
return (host: Tree, context: SchematicContext) => {
3838
const workspace = getWorkspace(host);
39+
if (!options.project) {
40+
throw new SchematicsException('Option "project" is required.');
41+
}
3942
const project = workspace.projects[options.project];
4043
if (project.projectType !== 'application') {
4144
throw new SchematicsException(`PWA requires a project type of "application".`);

packages/angular/pwa/pwa/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Schema {
1010
/**
1111
* The name of the project.
1212
*/
13-
project: string;
13+
project?: string;
1414
/**
1515
* ": "The target to apply service worker to.
1616
*/

packages/angular/pwa/pwa/schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"properties": {
77
"project": {
88
"type": "string",
9-
"description": "The name of the project."
9+
"description": "The name of the project.",
10+
"$default": {
11+
"$source": "projectName"
12+
}
1013
},
1114
"target": {
1215
"type": "string",
@@ -23,7 +26,5 @@
2326
"description": "The title of the application."
2427
}
2528
},
26-
"required": [
27-
"project"
28-
]
29+
"required": []
2930
}

packages/schematics/angular/service-worker/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function updateConfigFile(options: ServiceWorkerOptions): Rule {
3838

3939
const workspace = getWorkspace(host);
4040

41-
const project = workspace.projects[options.project];
41+
const project = workspace.projects[options.project as string];
4242

4343
if (!project) {
4444
throw new Error(`Project is not defined in this workspace.`);
@@ -94,7 +94,7 @@ function updateAppModule(options: ServiceWorkerOptions): Rule {
9494

9595
// find app module
9696
const workspace = getWorkspace(host);
97-
const project = workspace.projects[options.project];
97+
const project = workspace.projects[options.project as string];
9898
if (!project.architect) {
9999
throw new Error('Project architect not found.');
100100
}
@@ -164,7 +164,7 @@ function getTsSourceFile(host: Tree, path: string): ts.SourceFile {
164164
function updateIndexFile(options: ServiceWorkerOptions): Rule {
165165
return (host: Tree, context: SchematicContext) => {
166166
const workspace = getWorkspace(host);
167-
const project = workspace.projects[options.project];
167+
const project = workspace.projects[options.project as string];
168168
let path: string;
169169
if (project && project.architect && project.architect.build &&
170170
project.architect.build.options.index) {
@@ -227,6 +227,9 @@ function getIndent(text: string): string {
227227
export default function (options: ServiceWorkerOptions): Rule {
228228
return (host: Tree, context: SchematicContext) => {
229229
const workspace = getWorkspace(host);
230+
if (!options.project) {
231+
throw new SchematicsException('Option "project" is required.');
232+
}
230233
const project = workspace.projects[options.project];
231234
if (!project) {
232235
throw new SchematicsException(`Invalid project name (${options.project})`);

packages/schematics/angular/service-worker/schema.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Schema {
1010
/**
1111
* The name of the project.
1212
*/
13-
project: string;
13+
project?: string;
1414
/**
1515
* ": "The target to apply service worker to.
1616
*/

packages/schematics/angular/service-worker/schema.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"properties": {
77
"project": {
88
"type": "string",
9-
"description": "The name of the project."
9+
"description": "The name of the project.",
10+
"$default": {
11+
"$source": "projectName"
12+
}
1013
},
1114
"target": {
1215
"type": "string",
@@ -19,7 +22,5 @@
1922
"default": "production"
2023
}
2124
},
22-
"required": [
23-
"project"
24-
]
25+
"required": []
2526
}

0 commit comments

Comments
 (0)