在下面的代码中,我的make
任务调用了一个javascript函数buildTemplate
,我将JSON对象传递给它。但是,理想情况下,我想用build-template
任务替换此函数,我将该对象传递给它。这可能吗?另外,添加javascript函数来补充gulp文件,就像我认为这样做了不好的做法?
var gulp = require('gulp');
// Include Plugins
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var templates = require('./config/templates.json');
// Watch Files for Changes
gulp.task('watch', function() {
gulp.watch('./input/structure/*/*.liquid', ['make']);
});
gulp.task('make', function() {
// get a list of all templates (pull from config file)
for (var i = 0; i < templates.length; i++) {
var template = templates[i];
buildTemplate(template);
};
});
// Default Task
gulp.task('default', [
'make',
'watch'
]);
// Helper Function
function buildTemplate(template) {
var template_title = template['title'];
gulp.src(
[
'./input/structure/snippets/header.liquid',
'./input/structure/templates/' + template_title + '.liquid',
'./input/structure/snippets/footer.liquid'
])
.pipe(concat(template_title + '.html'))
.pipe(gulp.dest('./output/')
);
};