diff --git a/npm/ng-packs/packages/schematics/src/utils/index.ts b/npm/ng-packs/packages/schematics/src/utils/index.ts index 4ddc9e04c2..2110caa3d8 100644 --- a/npm/ng-packs/packages/schematics/src/utils/index.ts +++ b/npm/ng-packs/packages/schematics/src/utils/index.ts @@ -1,3 +1,4 @@ export * from './angular'; +export * from './project'; export * from './text'; export * from './workspace'; diff --git a/npm/ng-packs/packages/schematics/src/utils/project.ts b/npm/ng-packs/packages/schematics/src/utils/project.ts new file mode 100644 index 0000000000..79bb79c796 --- /dev/null +++ b/npm/ng-packs/packages/schematics/src/utils/project.ts @@ -0,0 +1,22 @@ +import { ProjectDefinition } from '@angular-devkit/core/src/workspace'; +import { SchematicsException, Tree } from '@angular-devkit/schematics'; +import { Exception } from '../enums'; +import { getWorkspace } from './angular/workspace'; +import { readWorkspaceSchema } from './workspace'; + +export async function resolveProject( + tree: Tree, + name: string, +): Promise<{ name: string; definition: ProjectDefinition }> { + const workspace = await getWorkspace(tree); + let definition = workspace.projects.get(name); + + if (!definition) { + name = readWorkspaceSchema(tree).defaultProject!; + definition = workspace.projects.get(name); + } + + if (!definition) throw new SchematicsException(Exception.NoProject); + + return { name, definition }; +}