diff --git a/npm/ng-packs/packages/schematics/src/utils/index.ts b/npm/ng-packs/packages/schematics/src/utils/index.ts index 5b84b6c8f1..4ddc9e04c2 100644 --- a/npm/ng-packs/packages/schematics/src/utils/index.ts +++ b/npm/ng-packs/packages/schematics/src/utils/index.ts @@ -1,2 +1,3 @@ export * from './angular'; export * from './text'; +export * from './workspace'; diff --git a/npm/ng-packs/packages/schematics/src/utils/workspace.ts b/npm/ng-packs/packages/schematics/src/utils/workspace.ts new file mode 100644 index 0000000000..69aae2e726 --- /dev/null +++ b/npm/ng-packs/packages/schematics/src/utils/workspace.ts @@ -0,0 +1,18 @@ +import { experimental } from '@angular-devkit/core'; +import { SchematicsException, Tree } from '@angular-devkit/schematics'; +import { Exception } from '../enums'; + +export function readWorkspaceSchema(tree: Tree) { + const workspaceBuffer = tree.read('/angular.json') || tree.read('/workspace.json'); + if (!workspaceBuffer) throw new SchematicsException(Exception.NoWorkspace); + + let workspaceSchema: experimental.workspace.WorkspaceSchema; + + try { + workspaceSchema = JSON.parse(workspaceBuffer.toString()); + } catch (_) { + throw new SchematicsException(Exception.InvalidWorkspace); + } + + return workspaceSchema; +}