colynb / gulp-data

Generate a data object from a variety of sources: json, front-matter, database, anything... and set it to the file object for other plugins to consume.
http://colynb.com/gulp-data/
MIT License
189 stars 14 forks source link

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

Open marcobarbosa opened 9 years ago

marcobarbosa commented 9 years ago

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?

taurni commented 8 years ago

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.

colynb commented 8 years ago

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