【问题标题】:“bash read command” in nodejsnodejs中的“bash读取命令”
【发布时间】:2017-04-11 19:15:57
【问题描述】:

我想用我擅长的 nodejs 编写一个 git hook 脚本。在 bash 文件中,我可以得到这样的参数:

#!/bin/bash read local_ref local_sha remote_ref remote_sha

nodejs中有没有相同的命令?

#!/usr/bin/env node "bash read function in nodejs"

【问题讨论】:

  • 搜索“nodejs 用户输入”会返回许多选项
  • @Adil 我试过了,但是参数的值是空的。
  • 确实通过了正确的git路径
  • :( node-cmd 为我工作,你可以试试 simple-git

标签: node.js git githooks


【解决方案1】:

这里有一些模块可以帮助你编写命令

节点命令

简单的命令行/终端界面,让您可以像在终端中一样运行 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-16
    • 1970-01-01
    • 2017-11-21
    • 2023-01-31
    • 1970-01-01
    • 2011-12-02
    • 2020-02-02
    • 1970-01-01
    相关资源
    最近更新 更多