Skip to content

Commit 3595ebb

Browse files
committed
fix(@angular-devkit/schematics): QoL changes for run-schematic
Allow private schematics to run on the RunSchematic task. Also allow 2 arguments to the constructor which will call a schematic from the same collection.
1 parent ca35adb commit 3595ebb

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

packages/angular_devkit/schematics/tasks/run-schematic/executor.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ import { SchematicContext, TaskExecutor } from '../../src';
99
import { RunSchematicTaskOptions } from './options';
1010

1111

12-
export default function(): TaskExecutor<RunSchematicTaskOptions> {
13-
return (options: RunSchematicTaskOptions, context: SchematicContext) => {
12+
export default function(): TaskExecutor<RunSchematicTaskOptions<{}>> {
13+
return (options: RunSchematicTaskOptions<{}>, context: SchematicContext) => {
1414
const maybeWorkflow = context.engine.workflow;
15+
const collection = options.collection || context.schematic.collection.description.name;
1516

1617
if (!maybeWorkflow) {
1718
throw new Error('Need Workflow to support executing schematics as post tasks.');
1819
}
1920

2021
return maybeWorkflow.execute({
21-
collection: options.collection,
22+
collection: collection,
2223
schematic: options.name,
2324
options: options.options,
25+
// Allow private when calling from the same collection.
26+
allowPrivate: collection == context.schematic.collection.description.name,
2427
});
2528
};
2629
}

packages/angular_devkit/schematics/tasks/run-schematic/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
export const RunSchematicName = 'run-schematic';
99

10-
export interface RunSchematicTaskOptions {
11-
collection: string;
10+
export interface RunSchematicTaskOptions<T> {
11+
collection: string | null;
1212
name: string;
13-
options: object;
13+
options: T;
1414
}

packages/angular_devkit/schematics/tasks/run-schematic/task.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,27 @@ import { TaskConfiguration, TaskConfigurationGenerator } from '../../src';
99
import { RunSchematicName, RunSchematicTaskOptions } from './options';
1010

1111

12-
export class RunSchematicTask implements TaskConfigurationGenerator<RunSchematicTaskOptions> {
13-
constructor(
14-
protected _collection: string,
15-
protected _schematic: string,
16-
protected _options: object,
17-
) {}
12+
export class RunSchematicTask<T> implements TaskConfigurationGenerator<RunSchematicTaskOptions<T>> {
13+
protected _collection: string | null;
14+
protected _schematic: string;
15+
protected _options: T;
1816

19-
toConfiguration(): TaskConfiguration<RunSchematicTaskOptions> {
17+
constructor(s: string, o: T);
18+
constructor(c: string, s: string, o: T);
19+
20+
constructor(c: string | null, s: string | T, o?: T) {
21+
if (arguments.length == 2 || typeof s !== 'string') {
22+
o = s as T;
23+
s = c as string;
24+
c = null;
25+
}
26+
27+
this._collection = c;
28+
this._schematic = s as string;
29+
this._options = o as T;
30+
}
31+
32+
toConfiguration(): TaskConfiguration<RunSchematicTaskOptions<T>> {
2033
return {
2134
name: RunSchematicName,
2235
options: {

0 commit comments

Comments
 (0)