Created
October 23, 2015 16:46
-
-
Save lkptrzk/1ae5ede0962ad5b0c1e1 to your computer and use it in GitHub Desktop.
nodejs script boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Async = require('async'); | |
exports.script = function () { | |
var options = internals.parseOptions(); | |
var context = { | |
options: options, | |
state: {}, | |
}; | |
var tasks = internals.tasks.map(function (task) { | |
return task.bind(context); | |
}); | |
Async.series(tasks, function (err, results) { | |
if (err) { | |
throw err; | |
} | |
process.exit(0); | |
}); | |
}; | |
var internals = exports._internals = { | |
tasks: [], | |
}; | |
internals.parseOptions = function () { | |
var options = {}; | |
return options; | |
}; | |
internals.tasks[0] = function (callback) { | |
var context = this; | |
console.log('task 0'); | |
return callback(null); | |
}; | |
internals.tasks[1] = function (callback) { | |
var context = this; | |
console.log('task 1'); | |
return callback(null); | |
}; | |
if (require.main === module) { | |
exports.script(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment