这里有一些模块可以帮助你编写命令
节点命令
简单的命令行/终端界面,让您可以像在终端中一样运行 cli 或 bash 风格的命令。
shelljs
ShellJS 是基于 Node.js API 的 Unix shell 命令的可移植(Windows/Linux/OS X)实现。您可以使用它来消除您的 shell 脚本对 Unix 的依赖,同时仍保留其熟悉且强大的命令。你也可以全局安装它,这样你就可以从外部的 Node 项目中运行它——告别那些粗糙的 Bash 脚本!
https://www.npmjs.com/package/node-cmd
https://www.npmjs.com/package/shelljs
看看这段代码可能对你有帮助
var cmd=require('node-cmd');
cmd.get(
git clone https://github.com/RIAEvangelist/node-cmd.git
cd node-cmd
ls
,
function(data){
console.log('the node-cmd cloned dir contains these files :\n\n',data)
}
);
看看这个模块
// starting a new repo
require('simple-git')()
.init()
.add('./*')
.commit("first commit!")
.addRemote('origin', 'https://github.com/user/repo.git')
.push('origin', 'master');
// push with -u
require('simple-git')()
.add('./*')
.commit("first commit!")
.addRemote('origin', 'some-repo-url')
.push(['-u', 'origin', 'master'], function () {
// done.
});
https://www.npmjs.com/package/simple-git