UNPKG

gulp-kit-2

Version:

Integrates node-kit with gulp 4 to compile .kit files

49 lines (39 loc) 1.05 kB
var kit = require('node-kit'); var through2 = require('through2'); var replaceExt = require('replace-ext'); var PluginError = require('plugin-error'); var path = require('path'); var partialPrefix = '_'; function isPartial(filepath) { return path.basename(filepath)[0] === partialPrefix; } module.exports = function (options) { options = options || {}; function transform(file, enc, next) { var self = this; if (file.isNull()) { this.push(file); // pass along return next(); } if (isPartial(file.path) && !options.compilePartials) { return next(); } if (file.isStream()) { this.emit( 'error', new PluginError('gulp-kit', 'Streaming not supported') ); return next(); } try { var html = kit(file.path); file.contents = new Buffer(html); file.path = replaceExt(file.path, '.html'); self.push(file); } catch (e) { self.emit('error', new PluginError('gulp-kit', e)); } next(); } return through2.obj(transform); };