多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[shelljs](https://www.npmjs.com/package/shelljs) 模块重新包装了 child_process,调用系统命令更加方便。它需要安装后使用。 ~~~ npm install --save shelljs ~~~ 然后,改写脚本。 ~~~ #!/usr/bin/env node var name = process.argv[2]; var shell = require("shelljs"); shell.exec("echo hello " + name); ~~~ 上面代码是 shelljs 的本地模式,即通过 exec 方法执行 shell 命令。此外还有全局模式,允许直接在脚本中写 shell 命令。 ~~~ require('shelljs/global'); if (!which('git')) { echo('Sorry, this script requires git'); exit(1); } mkdir('-p', 'out/Release'); cp('-R', 'stuff/*', 'out/Release'); cd('lib'); ls('*.js').forEach(function(file) { sed('-i', 'BUILD_VERSION', 'v0.1.2', file); sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file); sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file); }); cd('..'); if (exec('git commit -am "Auto-commit"').code !== 0) { echo('Error: Git commit failed'); exit(1); } ~~~