Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The console is quite cluttered without break lines

--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