lazd / gulp-declare

Safely declare namespaces and set their properties
MIT License
17 stars 3 forks source link

How to add extension along with filename in Declare? #10

Open imran5387 opened 8 years ago

imran5387 commented 8 years ago

My Gulp FIle is as shown below var handlebars=require('gulp-handlebars'); var handlebarSrc = config.appBasePath + '/js/templates/*/.hbss', handlebarDest = config.appBasePath + '/js/libs/iea/core/js/', handlebarDestFile = config.parentAppName + '.templates.js';

gulp.task('handlebars', function() { return gulp.src(handlebarSrc) .pipe(handlebars()) .pipe(wrap('Handlebars.template(<%= contents %>)')) .pipe(declare({ namespace: 'templates', noRedeclare: true, // Avoid duplicate declarations processName: function(filePath) { var a= filePath.split("\presentation\").pop(); //var a = String(filePath.replace('C:\xampp\htdocs\IEA-Test\presentation\', '')); /////entension was js somehow changing it to hbss below a = a.replace('.js', ".hbss"); return (a); } })) .pipe(concat(handlebarDestFile)) .pipe(wrap('define(["handlebars","helpers"], function(Handlebars) {<%= contents %>return this["templates"];});')) .pipe(gulp.dest(handlebarDest)); });

Directory structure :: js- templates- carousel- defaultView.hbss js-templates- form- defaultView.hbss js-templates-searchInput-defaultView.hbss ......................................-defaultView.hbss ... and so on

output template.js file WHAT I GET define(["handlebars","helpers"], function(Handlebars) { this["templates"] = this["templates"] || {}; this["templates"]["lib/js/templates/adaptive-image/defaultView"] = this["templates"]["lib/js/templates/adaptive-image/defaultView"] || {};

/////change needed here this["templates"]["lib/js/templates/adaptive-image/defaultView"]["hbss"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var stack1;

What I WANT::::

define(["handlebars","helpers"], function(Handlebars) { this["templates"] = this["templates"] || {};

this["templates"]["lib/js/templates/adaptive-image/defaultView.hbss"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var stack1;

Let me Know what is to be done in gulpfile handlebars to include extension in processName

xiaomingming commented 8 years ago

+1,i want move grunt-contrib-handlebars to gulp,but gulp-handlebars can't support it. Well,you can custom it's code:

// Default name processing function should give the filename without extension
var defaultProcessName = function(name) {
    var dirArr = path.dirname(name).split(path.sep);
    return dirArr[dirArr.length - 1] + '/' + path.basename(name, path.extname(name));
};