1.2.4 • Published 9 years ago
initialize-engine v1.2.4
initialize-engine
Code generation engine. Inspired by the work in mattdesl/quick-stub.
Installation
$ npm install initialize-engine
Usage
const initializeEngine = require('initialize-engine')
const mkdirp = require('mkdirp')
const path = require('path')
initializeEngine({
pre: [ createDir ],
files: [
'.gitignore',
'LICENSE',
'README.md',
'index.js',
'package.json',
],
devDependencies: [ 'istanbul', 'standard', 'tape' ]
}, { d: '../foobar' })
// create specified path
// (obj, fn) -> null
function createDir (argv, next) {
const loc = path.resolve(path.join(argv.d, argv.name))
mkdirp(loc, function (err) {
if (err) return next(err)
process.chdir(loc)
argv.directory = loc
argv.d = loc
next()
})
}
API
initializeEngine(opts, argv)
Run the engine with the given opts, and an optional settings object to extend. Opts are run in sequence. The following opts are available:
- pre: an array of functions that can execucute arbitrary code. Use it to prompt for user input, create repositories, query data and more.
- files: files to be written. Dotfiles need to be prepended with a
_
. Files are populated with variables using the{{varName}}
syntax. - devDependencies: npm dev dependencies to be installed.