1.0.1 • Published 6 years ago

vinyl-filter-by-file v1.0.1

Weekly downloads
2
License
GPL-3.0
Repository
github
Last release
6 years ago

vinyl-filter-by-file Build Status Code Coverage Dependency Status

Filter a vinyl stream (like gulp’s) based on .gitignore-like files.

Install this module using npm:

npm install --save-dev vinyl-filter-by-file

Usage with gulp

This plugin can be used to filter a stream in gulp:

const gulp = require('gulp');
const ignorefilter = require('vinyl-filter-by-file');

gulp.task('staticassets', () =>
    gulp.src('**', {read: false})
        .pipe(ignorefilter())
        .pipe(gulp.dest('dist'))
);

Options

The plugin exports one function, which returns a stream.Duplex that can be piped into a vinyl stream.Readable. The function takes an options object as only parameter. The options are:

namedescriptiontypedefault
filenamename of ignore filesstring or array of strings'.ignore'
maxParenthighest folder to traverse up to when looking for ignore files. Paths are resolved against process.cwd()path or a function vinylobject => pathfile => file.base
excludeIgnoreFilewhether to filter the ignore files from the streambooleantrue

Example with Options

const gulp = require('gulp');
const ignorefilter = require('vinyl-filter-by-file');

gulp.task('staticassets', () =>
    gulp.src('**', {read: false})
        .pipe(ignorefilter({
            filename: '.gitignore',
            excludeIgnoreFile: false,
            maxParent: '.'
        }))
        .pipe(gulp.dest('dist'))

If ./.gitignore looks for example like this:

/node_modules/
/dist/

the resulting stream will for example include src/index.js, .gitignore, but not node_modules/vinyl-filter-by-file/build/index.js.