我想用我擅长的nodejs编写一个git hook脚本。在 bash 文件中,我可以获得如下参数:
#!/bin/bash
读取 local_ref local_sha 远程_ref 远程_sha
nodejs中有相同的命令吗?
#!/usr/bin/env Node
“nodejs中的bash读取函数”
最佳答案
这里有一些可以帮助你编写命令的模块
node-cmd
简单的命令行/终端界面,允许您像在终端中一样运行 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)
}
);
have look on this module
// 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.
});
关于node.js - Node.js 中的 “bash read command”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40837990/