After considering going down this route, I realized that adding custom tasks is not currently supported. So, instead of attempting that, I opted to create a straightforward schematic that encapsulates the method I intended to call and utilize the RunSchematicTask
. This approach addressed my issue and gave me a sense of security, even though it led to some extra boilerplate in the schematics directory.
To illustrate, here's the basic schematic:
export function simpleSchematic(options: any): Rule {
return async () => {
await someAsyncMethod(options);
}
}
And this is how I utilized it within the "parent" schematic:
export function parentSchematic(options: any): Rule {
return chain([
someRuleCreator(options),
(_tree: Tree, context: SchematicContext) => {
context.addTask(new RunSchematicTask('simple-schematic', {})
}
]);
}
It should be noted that I had to include the simple-schematic
entry in the collection.json
, although I omitted that detail from my example above.