Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/ng-generate/update-schematic/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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));
Expand Down
9 changes: 8 additions & 1 deletion src/ng-generate/update-schematic/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}