forked from jaredly/hexo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
36 lines (29 loc) · 1 KB
/
deploy.js
File metadata and controls
36 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var spawn = require('child_process').spawn
function once(fn) {
var called = false
return function () {
if (!called) fn.apply(this, arguments)
called = true
}
}
module.exports = function (config, message, done) {
var deployCommand = config.admin && config.admin.deployCommand ? config.admin.deployCommand.split(' ') : [];
var command = deployCommand.length > 0 ? deployCommand[0] : 'hexo';
generateCommand.shift();
var options = deployCommand.length > 0 ? deployCommand : ['deploy'];
if (message && message !== '') {
options.push('-m ' + message + '');
}
done = once(done);
var proc = spawn(command, options, {detached: true});
var stdout = '';
var stderr = '';
proc.stdout.on('data', function(data){ stdout += data.toString() });
proc.stderr.on('data', function(data){ stderr += data.toString() });
proc.on('error', function(err) {
done(err, {stdout: stdout, stderr: stderr});
});
proc.on('close', function () {
done(null, {stdout: stdout, stderr: stderr});
});
}