gulp-run-task-if
v1.0.3
Published
Conditionally decide whether to run a gulp task or to skip it
Downloads
924
Maintainers
Readme
gulp-run-task-if
npm i gulp-run-task-if --save-dev
Usage
const taskIf = require('gulp-run-task-if');
const condition = false; // Add business logic...
gulp.task('task', taskIf(condition, () => (
gulp.src('src/*')
.pipe(...)
.pipe(gulp.dest('dist/'));
));
For example
const taskIf = require('gulp-run-task-if');
const condition = false; // Add your business logic...
gulp.task('conditionTask', taskIf(condition, () => (
gulp.src('src/*')
.pipe(...)
.pipe(gulp.dest('dist/'));
)));
gulp.task('regularTask', () => (
gulp.src('src/*')
.pipe(...)
.pipe(gulp.dest('dist/'));
));
gulp.task('default', gulp.series(
'conditionTask', // --> will be skiped.
'regularTask'
));
Will output in a console:
[08:00:00] Starting 'default'...
[08:00:00] Starting 'conditionTask'...
[08:00:00] Skipped task
[08:00:00] Finished 'conditionTask' after 9.80 ms
[08:00:00] Starting 'regularTask'...
[08:00:00] Finished 'regularTask' after 488 ms
[08:00:00] Finished 'default' after 497.80 ms
API
taskIf(condition, [name], fn)
With the name
const taskIf = require('gulp-run-task-if');
const condition = false; // Add your business logic...
gulp.task('conditionTask', taskIf(condition, 'conditionTask', () => (
gulp.src('src/*')
.pipe(...)
.pipe(gulp.dest('dist/'));
)));
gulp.task('regularTask', () => (
gulp.src('src/*')
.pipe(...)
.pipe(gulp.dest('dist/'));
));
gulp.task('default', gulp.series(
'conditionTask', // --> will be skiped.
'regularTask'
));
Will output in a console:
[08:00:00] Starting 'default'...
[08:00:00] Starting 'conditionTask'...
[08:00:00] Skipped 'conditionTask'
[08:00:00] Finished 'conditionTask' after 9.80 ms
[08:00:00] Starting 'regularTask'...
[08:00:00] Finished 'regularTask' after 488 ms
[08:00:00] Finished 'default' after 497.80 ms