shipit-utils
Advanced tools
Comparing version 1.3.1 to 1.4.0
/** | ||
* Register a task from Grunt or Shipit instance. | ||
* If optional description argument is used, and taskrunner is grunt | ||
* pass along the description for the task. | ||
*/ | ||
module.exports = function registerTask(gruntOrShipit, name, task) { | ||
module.exports = function registerTask(gruntOrShipit, name, desc, task) { | ||
var shipitMethod = 'blTask'; | ||
@@ -10,19 +12,41 @@ | ||
if (gruntOrShipit.registerTask) { | ||
if (Array.isArray(task)) { | ||
return gruntOrShipit.registerTask(name, task); | ||
} | ||
if (typeof desc !== 'string') { | ||
if (Array.isArray(desc)) { | ||
return gruntOrShipit.registerTask(name, desc); | ||
} | ||
return gruntOrShipit.registerTask(name, function() { | ||
var done = this.async(); | ||
var promise = task(); | ||
return gruntOrShipit.registerTask(name, function() { | ||
var done = this.async(); | ||
var promise = desc(); | ||
if (promise && promise.nodeify) { | ||
promise.nodeify(done); | ||
} else { | ||
done(); | ||
if (promise && promise.nodeify) { | ||
promise.nodeify(done); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
} else { | ||
if (Array.isArray(task)) { | ||
return gruntOrShipit.registerTask(name, desc, task); | ||
} | ||
}); | ||
return gruntOrShipit.registerTask(name, desc, function() { | ||
var done = this.async(); | ||
var promise = task(); | ||
if (promise && promise.nodeify) { | ||
promise.nodeify(done); | ||
} else { | ||
done(); | ||
} | ||
}); | ||
} | ||
} | ||
return gruntOrShipit[shipitMethod](name, task); | ||
}; | ||
// Manage calls not using description | ||
if (typeof desc !== 'string') { | ||
return gruntOrShipit[shipitMethod](name, desc); | ||
} else { | ||
return gruntOrShipit[shipitMethod](name, task); | ||
} | ||
}; |
{ | ||
"name": "shipit-utils", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "lodash": "^3.5.0" |
@@ -25,5 +25,7 @@ # shipit-utils | ||
### utils.registerTask(gruntOrShipit, name, task) | ||
### utils.registerTask(gruntOrShipit, name, [description,] task) | ||
Register a task, regardless of your context (Grunt or Shipit). | ||
The description arguement is optional, and will only try to pass along a task description if you are using Grunt (it will be ignored if you are using Shipit). | ||
##### task `Fn`|`Array<String>` | ||
@@ -30,0 +32,0 @@ Task function or array of task names to run in order. *Note: If in a Grunt context and passing an array of task names, task will always be synchronous/blocking.* |
@@ -52,2 +52,14 @@ var sinon = require('sinon'); | ||
}); | ||
it('should optionally register a Grunt task with desc.', function(done) { | ||
utils.registerTask(grunt, 'test', 'something testy!', task); | ||
expect(grunt.task.exists('test')).to.equal(true); | ||
done(); | ||
}); | ||
it('should still register a Shipit task if there is a desc.', function(done) { | ||
utils.registerTask(shipit, 'test', 'something testy!', task); | ||
expect(shipit.hasTask('test')).to.equal(true); | ||
done(); | ||
}); | ||
}); | ||
@@ -54,0 +66,0 @@ |
6285
9
151
60