1、execa
进程管理
https://www.npmjs.com/package/execa
支持promise
2、shelljs
shell脚本
https://developer.aliyun.com/mirror/npm/package/shelljs
同步操作
3、listr
https://developer.aliyun.com/mirror/npm/package/listr
终端任务列表,可以同步,也支持异步。
示例代码:
const execa = require("execa");
const shell = require("shelljs");
const Listr = require("listr");
console.log('===execa示例开始===')
execa("ls").then(result => console.log(result.stdout, '===execa==='));
console.log('===execa示例结束===')
console.log('===shelljs示例开始===')
shell.ls('*.js').forEach(function (file) {
console.log(file, '===shelljs===')
});
console.log('===shelljs示例结束===')
console.log('===Listr示例开始===')
new Listr([
{
title: "Running npm install",
task: () => execa("cnpm", ["install"])
}
]).run();
console.log('===Listr示例结束===')
效果: