Skip to content

Instantly share code, notes, and snippets.

@wiky
Last active August 29, 2015 13:57
Show Gist options
  • Save wiky/9679831 to your computer and use it in GitHub Desktop.
Save wiky/9679831 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
path = require('path'),
TianmaCmd = require('./tianma-cmd'),
doc = window.document,
workdir = doc.getElementById('workdir'),
tianma = TianmaCmd();
workdir.addEventListener('change', function(evt) {
var dir = this.value,
configArr = [];
fs.readdir(dir, function(err, files) {
files.forEach(function(file, i) {
if (fs.statSync(path.join(dir, file)).isFile()) {
if (path.extname(file) == '.js') {
configArr.push(file);
}
}
});
console.log(configArr);
});
}, false);
tianma.start('config.js', function() {
console.log(arguments);
});
<html>
<head>
<title>tianmaGUI</title>
</head>
<body>
<script type="text/javascript">
require('./app.js');
</script>
</body>
</html>
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