mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
fix(@schematics/angular): show better error when non existing project is passed to the component schematic
Closes: #21003
This commit is contained in:
parent
f9657bc919
commit
7cd801eb06
@ -116,7 +116,11 @@ export default function (options: ComponentOptions): Rule {
|
|||||||
const workspace = await getWorkspace(host);
|
const workspace = await getWorkspace(host);
|
||||||
const project = workspace.projects.get(options.project as string);
|
const project = workspace.projects.get(options.project as string);
|
||||||
|
|
||||||
if (options.path === undefined && project) {
|
if (!project) {
|
||||||
|
throw new SchematicsException(`Project "${options.project}" does not exist.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.path === undefined) {
|
||||||
options.path = buildDefaultPath(project);
|
options.path = buildDefaultPath(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ export default function (options: DirectiveOptions): Rule {
|
|||||||
const workspace = await getWorkspace(host);
|
const workspace = await getWorkspace(host);
|
||||||
const project = workspace.projects.get(options.project as string);
|
const project = workspace.projects.get(options.project as string);
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new SchematicsException(`Invalid project name (${options.project})`);
|
throw new SchematicsException(`Project "${options.project}" does not exist.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.path === undefined) {
|
if (options.path === undefined) {
|
||||||
|
@ -179,7 +179,7 @@ export default function (options: LibraryOptions): Rule {
|
|||||||
commonModule: false,
|
commonModule: false,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: sourceDir,
|
path: sourceDir,
|
||||||
project: options.name,
|
project: projectName,
|
||||||
}),
|
}),
|
||||||
schematic('component', {
|
schematic('component', {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
@ -189,13 +189,13 @@ export default function (options: LibraryOptions): Rule {
|
|||||||
flat: true,
|
flat: true,
|
||||||
path: sourceDir,
|
path: sourceDir,
|
||||||
export: true,
|
export: true,
|
||||||
project: options.name,
|
project: projectName,
|
||||||
}),
|
}),
|
||||||
schematic('service', {
|
schematic('service', {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
flat: true,
|
flat: true,
|
||||||
path: sourceDir,
|
path: sourceDir,
|
||||||
project: options.name,
|
project: projectName,
|
||||||
}),
|
}),
|
||||||
options.lintFix ? applyLintFix(sourceDir) : noop(),
|
options.lintFix ? applyLintFix(sourceDir) : noop(),
|
||||||
(_tree: Tree, context: SchematicContext) => {
|
(_tree: Tree, context: SchematicContext) => {
|
||||||
|
@ -85,7 +85,7 @@ export async function createDefaultPath(tree: Tree, projectName: string): Promis
|
|||||||
const workspace = await getWorkspace(tree);
|
const workspace = await getWorkspace(tree);
|
||||||
const project = workspace.projects.get(projectName);
|
const project = workspace.projects.get(projectName);
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Specified project does not exist.');
|
throw new Error(`Project "${projectName}" does not exist.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildDefaultPath(project);
|
return buildDefaultPath(project);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user