Skip to content

Commit

Permalink
fix(@angular-devkit/schematics-cli): fix list-schematics is not pri…
Browse files Browse the repository at this point in the history
…nting anything

Usage:
```
$  schematics @schematics/angular: --list-schematics
$  schematics --list-schematics
```

When no colon is specified, it means that that you are passing a schematic name to be looked up in the default collection.

Closes #12220
  • Loading branch information
alan-agius4 authored and hansl committed Sep 18, 2018
1 parent 84533e2 commit 8fac6a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/angular_devkit/schematics/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class SchematicEngine<CollectionT extends object, SchematicT extends obje
}

// remove duplicates
return [...new Set(names)];
return [...new Set(names)].sort();
}

transformOptions<OptionT extends object, ResultT extends object>(
Expand Down
51 changes: 33 additions & 18 deletions packages/angular_devkit/schematics_cli/bin/schematics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ import {
virtualFs,
} from '@angular-devkit/core';
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
import { DryRunEvent, UnsuccessfulWorkflowExecution } from '@angular-devkit/schematics';
import { NodeWorkflow } from '@angular-devkit/schematics/tools';
import {
DryRunEvent,
SchematicEngine,
UnsuccessfulWorkflowExecution,
} from '@angular-devkit/schematics';
import {
FileSystemEngineHost,
NodeModulesEngineHost,
NodeWorkflow,
} from '@angular-devkit/schematics/tools';
import * as minimist from 'minimist';


Expand All @@ -36,21 +44,26 @@ function usage(exitCode = 0): never {
Options:
--debug Debug mode. This is true by default if the collection is a relative
path (in that case, turn off with --debug=false).
--allowPrivate Allow private schematics to be run from the command line. Default to
false.
--dry-run Do not output anything, but instead just show what actions would be
performed. Default to true if debug is also true.
--force Force overwriting files that would otherwise be an error.
--list-schematics List all schematics from the collection, by name.
--list-schematics List all schematics from the collection, by name. A collection name
should be suffixed by a colon. Example: '@schematics/schematics:'.
--verbose Show more information.
--help Show this message.
Any additional option is passed to the Schematics depending on
`);

process.exit(exitCode);
throw 0; // The node typing sometimes don't have a never type for process.exit().
return process.exit(exitCode);
}


Expand All @@ -68,20 +81,12 @@ function usage(exitCode = 0): never {
* @param str The argument to parse.
* @return {{collection: string, schematic: (string)}}
*/
function parseSchematicName(str: string | null): { collection: string, schematic: string } {
function parseSchematicName(str: string | null): { collection: string, schematic: string | null} {
let collection = '@schematics/schematics';

if (!str || str === null) {
usage(1);
}

let schematic: string = str as string;
if (schematic.indexOf(':') != -1) {
let schematic = str;
if (schematic && schematic.indexOf(':') != -1) {
[collection, schematic] = schematic.split(':', 2);

if (!schematic) {
usage(2);
}
}

return { collection, schematic };
Expand Down Expand Up @@ -124,11 +129,21 @@ const isLocalCollection = collectionName.startsWith('.') || collectionName.start

/** If the user wants to list schematics, we simply show all the schematic names. */
if (argv['list-schematics']) {
// logger.info(engine.listSchematicNames(collection).join('\n'));
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'));

process.exit(0);
throw 0; // TypeScript doesn't know that process.exit() never returns.
}

if (!schematicName) {
usage(1);
throw 0; // TypeScript doesn't know that process.exit() never returns.
}

/** Gather the arguments for later use. */
const debug: boolean = argv.debug === null ? isLocalCollection : argv.debug;
Expand Down

0 comments on commit 8fac6a7

Please sign in to comment.