Skip to content

Instantly share code, notes, and snippets.

@wiky
Created March 20, 2014 16:58
Show Gist options
  • Save wiky/9668616 to your computer and use it in GitHub Desktop.
Save wiky/9668616 to your computer and use it in GitHub Desktop.
var exec = require('child_process').exec,
path = require('path');
var TianmaCmd = function(tianma, cwd) {
this.tianma = tianma || path.join(__dirname, '../node_modules/tianma/bin/tianma');
this.cwd = cwd || path.join(__dirname, '../node_modules/tianma/deploy');
};
TianmaCmd.prototype = {
_exec: function(cmd, callback) {
cmd = ['node', this.tianma, cmd].join(' ');
exec(cmd, {
cwd: this.cwd
}, function(err, info) {
if (err) {
console.error(err.message);
} else {
console.info(info);
}
});
},
start: function(config, callback) {
if (typeof config === 'function') {
callback = config;
config = null;
}
this._exec(['start', config || ''].join(' '), callback);
},
stop: function(callback) {
this._exec('stop', callback);
},
restart: function(callback) {
this._exec('restart', callback);
}
};
module.exports = function(tianma, cwd) {
return new TianmaCmd(tianma, cwd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment