add and run task like schematics's NodePackageInstallTask
import { Rule } from '@angular-devkit/schematics';
type TaskFn = Rule;
TaskFn
has no difference with a normal Rule
.
addTask
, return aRule
, so you can use it like otherRule
generators.newTask
, task generate utility, then you can add the result tocontext.addTask
import { addTask } from 'schematics-task';
import { chain, Rule } from '@angular-devkit/schematics';
function foo(tree, context): Rule {
return chain([
// ...
addTask(async () => {
// Let's run a shell script
await execa('echo', ['hello', 'world'], {stdio: 'inherit'});
// do whatever you want
}),
]);
}
import { newTask } from 'schematics-task';
import { Tree, SchematicContext } from '@angular-devkit/schematics';
import execa from 'execa';
function foo(tree: Tree, context: SchematicContext) {
context.addTask(
newTask(async (_tree, _context) => {
// you can also use tree & context here
// Let's run a shell script
await execa('echo', ['hello', 'world'], {stdio: 'inherit'});
// do whatever you want
})
);
return tree;
}
MIT