tooljs-module-generator
Version:
Tool for generating a node or browser module
83 lines (72 loc) • 2.13 kB
JavaScript
/**
* Module dependencies.
*/
var exec = require('child_process').exec;
var template = require('tooljs-template');
var optional = require('tooljs-optional');
var tool = require('tooljs-tool');
var rm = require('rimraf').sync;
/**
* Expose `Generator`.
*/
var Generator = module.exports = tool('module-generator')
.input('organization', { type: 'string' })
.input('name', { type: 'string' })
.input('repository', { type: 'string', value: '{{ organization }}/{{ name }}' })
.input('browser', { type: 'boolean', value: false })
.input('node', { type: 'boolean', value: true })
.input('travis', { type: 'boolean', value: true })
.input('mit', { type: 'boolean', value: true })
.input('source', { type: 'string', value: __dirname + '/templates' })
.input('target', { type: 'string', value: process.cwd() + '/{{ name }}' })
.output('source', { type: 'string', value: '{{ source }}' })
.output('target', { type: 'string', value: '{{ target }}' })
.output('locals', { type: 'object' })
.use(user())
.use(locals())
.use(template('gitignore', '.gitignore'))
.use(template('travis.yml', '.travis.yml'))
.use(template('Readme.md'))
.use(template('Makefile'))
.use(template('index.js'))
.use(template('test/index.js'))
.use(template('example.js'))
.use(optional('browser', template('component.json')))
.use(optional('node', template('package.json')));
/**
* Undo the generator.
*
* TODO: find an abstract way.
*
* @api public
*/
Generator.prototype.remove = function(){
};
/**
* Locals used in templates.
*
* @return {Function}
* @api private
*/
function locals() {
return function(next){
this.date = (new Date).getFullYear();
this.locals = this;
next();
};
}
/**
* TODO: Get local github user info from the command line.
*/
function user() {
return function(next){
var user = this.user = {};
exec('git config user.name', function(err, stdout){
if (stdout) user.username = stdout.trim();
exec('git config user.email', function(err, stdout){
if (stdout) user.email = stdout.trim();
next();
});
});
};
}