-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// var debug = require('debug')('scrat:init'),
var colors = require('colors'),
yeoman = require('yeoman-generator'),
path = require('path'),
localPath = path.join(__dirname, 'node_modules');
// prepend ./node_modules to NODE_PATH
process.env.NODE_PATH = process.env.NODE_PATH ?
localPath + ':' + process.env.NODE_PATH : localPath;
function log(type, msg, color) {
color = color || 'grey';
var pad = Array(Math.max(0, 10 - type.length) + 1).join(' '),
m = type === 'error' ? type : 'log';
console[m]((pad + type).green, msg[color]);
}
exports.name = 'init';
exports.usage = '[options]'
exports.desc = 'init ybruin project';
exports.register = function (commander) {
commander
.option('--skip-install', 'skip installation')
.action(function () {
var env = yeoman(),
args = Array.prototype.slice.call(arguments),
options = args.pop(),
opts = {
clean: true,
skipInstall: !!options.skipInstall
};
env.lookup();
env.on('error', function (err) {
if (~err.message.indexOf('You don\'t seem to have a generator with the name')) {
err.message = err.message.split('\n')[0];
}
log('error', err.message, 'red');
process.exit(err.code || 1);
});
env.on('end', function () {
log('init', 'finished');
});
env.run('ybruin', opts);
});
};