Tasks are mod's bread and butter. The stuff you do most often, like min or cat. Every time Mod is run, you specify one or more tasks to run, which tells Mod what you'd like it to do.
In addition to the built-in tasks, you can create your own task:
exports.summary = 'my task';
exports.usage = '<source> [options]';
exports.options = {
"dest" : {
alias : 'd'
,default : '<source>'
,describe : 'destination file'
},
"charset" : {
alias : 'c'
,default : 'utf-8'
,describe : 'file encoding type'
}
};
exports.run = function (options, done) {
var target = options.target;
// ...
done();
};exports.usage = '<source> [options]';
exports.options = {
"dest" : {
alias : 'd'
,default : '<source>'
,describe : 'destination file'
},
"charset" : {
alias : 'c'
,default : 'utf-8'
,describe : 'file encoding type'
}
};
General task is asynchronous, how mod know task is run over? We use done callback.
When a asynchronous task is over, call the done() method.
exports.run = function (options, done) {
exec(function(){
// balabal...
done();
});
};If task is a synchronous, the done callback is optional:
exports.run = function (options) {
console.log('run done');
};Mod plugin API are provided directly on the exports object for convenience. See the individual api section docs for detailed explanations and examples.
exports.taskName
exports.files
exports.loadTask()
exports.runTask()
exports.config()
exports.log()
exports.error()
exports.warn()
exports.debug()
exports.file
exports.utils
exports._
exports.async
exports.request
exports.prompt- Author project's
package.json. - Run
npm publishto publish the mod plugin to npm