gulp4-expression
v1.0.11
Published
combine gulp tasks using declarative expression
Downloads
2
Maintainers
Readme
Intro.
Gulp 4 empowers developers to write tasks and combine tasks (in series or in parallel) in an imperative fashion:
gulp4.task( 'A', done => {done();} );
gulp4.task( 'B', done => {done();} );
gulp4.task( 'C', done => {done();} );
gulp4.task('default', gulp4.series('A', gulp4.parallel('B', 'C')));
This npm package provides developers an interface to combine gulp tasks in a declarative way as an alternative, it also calculates the overall task completion when an individual task finishes.
gulp4.task('default', parseGulpExpression('A | B & C'));
Installation:
$ npm install gulp4-expression
Usage:
- series:
|
- parallel:
&
- sub-expression parentheses:
(...)
&
has a higher precedence than|
// gulpfile.js
const gulp4 = require('gulp4');
const parseGulpExpression = require('gulp4-expression').parseGulpExpression;
// Register tasks
gulp4.task( 'A', done => {console.log('A'); setTimeout(done, 500);} );
gulp4.task( 'B', done => {console.log('B'); done()} );
gulp4.task( 'C', done => {console.log('C'); done()} );
gulp4.task( 'D', done => {console.log('D'); done()} );
gulp4.task( 'E', done => {console.log('E'); done()} );
gulp4.task( 'F', done => {console.log('F'); done()} );
gulp4.task( 'G', done => {console.log('G'); done()} );
gulp4.task( 'H', done => {console.log('H'); done()} );
// Combine tasks
gulp4.task('default', parseGulpExpression(
'(A | B & C | D) & (E & F | G | H)'
));
$ gulp --tasks
# output
[14:56:13] └─┬ default
[14:56:13] └─┬ <parallel>
[14:56:13] ├─┬ <series>
[14:56:13] │ ├── A (GulpExpressionNodeTask-1)
[14:56:13] │ ├─┬ <parallel>
[14:56:13] │ │ ├── B (GulpExpressionNodeTask-2)
[14:56:13] │ │ └── C (GulpExpressionNodeTask-3)
[14:56:13] │ └── D (GulpExpressionNodeTask-4)
[14:56:13] └─┬ <series>
[14:56:13] ├─┬ <parallel>
[14:56:13] │ ├── E (GulpExpressionNodeTask-5)
[14:56:13] │ └── F (GulpExpressionNodeTask-6)
[14:56:13] ├── G (GulpExpressionNodeTask-7)
[14:56:13] └── H (GulpExpressionNodeTask-8)
$ gulp --silent
# output
A
E
[14:56:38] progress: 8%
F
[14:56:38] progress: 17%
G
[14:56:38] progress: 33%
H
[14:56:38] progress: 50%
[14:56:38] progress: 67%
B
[14:56:38] progress: 75%
C
[14:56:38] progress: 83%
D
[14:56:38] progress: 100%
$ gulp
# output
[16:36:14] Starting 'default'...
[16:36:14] Starting 'A (GulpExpressionNodeTask-1)'...
A
[16:36:14] Starting 'E (GulpExpressionNodeTask-5)'...
[16:36:14] Starting 'F (GulpExpressionNodeTask-6)'...
E
[16:36:14] Finished 'E (GulpExpressionNodeTask-5)' after 688 μs
[16:36:14] progress: 8%
F
[16:36:14] Finished 'F (GulpExpressionNodeTask-6)' after 1.56 ms
[16:36:14] progress: 17%
[16:36:14] Starting 'G (GulpExpressionNodeTask-7)'...
G
[16:36:14] Finished 'G (GulpExpressionNodeTask-7)' after 318 μs
[16:36:14] progress: 33%
[16:36:14] Starting 'H (GulpExpressionNodeTask-8)'...
H
[16:36:14] Finished 'H (GulpExpressionNodeTask-8)' after 289 μs
[16:36:14] progress: 50%
[16:36:14] Finished 'A (GulpExpressionNodeTask-1)' after 508 ms
[16:36:14] progress: 67%
[16:36:14] Starting 'B (GulpExpressionNodeTask-2)'...
[16:36:14] Starting 'C (GulpExpressionNodeTask-3)'...
B
[16:36:14] Finished 'B (GulpExpressionNodeTask-2)' after 689 μs
[16:36:14] progress: 75%
C
[16:36:14] Finished 'C (GulpExpressionNodeTask-3)' after 838 μs
[16:36:14] progress: 83%
[16:36:14] Starting 'D (GulpExpressionNodeTask-4)'...
D
[16:36:14] Finished 'D (GulpExpressionNodeTask-4)' after 409 μs
[16:36:14] progress: 100%
[16:36:14] Finished 'default' after 513 ms