Git Product home page Git Product logo

vinyl-paths's Introduction

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 an async Node.js package.

Simply pass an async function such as del and this package will provide each path in the stream as the first argument.

Install

$ npm install vinyl-paths

Usage

// gulpfile.js
const gulp = require('gulp');
const stripDebug = require('gulp-strip-debug');
const del = require('del');
const vinylPaths = require('vinyl-paths');

// Log file paths in the stream
gulp.task('log', =>
	gulp.src('app/*')
		.pipe(stripDebug())
		.pipe(vinylPaths(async paths => {
			console.log('Paths:', paths);
		})
);

// Delete files in the stream
gulp.task('delete', =>
	gulp.src('app/*')
		.pipe(stripDebug())
		.pipe(vinylPaths(del))
);

// Or if you need to use the paths after the pipeline
gulp.task('delete2', =>
	new Promise(function (resolve, reject) {
		const vp = vinylPaths();

		gulp.src('app/*')
			.pipe(vp)
			.pipe(gulp.dest('dist'))
			.on('end', async () => {
				try {
					await del(vp.paths);
					resolve();
				} catch (error) {
					reject(error);
				}
			});
	})
);

You should only use a vanilla Node.js package 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 optional callback will receive 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

vinyl-paths's People

Contributors

sindresorhus avatar jonatanlinden avatar wbinnssmith avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.