From 32f8c985d03238a300f9c3b83131544b9f973e1a Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Tue, 31 Jul 2018 14:09:16 +0100 Subject: [PATCH] PCHR-4049: Fix tasks promises execution --- uk.co.compucorp.civicrm.hrcore/gulpfile.js | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/uk.co.compucorp.civicrm.hrcore/gulpfile.js b/uk.co.compucorp.civicrm.hrcore/gulpfile.js index 4542adefda1..d4ff4b6640c 100644 --- a/uk.co.compucorp.civicrm.hrcore/gulpfile.js +++ b/uk.co.compucorp.civicrm.hrcore/gulpfile.js @@ -5,21 +5,29 @@ var gulp = require('gulp'); var utils = require('./gulp/utils'); var tasks = getMainTasks(); +var watcherPromises = buildTaskPromises(['sass:watch', 'requirejs:watch', 'test:watch']); +var builderPromises = buildTaskPromises(['sass:watch', 'requirejs:watch', 'test:watch']); + _.each(tasks, function (fn, name) { gulp.task(name, fn); }); -gulp.task('watch', gulp.series( - utils.spawnTaskForExtension('sass:watch', tasks['sass:watch']), - utils.spawnTaskForExtension('requirejs:watch', tasks['requirejs:watch']), - utils.spawnTaskForExtension('test:watch', tasks['test:watch']) -)); +gulp.task('watch', gulp.series(watcherPromises)); +gulp.task('build', gulp.series(builderPromises)); -gulp.task('build', gulp.series( - utils.spawnTaskForExtension('sass', tasks['sass']), - utils.spawnTaskForExtension('requirejs', tasks['requirejs']), - utils.spawnTaskForExtension('test', tasks['test']) -)); +/** + * Builds extension tasks promises + * + * @param {Array} taskNames + * @return {Array} of task promises + */ +function buildTaskPromises (taskNames) { + return taskNames.map(function (taskName) { + return function () { + return utils.spawnTaskForExtension(taskName, tasks[taskName]); + }; + }); +} /** * Gets all the task listed in the files under the gulp/task folder