【发布时间】:2015-02-06 02:23:38
【问题描述】:
我正在尝试将 jekyll build 作为 gulp 文件中的节点子进程运行。问题是jekyll build 似乎运行了多次并且永远不会关闭。
我唯一能想到的可能是jekyll build 进程修改了markdown 文件,这会导致gulp.watch 再次运行。不过,我没有看到任何证据。
如果我只是从终端运行jekyll build,我会得到:
Configuration file: /home/user_name/projects/project_name/_config.yml
Source: /home/user_name/projects/project_name
Destination: /home/user_name/projects/project_name/_site
Generating...
done.
Auto-regeneration: disabled. Use --watch to enable.
当我将它作为节点子进程运行时,我得到:
[20:59:03] Configuration file: /home/user_name/projects/project_name/_config.yml
Source: /home/user_name/projects/project_name
Destination: /home/user_name/projects/project_name/_site
Generating...
[20:59:03] Configuration file: /home/user_name/projects/project_name/_config.yml
Source: /home/user_name/projects/project_name
Destination: /home/user_name/projects/project_name/_site
Generating...
[20:59:03] Configuration file: /home/user_name/projects/project_name/_config.yml
Source: /home/user_name/projects/project_name
Destination: /home/user_name/projects/project_name/_site
Generating...
它会像这样重复 20 多次然后就停止并且在那之后不输出任何东西。
这是我的 gulpfile.js:
var gulp = require('gulp');
var spawn = require('child_process').spawn;
var gutil = require('gulp-util');
gulp.task('default', function () {
gulp.watch('**/*.md', function (e) {
var cp = spawn('jekyll', ['build']),
stdout = '',
stderr = '';
cp.stdout.setEncoding('utf8');
cp.stdout.on('data', function (data) {
stdout += data;
gutil.log(data);
});
cp.stderr.setEncoding('utf8');
cp.stderr.on('data', function (data) {
stderr += data;
gutil.log(gutil.colors.red(data));
});
cp.on('error', function (err) {
gutil.log(gutil.colors.red('gulp-jekyll', err));
});
cp.on('close', function (code) {
gutil.log('Done with exit code ', code);
gutil.log('Jekyll has completed the build process.');
});
});
});
【问题讨论】:
标签: node.js jekyll gulp child-process