forked from jaredly/hexo-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
31 lines (26 loc) · 954 Bytes
/
generate.js
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
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, done) {
done = once(done);
var generateCommand = config.admin && config.admin.generateCommand ? config.admin.generateCommand.split(' ') : [];
var command = generateCommand.length > 0 ? generateCommand[0] : 'hexo';
generateCommand.shift();
var options = generateCommand.length > 0 ? generateCommand : ['generate'];
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});
});
}