1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00
Lidarr/gulp/handlebars.js
2015-02-14 19:14:58 +01:00

52 lines
1.6 KiB
JavaScript

var gulp = require('gulp');
var handlebars = require('gulp-handlebars');
var declare = require('gulp-declare');
var concat = require('gulp-concat');
var wrap = require("gulp-wrap");
var path = require('path');
var streamqueue = require('streamqueue');
var stripbom = require('gulp-stripbom');
var paths = require('./paths.js');
gulp.task('handlebars', function () {
var coreStream = gulp.src([paths.src.templates, '!*/**/*Partial.*'])
.pipe(stripbom({ showLog: false }))
.pipe(handlebars())
.pipe(declare({
namespace: 'T',
noRedeclare: true,
processName: function (filePath) {
filePath = path.relative(paths.src.root, filePath);
return filePath.replace(/\\/g, '/')
.toLocaleLowerCase()
.replace('template', '')
.replace('.js', '');
}
}));
var partialStream = gulp.src([paths.src.partials])
.pipe(stripbom({ showLog: false }))
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, <%= contents %>)', {}, {
imports: {
processPartialName: function (fileName) {
return JSON.stringify(
path.basename(fileName, '.js')
);
}
}
}));
return streamqueue({ objectMode: true },
partialStream,
coreStream
).pipe(concat('templates.js'))
.pipe(gulp.dest(paths.dest.root));
});