gulp-run-sequence
Advanced tools
Comparing version
85
index.js
@@ -6,48 +6,47 @@ /*jshint node:true */ | ||
var colors = require('chalk'); | ||
var gulp = require('gulp'); | ||
module.exports = function(gulp) { | ||
return function() { | ||
var taskSets = Array.prototype.slice.call(arguments), | ||
callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false, | ||
currentTaskSet, | ||
finish = function(err) { | ||
gulp.removeListener('task_stop', onTaskEnd); | ||
gulp.removeListener('task_err', onError); | ||
if(callBack) { | ||
callBack(err); | ||
} else if(err) { | ||
console.log(colors.red('Error running task sequence:'), err); | ||
module.exports = function() { | ||
var taskSets = Array.prototype.slice.call(arguments), | ||
callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false, | ||
currentTaskSet, | ||
finish = function(err) { | ||
gulp.removeListener('task_stop', onTaskEnd); | ||
gulp.removeListener('task_err', onError); | ||
if(callBack) { | ||
callBack(err); | ||
} else if(err) { | ||
console.log(colors.red('Error running task sequence:'), err); | ||
} | ||
}, | ||
onError = function(err) { | ||
finish(err); | ||
}, | ||
onTaskEnd = function(event) { | ||
var idx = currentTaskSet.indexOf(event.task); | ||
if(idx > -1) { | ||
currentTaskSet.splice(idx,1); | ||
} | ||
if(currentTaskSet.length === 0) { | ||
runNextSet(); | ||
} | ||
}, | ||
runNextSet = function() { | ||
if(taskSets.length) { | ||
var command = taskSets.shift(); | ||
if(!Array.isArray(command)) { | ||
command = [command]; | ||
} | ||
}, | ||
onError = function(err) { | ||
finish(err); | ||
}, | ||
onTaskEnd = function(event) { | ||
var idx = currentTaskSet.indexOf(event.task); | ||
if(idx > -1) { | ||
currentTaskSet.splice(idx,1); | ||
} | ||
if(currentTaskSet.length === 0) { | ||
runNextSet(); | ||
} | ||
}, | ||
runNextSet = function() { | ||
if(taskSets.length) { | ||
var command = taskSets.shift(); | ||
if(!Array.isArray(command)) { | ||
command = [command]; | ||
} | ||
currentTaskSet = command; | ||
gulp.run.apply(gulp, command); | ||
} else { | ||
finish(); | ||
} | ||
}; | ||
gulp.on('task_stop', onTaskEnd); | ||
gulp.on('task_err', onError); | ||
runNextSet(); | ||
}; | ||
currentTaskSet = command; | ||
gulp.run.apply(gulp, command); | ||
} else { | ||
finish(); | ||
} | ||
}; | ||
gulp.on('task_stop', onTaskEnd); | ||
gulp.on('task_err', onError); | ||
runNextSet(); | ||
}; | ||
{ | ||
"name": "gulp-run-sequence", | ||
"description": "Run a series of dependent gulp tasks in order", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/OverZealous/gulp-run-sequence", | ||
@@ -36,3 +36,3 @@ "repository": { | ||
], | ||
"readme": "\n\ngulp-run-sequence\n=======\n\nRuns a sequence of gulp tasks in the specified order. This function is designed to solve the situation where you have defined run-order, but choose not to or cannot use dependencies.\n\nYou can still run some of the tasks in parallel, by providing an array of task names.\n\nIf the final argument is a function, it will be used as a callback after all the functions are either finished or an error has occurred.\n\nUsage\n-----\n\nYou must call the exported function with your gulp instance.\n\n```javascript\nvar gulp = require('gulp');\nvar runSequence = require('gulp-run-sequence')(gulp);\nvar clean = require('gulp-clean');\n\ngulp.task('build', function(cb) {\n runSequence('build-clean', ['build-scripts', 'build-styles'], 'build-html', cb);\n});\n\n// configure build-clean, build-scripts, build-styles, build-html as you\n// wish, but make sure they either return a stream or handle the callback\n\ngulp.task('build-clean', function() {\n\treturn gulp.src('build').pipe(clean());\n});\n\n```\n\nLICENSE\n-------\n\n(MIT License)\n\nCopyright (c) 2014 [Phil DeJarnett](http://overzealous.com)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", | ||
"readme": "\n\ngulp-run-sequence\n=======\n\nRuns a sequence of gulp tasks in the specified order. This function is designed to solve the situation where you have defined run-order, but choose not to or cannot use dependencies.\n\nYou can still run some of the tasks in parallel, by providing an array of task names.\n\nIf the final argument is a function, it will be used as a callback after all the functions are either finished or an error has occurred.\n\nUsage\n-----\n\n```javascript\nvar gulp = require('gulp');\nvar runSequence = require('gulp-run-sequence');\nvar clean = require('gulp-clean');\n\ngulp.task('build', function(cb) {\n runSequence('build-clean', ['build-scripts', 'build-styles'], 'build-html', cb);\n});\n\n// configure build-clean, build-scripts, build-styles, build-html as you\n// wish, but make sure they either return a stream or handle the callback\n// Example:\n\ngulp.task('build-clean', function() {\n\treturn gulp.src('build').pipe(clean());\n});\n\n```\n\nLICENSE\n-------\n\n(MIT License)\n\nCopyright (c) 2014 [Phil DeJarnett](http://overzealous.com)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", | ||
"readmeFilename": "README.md", | ||
@@ -42,4 +42,4 @@ "bugs": { | ||
}, | ||
"_id": "gulp-run-sequence@0.2.0", | ||
"_id": "gulp-run-sequence@0.3.0", | ||
"_from": "gulp-run-sequence@*" | ||
} |
@@ -15,7 +15,5 @@  | ||
You must call the exported function with your gulp instance. | ||
```javascript | ||
var gulp = require('gulp'); | ||
var runSequence = require('gulp-run-sequence')(gulp); | ||
var runSequence = require('gulp-run-sequence'); | ||
var clean = require('gulp-clean'); | ||
@@ -29,2 +27,3 @@ | ||
// wish, but make sure they either return a stream or handle the callback | ||
// Example: | ||
@@ -31,0 +30,0 @@ gulp.task('build-clean', function() { |
7800
-1.97%45
-2.17%59
-1.67%