Reputation: 6882
I wanna write a git hook scripts with nodejs which I'm good at. In bash files, I can get params like this:
#!/bin/bash
read local_ref local_sha remote_ref remote_sha
Is there any same command in nodejs?
#!/usr/bin/env node
"bash read function in nodejs"
Upvotes: 1
Views: 537
Reputation: 59936
here are some module which help u to write command
node-cmd
Simple commandline/terminal interface to allow you to run cli or bash style commands as if you were in the terminal.
shelljs
ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts!
https://www.npmjs.com/package/node-cmd
https://www.npmjs.com/package/shelljs
have a look at this code may help u
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
Upvotes: 2