I have a gulp task to precompile descriptor templates, consisting of the following:
gulp.src(['templates/*.hbs'])
.pipe(handlebars())
.pipe(declare({
namespace: 'Template.templates',
noRedeclare: true
}))
.pipe(concat('compiled.js'))
.pipe(header('Template = {};\nTemplate.render = function(templateName, context) { return Handlebars.template(Template.templates[templateName])(context) };\n'))
.pipe(gulp.dest('templates'));
I want to create a gulp plugin that wraps this functionality to make it easier to use, for example:
gulp.src(['templates/*.hbs'])
.pipe(handlebars2())
.dest('templates')
Or with options:
gulp.src(['templates/*.hbs'])
.pipe(handlebars2({
filename: 'compiled.js',
namespace: 'Template'
}))
.dest('templates')
The documentation for writing gulp plugins and the source code of the examples I looked at show only the use of threads, and I'm not sure how to apply this to using other gulp plugins inside my own.
How to write a gulp plugin to execute the functions handlebars2above?
Even if someone just points me in the right direction, I can solve it and post the solution as an answer to others. Thank!