gulp-data icon indicating copy to clipboard operation
gulp-data copied to clipboard

gulp-data not throwing errors (with gulp-jade)

Open marcobarbosa opened this issue 9 years ago • 2 comments

Hi,

I'm having issues where the gulp-data plugin is not giving me compilation errors.

Please see my compile-jade task below.

'use strict';

var path = require('path');

module.exports = function(gulp, plugins, config, browserSync) {
    return function() {
        var jadeParams = {
            pretty: true,
            compileDebug: true
        };
        gulp.src(config.templatesSource, { base: './src' })
            .pipe(plugins.data(function(file) {
                try {
                    return require( path.resolve( '.', config.dataFile ) );
                } catch (e) {
                    return plugins.util.log(plugins.util.colors.magenta('jade error'), e);
                }
            }))
            .pipe(plugins.jade(jadeParams))
            .pipe(gulp.dest(config.outputDistDir))
            .pipe(browserSync.stream());
    };
};

If I run gulp compile-jade I simply get the "task finished" in the terminal. Running jade <template> manually in the terminal gives me the syntax error that I want.

If I remove the plugins.data pipe part, then running gulp compile-jade again will give me the correct syntax errors. So I'm wondering, what is wrong with the require above? Why is it making jade not give me errors?

Everything will work fine without any syntax error (including the data being passed).

Can you spot any errors with this approach?

marcobarbosa avatar Oct 28 '15 13:10 marcobarbosa

Hi,

I have similar problem with 'gulp-compile-handlebars'

return gulp.src(hbsWild)
        .pipe(data(function(file) {
            var fileObject = path.parse(file.path);
            var filePath = fileObject.dir + '/' + fileObject.name + '.json';
            return (fs.existsSync(filePath)) ? require(filePath) : {};
        }))
        .pipe(handlebars(templateData, options))
        .pipe(rename({extname: ".html"}))
        .pipe(gulp.dest('src'));

Removing data plugin will get it work as expected.

taurni avatar Nov 10 '15 06:11 taurni

I'll play around with this tonight. Sorry for the delay.

colynb avatar Nov 30 '15 17:11 colynb