Skip to content

Commit

Permalink
fix(@angular-devkit/schematics-cli): inconsistency in referencing col…
Browse files Browse the repository at this point in the history
…lection

Fixes #12600
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Oct 23, 2018
1 parent 39b6300 commit 0b4f3c1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/angular_devkit/schematics_cli/bin/schematics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import {
SchematicEngine,
UnsuccessfulWorkflowExecution,
} from '@angular-devkit/schematics';
import {
FileSystemEngineHost,
NodeModulesEngineHost,
NodeWorkflow,
} from '@angular-devkit/schematics/tools';
import { NodeModulesEngineHost, NodeWorkflow } from '@angular-devkit/schematics/tools';
import * as minimist from 'minimist';


Expand Down Expand Up @@ -73,7 +69,6 @@ export async function main({

/** Create the DevKit Logger used through the CLI. */
const logger = createConsoleLogger(argv['verbose'], stdout, stderr);

if (argv.help) {
logger.info(getUsage());

Expand All @@ -87,16 +82,18 @@ export async function main({
} = 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']) {
const engineHost = isLocalCollection
? new FileSystemEngineHost(normalize(process.cwd()))
: new NodeModulesEngineHost();

const engine = new SchematicEngine(engineHost);
const collection = engine.createCollection(collectionName);
logger.info(engine.listSchematicNames(collection).join('\n'));
try {
const engineHost = new NodeModulesEngineHost();
const engine = new SchematicEngine(engineHost);
const collection = engine.createCollection(collectionName);
logger.info(engine.listSchematicNames(collection).join('\n'));
} catch (error) {
logger.fatal(error.message);

return 1;
}

return 0;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/legacy-cli/e2e/tests/schematics_cli/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as path from 'path';
import { getGlobalVariable } from '../../utils/env';
import { exec, execAndWaitForOutputToMatch, silentNpm } from '../../utils/process';

const packages = require('../../../../../lib/packages').packages;

export default async function () {
// setup
const argv = getGlobalVariable('argv');
if (argv.noglobal) {
return;
}

const startCwd = process.cwd();
await silentNpm('install', '-g', packages['@angular-devkit/schematics-cli'].tar, '--unsafe-perm');
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');

// create blank schematic
await exec('schematics', 'schematic', '--name', 'test-schematic');

process.chdir(path.join(startCwd, 'test-schematic'));
await execAndWaitForOutputToMatch(
'schematics',
['.:', '--list-schematics'],
/my-full-schematic/,
);

// restore path
process.chdir(startCwd);

}

0 comments on commit 0b4f3c1

Please sign in to comment.