fix(@angular-devkit/schematics-cli): use workflow to list schematics

Closes #18548
This commit is contained in:
Alan Agius 2020-08-17 11:58:09 +02:00
parent 3258267776
commit 439385fef6

View File

@ -22,11 +22,10 @@ import {
import { NodeJsSyncHost, ProcessOutput, createConsoleLogger } from '@angular-devkit/core/node';
import {
DryRunEvent,
SchematicEngine,
UnsuccessfulWorkflowExecution,
formats,
} from '@angular-devkit/schematics';
import { NodeModulesEngineHost, NodeWorkflow, validateOptionsWithSchema } from '@angular-devkit/schematics/tools';
import { NodeWorkflow, validateOptionsWithSchema } from '@angular-devkit/schematics/tools';
import * as inquirer from 'inquirer';
import * as minimist from 'minimist';
@ -64,12 +63,10 @@ export interface MainOptions {
}
function _listSchematics(collectionName: string, logger: logging.Logger) {
function _listSchematics(workflow: NodeWorkflow, collectionName: string, logger: logging.Logger) {
try {
const engineHost = new NodeModulesEngineHost();
const engine = new SchematicEngine(engineHost);
const collection = engine.createCollection(collectionName);
logger.info(engine.listSchematicNames(collection).join('\n'));
const collection = workflow.engine.createCollection(collectionName);
logger.info(collection.listSchematicNames().join('\n'));
} catch (error) {
logger.fatal(error.message);
@ -140,19 +137,9 @@ export async function main({
collection: collectionName,
schematic: schematicName,
} = parseSchematicName(argv._.shift() || null);
const isLocalCollection = collectionName.startsWith('.') || collectionName.startsWith('/');
/** If the user wants to list schematics, we simply show all the schematic names. */
if (argv['list-schematics']) {
return _listSchematics(collectionName, logger);
}
if (!schematicName) {
logger.info(getUsage());
return 1;
}
/** Gather the arguments for later use. */
const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug;
const dryRun: boolean = argv['dry-run'] === null ? debug : argv['dry-run'];
@ -171,6 +158,17 @@ export async function main({
resolvePaths: [process.cwd(), __dirname],
});
/** If the user wants to list schematics, we simply show all the schematic names. */
if (argv['list-schematics']) {
return _listSchematics(workflow, collectionName, logger);
}
if (!schematicName) {
logger.info(getUsage());
return 1;
}
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
workflow.engineHost.registerOptionsTransform(validateOptionsWithSchema(registry));