node.js - Node.js 中的 “bash read command”

标签 node.js git githooks

我想用我擅长的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. 
     });

https://www.npmjs.com/package/simple-git

关于node.js - Node.js 中的 “bash read command”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40837990/

相关文章:

Git 后提交 : skip --amend and rebase

git - 如何使 "nohup ./script.sh & disown"在 post-receive git hook 中工作?

Node.js 如何创建只能由 SNS 主题访问的 API 端点?

git - 将 Git bash 作为外部工具嵌入 PyCharm 并在 PyCharm 窗口 (windows xp) 中使用它

javascript - Node.js:查询聚合不起作用(mongodb)

Git 开发工作流程

git - 一个接一个地单独推送一个分支的所有提交

git - 当我 'git push' 时,git 钩子(Hook)是否被推送到远程?

javascript - 如何使用sequelize获取用户角色?

javascript - 在 Node.JS 中将多个音频文件合并/合并为一个