Skip to content

Commit

Permalink
Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
OverZealous committed Feb 8, 2014
1 parent 58f10e5 commit 0eada4d
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

"use strict";

var colors = require('chalk');
var gulp = require('gulp');
var gulp = require('gulp'),
colors = require('chalk');

var verifyTaskSets = function(taskSets, skipArrays) {
taskSets.forEach(function(t, i) {
function verifyTaskSets(taskSets, skipArrays) {
if(taskSets.length === 0) {
throw new Error('No tasks were provided to run-sequence');
}
taskSets.forEach(function(t) {
var isTask = typeof t === "string",
isArray = !skipArrays && Array.isArray(t);
if(!isTask && !isArray) {
Expand All @@ -21,13 +24,17 @@ var verifyTaskSets = function(taskSets, skipArrays) {
}
verifyTaskSets(t, true);
}
})
});
}

module.exports = function() {
var taskSets = Array.prototype.slice.call(arguments),
callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false,
function runSequence() {
var taskSets = Array.prototype.slice.call(arguments);

verifyTaskSets(taskSets);

var callBack = typeof taskSets[taskSets.length-1] === 'function' ? taskSets.pop() : false,
currentTaskSet,

finish = function(err) {
gulp.removeListener('task_stop', onTaskEnd);
gulp.removeListener('task_err', onError);
Expand All @@ -37,6 +44,7 @@ module.exports = function() {
console.log(colors.red('Error running task sequence:'), err);
}
},

onError = function(err) {
finish(err);
},
Expand All @@ -49,6 +57,7 @@ module.exports = function() {
runNextSet();
}
},

runNextSet = function() {
if(taskSets.length) {
var command = taskSets.shift();
Expand All @@ -62,14 +71,10 @@ module.exports = function() {
}
};

if(taskSets.length === 0) {
throw new Error('No tasks were provided to run-sequence');
}
verifyTaskSets(taskSets);

gulp.on('task_stop', onTaskEnd);
gulp.on('task_err', onError);

runNextSet();
};
}

module.exports = runSequence;

0 comments on commit 0eada4d

Please sign in to comment.