npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

vinyl-paths

2.1.0 • Public • Published

vinyl-paths Build Status

Get the file paths in a vinyl stream

Useful when you need to use the file paths from a gulp pipeline in Promise-returning node module.

Simply pass a promise-returning function such as del and vinyl-paths will provide each path in the stream as the first argument.

Install

$ npm install --save vinyl-paths

Usage

// gulpfile.js
var gulp = require('gulp');
var stripDebug = require('gulp-strip-debug');
var del = require('del');
var vinylPaths = require('vinyl-paths');
 
// log file paths in the stream
gulp.task('log', function () {
    return gulp.src('app/*')
        .pipe(stripDebug())
        .pipe(vinylPaths(function (paths) {
            console.log('Paths:', paths);
            return Promise.resolve();
        }));
});
 
// delete files in the stream
gulp.task('delete', function () {
    return gulp.src('app/*')
        .pipe(stripDebug())
        .pipe(vinylPaths(del));
});
 
// or if you need to use the paths after the pipeline
gulp.task('delete2', function () {
    return new Promise(function (resolve, reject) {
        var vp = vinylPaths();
 
        gulp.src('app/*')
            .pipe(vp)
            .pipe(gulp.dest('dist'))
            .on('end', function () {
                del(vp.paths).then(resolve).catch(reject);
            });
    });
});

You should only use a vanilla node module like this if you're already using other plugins in the pipeline, otherwise just use the module directly as gulp.src is costly. Remember that gulp tasks can return Promises as well as streams!

API

vinylPaths([callback])

The optionally supplied callback will get a file path for every file and is expected to return a Promise. An array of the file paths so far is available as a paths property on the stream.

callback(path)

Related

License

MIT © Sindre Sorhus

install

npm i vinyl-paths

Downloadsweekly downloads

34,629

version

2.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability