diff --git a/packages/angular/pwa/pwa/index.ts b/packages/angular/pwa/pwa/index.ts index c7f88c894b..0d7c963742 100644 --- a/packages/angular/pwa/pwa/index.ts +++ b/packages/angular/pwa/pwa/index.ts @@ -36,6 +36,9 @@ function addServiceWorker(options: PwaOptions): Rule { export default function (options: PwaOptions): Rule { return (host: Tree, context: SchematicContext) => { const workspace = getWorkspace(host); + if (!options.project) { + throw new SchematicsException('Option "project" is required.'); + } const project = workspace.projects[options.project]; if (project.projectType !== 'application') { throw new SchematicsException(`PWA requires a project type of "application".`); diff --git a/packages/angular/pwa/pwa/schema.d.ts b/packages/angular/pwa/pwa/schema.d.ts index 1331fdaebf..55091c336f 100644 --- a/packages/angular/pwa/pwa/schema.d.ts +++ b/packages/angular/pwa/pwa/schema.d.ts @@ -10,7 +10,7 @@ export interface Schema { /** * The name of the project. */ - project: string; + project?: string; /** * ": "The target to apply service worker to. */ diff --git a/packages/angular/pwa/pwa/schema.json b/packages/angular/pwa/pwa/schema.json index 05a34fcbd6..b06bd47d1d 100644 --- a/packages/angular/pwa/pwa/schema.json +++ b/packages/angular/pwa/pwa/schema.json @@ -6,7 +6,10 @@ "properties": { "project": { "type": "string", - "description": "The name of the project." + "description": "The name of the project.", + "$default": { + "$source": "projectName" + } }, "target": { "type": "string", @@ -23,7 +26,5 @@ "description": "The title of the application." } }, - "required": [ - "project" - ] + "required": [] } \ No newline at end of file diff --git a/packages/schematics/angular/service-worker/index.ts b/packages/schematics/angular/service-worker/index.ts index 87b013080f..55e8af392d 100644 --- a/packages/schematics/angular/service-worker/index.ts +++ b/packages/schematics/angular/service-worker/index.ts @@ -38,7 +38,7 @@ function updateConfigFile(options: ServiceWorkerOptions): Rule { const workspace = getWorkspace(host); - const project = workspace.projects[options.project]; + const project = workspace.projects[options.project as string]; if (!project) { throw new Error(`Project is not defined in this workspace.`); @@ -94,7 +94,7 @@ function updateAppModule(options: ServiceWorkerOptions): Rule { // find app module const workspace = getWorkspace(host); - const project = workspace.projects[options.project]; + const project = workspace.projects[options.project as string]; if (!project.architect) { throw new Error('Project architect not found.'); } @@ -164,7 +164,7 @@ function getTsSourceFile(host: Tree, path: string): ts.SourceFile { function updateIndexFile(options: ServiceWorkerOptions): Rule { return (host: Tree, context: SchematicContext) => { const workspace = getWorkspace(host); - const project = workspace.projects[options.project]; + const project = workspace.projects[options.project as string]; let path: string; if (project && project.architect && project.architect.build && project.architect.build.options.index) { @@ -227,6 +227,9 @@ function getIndent(text: string): string { export default function (options: ServiceWorkerOptions): Rule { return (host: Tree, context: SchematicContext) => { const workspace = getWorkspace(host); + if (!options.project) { + throw new SchematicsException('Option "project" is required.'); + } const project = workspace.projects[options.project]; if (!project) { throw new SchematicsException(`Invalid project name (${options.project})`); diff --git a/packages/schematics/angular/service-worker/schema.d.ts b/packages/schematics/angular/service-worker/schema.d.ts index 624ffaadde..aa66e38820 100644 --- a/packages/schematics/angular/service-worker/schema.d.ts +++ b/packages/schematics/angular/service-worker/schema.d.ts @@ -10,7 +10,7 @@ export interface Schema { /** * The name of the project. */ - project: string; + project?: string; /** * ": "The target to apply service worker to. */ diff --git a/packages/schematics/angular/service-worker/schema.json b/packages/schematics/angular/service-worker/schema.json index 8f84154b17..4ec3fe49e3 100644 --- a/packages/schematics/angular/service-worker/schema.json +++ b/packages/schematics/angular/service-worker/schema.json @@ -6,7 +6,10 @@ "properties": { "project": { "type": "string", - "description": "The name of the project." + "description": "The name of the project.", + "$default": { + "$source": "projectName" + } }, "target": { "type": "string", @@ -19,7 +22,5 @@ "default": "production" } }, - "required": [ - "project" - ] + "required": [] } \ No newline at end of file