fie-task
fie 任务流模块,用于执行fie的任务流
安装
npm install fie-task --save
API
has(tasks, when)
是否存在当前时机的任务流
- tasks
{array}
任务列表 - when
{string}
时机
run(options)
Generator 函数
,执行一串任务流, 直接传一对应指令的任务流,并指定进行时机
- options
{object}
选项 - options.tasks
{array}
任务流数组, 如果需要传入函数,仅支持 generator 函数 - options.when
{string}
时机, before 或 after - options.args
{array}
如果任务流里面有函数,当组数为传给函数的参数 - options.command
{string}
当前正在运行的 fie 指令, 用于在控制台提示及对 $$ 参数进行替换
使用案例
const tasks = [{
command: 'echo "$$"'
}, {
* func(a, b) {
console.log(a, b);
}
}, {
command: '__toolkitCommand__'
}, {
comamnd: 'echo afterTask'
}];
// 调用前置任务
yield run({
tasks,
when: 'before',
args: ['aaa', 'bbb'],
command: 'test'
});
// 调用后置任务
yield run({
tasks,
when: 'after',
command: 'test'
});
假设命令行里面输入的是 fie test x -y z
, 那么上面的两次调用的输出结果分别是:
> x -y z
> aaa bbb
> afterTask
runFunction();
Generator 函数
,执行一个函数, 支持 generator 及普通函数
- options
{object}
- options.method
{function}
需要被执行的函数 - options.args
{array}
需要传给 method 的参数 - options.next
{function}
下一步执行方法, 如果 method 是普通函数会自动拼到 args 里面,传给 method, 如果 method 是 generator 函数或 promise 可以不传, 里面会执行完该函数后才退出 runFunction函数
执行普通函数
yield runFunction({
method(a, b, next) {
setTimeout(() => {
console.log(a, b);
next();
}, 10);
},
args: ['aaa', 'bbb'],
next() {
console.log('ccc');
}
});
// 执行结果
// > aaa bbb
// > ccc
执行 generator 函数
yield runFunction({
* method(a, b) {
return new Promise(resolve => {
setTimeout(() => {
console.log(a, b);
resolve();
}, 10);
});
},
args: ['aaa', 'bbb']
});
console.log('ccc');
// 执行结果
// > aaa bbb
// > ccc
Support
使用过程中遇到的相关问题,及BUG反馈,可联系: hugohua baofen14787@gmail.com ,也可直接提issues