From fca8e55469b02f6b9ede708f436a7fffd71ba739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 18 Nov 2021 15:36:05 +0100 Subject: [PATCH] feat(generate): add --project flag for update schematic --- src/ng-generate/update-schematic/index.ts | 16 +++++++++++++++- src/ng-generate/update-schematic/schema.json | 9 ++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/ng-generate/update-schematic/index.ts b/src/ng-generate/update-schematic/index.ts index 47f5fd8..5fd905d 100644 --- a/src/ng-generate/update-schematic/index.ts +++ b/src/ng-generate/update-schematic/index.ts @@ -1,4 +1,5 @@ -import { apply, applyTemplates, chain, mergeWith, move, noop, Tree, url } from '@angular-devkit/schematics'; +import { apply, applyTemplates, chain, mergeWith, move, noop, SchematicsException, Tree, url } from '@angular-devkit/schematics'; +import { buildDefaultPath, getWorkspace } from '@schematics/angular/utility/workspace'; import * as path from 'path'; import { camelize, dasherize } from '@angular-devkit/core/src/utils/strings'; import { strings } from '@angular-devkit/core'; @@ -8,12 +9,25 @@ import { Location } from '@schematics/angular/utility/parse-name'; export interface UpdateSchematicOptions { name: string; path: string; + project: string; description: string; version: string; } export function createUpdateSchematic(options: UpdateSchematicOptions) { return async (host: Tree) => { + + const workspace = await getWorkspace(host); + const project = workspace.projects.get(options.project as string); + + if (!project) { + throw new SchematicsException(`Project "${options.project}" does not exist.`); + } + + if (options.path === undefined) { + options.path = buildDefaultPath(project); + } + const parsedPath = getParsedPath(options.path, options.name); const generatedSchematicDir = path.join(__dirname, parsedPath.path, dasherize(options.name)); diff --git a/src/ng-generate/update-schematic/schema.json b/src/ng-generate/update-schematic/schema.json index e91b043..c168b4b 100644 --- a/src/ng-generate/update-schematic/schema.json +++ b/src/ng-generate/update-schematic/schema.json @@ -20,8 +20,15 @@ "path": { "type": "string", "format": "path", - "description": "", + "description": "The path to create the schematic.", "visible": false + }, + "project": { + "type": "string", + "description": "The name of the project.", + "$default": { + "$source": "projectName" + } } } }