-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (44 loc) · 1.58 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
47
48
49
50
51
52
53
'use strict';
var debug = require('debug')('scrat:init'),
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 scrat 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');
debug(err.stack);
process.exit(err.code || 1);
});
env.on('end', function () {
log('init', 'finished');
});
env.run('scrat', opts);
});
};