gulp-promisify
Version:
Gulp flow control using async/await.
91 lines (65 loc) • 3.21 kB
Markdown
[![NPM version][npm-img]][npm-url] [![Downloads][downloads-img]][npm-url] [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Chat][gitter-img]][gitter-url] [![Tip][amazon-img]][amazon-url]
Enables use of Promises or ES7 async/await keywords to control the flow of Gulp 3 tasks. If using Gulp 4, you should use the `.serial()` and `.parallel()` methods instead of this module.
$ npm install --save-dev gulp-promisify
```js
import gulp from 'gulp';
import promisify from 'gulp-promisify';
import tape from 'gulp-tape';
import xo from 'gulp-xo';
promisify(gulp);
export function lint() {
return gulp
.src('*.js')
.pipe(xo());
}
export function test() {
return gulp
.src('test.js')
.pipe(tape());
}
export function testParallel() {
lint();
test();
}
export async function testSeries() {
await lint();
await test();
}
gulp.task('lint', lint);
gulp.task('test', test);
gulp.task('test:parallel', testParallel);
gulp.task('test:series', testSeries);
```
Causes streams returned by `.src()`, `.dest()`, and `.symlink()` to also be [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) objects with `.then()` and `.catch()` methods. The promise is resolved when the stream emits the [`'end'`](https://nodejs.org/api/stream.html#stream_event_end) event. This promisification propagates to all subsequent streams via `.pipe()` to ensure that you may await any following stream.
```js
gulp.src('*.js')
.pipe(somePlugin())
.pipe(anotherPlugin())
.pipe(yetAnotherPlugin()); // <- returns a promisified stream
```
[![Tasks][waffle-img]][waffle-url]
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
$ npm test
----
© 2016 Shannon Moeller <me@shannonmoeller.com>
Licensed under [MIT](http://shannonmoeller.com/mit.txt)
[]: https://img.shields.io/badge/amazon-tip_jar-yellow.svg?style=flat-square
[]: https://www.amazon.com/gp/registry/wishlist/1VQM9ID04YPC5?sort=universal-price
[]: http://img.shields.io/coveralls/shannonmoeller/gulp-promisify/master.svg?style=flat-square
[]: https://coveralls.io/r/shannonmoeller/gulp-promisify
[]: http://img.shields.io/npm/dm/gulp-promisify.svg?style=flat-square
[]: http://img.shields.io/badge/gitter-join_chat-1dce73.svg?style=flat-square
[]: https://gitter.im/shannonmoeller/shannonmoeller
[]: http://img.shields.io/npm/v/gulp-promisify.svg?style=flat-square
[]: https://npmjs.org/package/gulp-promisify
[]: http://img.shields.io/travis/shannonmoeller/gulp-promisify.svg?style=flat-square
[]: https://travis-ci.org/shannonmoeller/gulp-promisify
[]: http://img.shields.io/github/issues/shannonmoeller/gulp-promisify.svg?style=flat-square
[]: http://waffle.io/shannonmoeller/gulp-promisify