haoxins / gulp-file-include

MAINTAINER WANTED ~ [gulp-file-include] a gulp plugin for file include
MIT License
676 stars 95 forks source link

Including a suffix breaks filters #57

Open eneuhauser opened 9 years ago

eneuhauser commented 9 years ago

When I include a suffix and filters, I get the following error. This error occurs regardless if I apply the filter.

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Cannot read property '0' of null

For my case, I'm including a file inside JSON, so I wrap the file include inside quotes to make it valid JSON. Here's the snippet with the include:

{
    "definitions": {
        "post": "@@include(indent('post.def.json'))"
    }
}

My task looks like this:

gulp.task('schema', function() {
    return gulp.src(['**/*.schema.json'])
        .pipe(fileinclude({
            prefix: '"@@',
            suffix: '"',
            basepath: '@file',
            filters: {
                indent: indent
            }
        }))
        .pipe(gulp.dest('./dist/'));
});

If I comment out suffix, it works, but leaves a trailing quote. If I comment out the filters, it works, but doesn't apply the indent.

eneuhauser commented 9 years ago

Using gulp-replace, the following fixes the trailing quote until the suffix issue can be worked out.

gulp.task('schema', function() {
    return gulp.src(['**/*.schema.json'])
        .pipe(fileinclude({
            prefix: '"@@',
            //suffix: '"',
            basepath: '@file',
            filters: {
                indent: indent
            }
        }))
        .pipe(replace('}"', '}'))
        .pipe(gulp.dest('./dist/'));
});