var exec = require('child_process').exec;
function _command (command, cb){
var child = exec(command, function(err, stdout, stderr){
if(err != null){
return cb(new Error(err), null);
}else if(typeof(stderr) != "string"){
return cb(new Error(stderr), null);
}else{
return cb(null, stdout);
}
});
}
async.series(
[
function (callback) {
_command("git clone git@git@github.com:request/request.git", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------CLONE DONE---------");
callback();
});
},
function (callback) {
_command("git branch new", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------BRANCH CREATED DONE---------");
callback();
});
},
function (callback) {
_command("git checkout new", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------CHECKOUT NEW BRANCH DONE---------");
callback();
});
},
function (callback) {
fs.writeFile('message.txt', 'Hello Node', function (err) {
if (err) throw err;
console.log("------------FILE CREATED DONE---------");
callback();
});
},
function (callback) {
_command("git add \"*\"", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------GIT ADD DONE---------");
callback();
});
},
function (callback) {
_command("git commit -m \"new branch\"", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------GIT COMMIT DONE---------");
callback();
});
},
function (callback) {
_command("git push origin master", function (err, response) {
if (err) {
return console.log("ERR: " + err);
}
console.log("------------GIT PUSH DONE---------");
callback();
});
}
],
function _allGood(err, results) {
if (err) {
console.log("-------------ERROR-------------")
}
else {
console.log("-------------ALL GOOD-------------")
}
}
);