Browse Source

feat: add utility function to resolve project definition

pull/5137/head
Arman Ozak 6 years ago
parent
commit
9d6d7e488c
  1. 1
      npm/ng-packs/packages/schematics/src/utils/index.ts
  2. 22
      npm/ng-packs/packages/schematics/src/utils/project.ts

1
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';

22
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 };
}
Loading…
Cancel
Save