Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

fix(@angular/pwa): use default project #813

Merged
merged 1 commit into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/angular/pwa/pwa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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".`);
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/pwa/pwa/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Schema {
/**
* The name of the project.
*/
project: string;
project?: string;
/**
* ": "The target to apply service worker to.
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/angular/pwa/pwa/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +26,5 @@
"description": "The title of the application."
}
},
"required": [
"project"
]
"required": []
}
9 changes: 6 additions & 3 deletions packages/schematics/angular/service-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand Down Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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})`);
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/service-worker/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Schema {
/**
* The name of the project.
*/
project: string;
project?: string;
/**
* ": "The target to apply service worker to.
*/
Expand Down
9 changes: 5 additions & 4 deletions packages/schematics/angular/service-worker/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -19,7 +22,5 @@
"default": "production"
}
},
"required": [
"project"
]
"required": []
}