1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-14 23:13:24 +01:00
Radarr/gulp/handlebars.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-08-28 23:40:18 +02:00
var gulp = require('gulp');
var handlebars = require('gulp-handlebars');
var declare = require('gulp-declare');
var concat = require('gulp-concat');
var wrap = require("gulp-wrap");
2015-07-22 04:38:46 +02:00
var livereload = require('gulp-livereload');
2014-08-28 23:40:18 +02:00
var path = require('path');
var streamqueue = require('streamqueue');
2015-02-14 19:07:59 +01:00
var stripbom = require('gulp-stripbom');
2014-08-28 23:40:18 +02:00
var paths = require('./paths.js');
2015-07-22 04:42:38 +02:00
gulp.task('handlebars', function() {
2014-08-28 23:40:18 +02:00
2015-07-22 04:42:38 +02:00
var coreStream = gulp.src([
paths.src.templates,
'!*/**/*Partial.*'
])
.pipe(stripbom({ showLog : false }))
2014-08-28 23:40:18 +02:00
.pipe(handlebars())
.pipe(declare({
2015-07-22 04:42:38 +02:00
namespace : 'T',
noRedeclare : true,
processName : function(filePath) {
2014-08-28 23:40:18 +02:00
filePath = path.relative(paths.src.root, filePath);
return filePath.replace(/\\/g, '/')
.toLocaleLowerCase()
.replace('template', '')
.replace('.js', '');
}
}));
var partialStream = gulp.src([paths.src.partials])
2015-07-22 04:42:38 +02:00
.pipe(stripbom({ showLog : false }))
2014-08-28 23:40:18 +02:00
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(wrap('Handlebars.registerPartial(<%= processPartialName(file.relative) %>, <%= contents %>)', {}, {
2015-07-22 04:42:38 +02:00
imports : {
processPartialName : function(fileName) {
2014-08-28 23:40:18 +02:00
return JSON.stringify(
path.basename(fileName, '.js')
);
}
}
}));
2015-07-22 04:42:38 +02:00
return streamqueue({ objectMode : true },
2014-08-28 23:40:18 +02:00
partialStream,
coreStream
).pipe(concat('templates.js'))
2015-07-22 04:38:46 +02:00
.pipe(gulp.dest(paths.dest.root))
.pipe(livereload());
2014-08-28 23:40:18 +02:00
});