-
Notifications
You must be signed in to change notification settings - Fork 654
/
fis.js
138 lines (120 loc) · 4.15 KB
/
fis.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* fis
* http://fis.baidu.com/
*/
'use strict';
//kernel
var fis = module.exports = require('fis-kernel');
//merge standard conf
fis.config.merge({
modules : {
preprocessor: {
js: 'components',
css: 'components',
html: 'components'
},
postprocessor : {
js : 'jswrapper'
},
optimizer : {
js : 'uglify-js',
css : 'clean-css',
png : 'png-compressor'
},
spriter : 'csssprites',
packager : 'map',
deploy : 'default',
prepackager: 'derived'
}
});
//exports cli object
fis.cli = {};
fis.cli.name = 'fis';
//colors
fis.cli.colors = require('colors');
//commander object
fis.cli.commander = null;
//package.json
fis.cli.info = fis.util.readJSON(__dirname + '/package.json');
//output help info
fis.cli.help = function(){
var content = [
'',
' Usage: ' + fis.cli.name + ' <command>',
'',
' Commands:',
''
];
fis.cli.help.commands.forEach(function(name){
var cmd = fis.require('command', name);
name = cmd.name || name;
name = fis.util.pad(name, 12);
content.push(' ' + name + (cmd.desc || ''));
});
content = content.concat([
'',
' Options:',
'',
' -h, --help output usage information',
' -v, --version output the version number',
' --no-color disable colored output',
''
]);
console.log(content.join('\n'));
};
fis.cli.help.commands = [ 'release', 'install', 'server' ];
//output version info
fis.cli.version = function(){
var content = [
'',
' v' + fis.cli.info.version,
'',
' __' + '/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'.bold.red + '__' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.yellow + '_____' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.green + '___',
' _' + '\\/\\\\\\///////////'.bold.red + '__' + '\\/////\\\\\\///'.bold.yellow + '____' + '/\\\\\\/////////\\\\\\'.bold.green + '_' + ' ',
' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '______' + '\\//\\\\\\'.bold.green + '______' + '\\///'.bold.green + '__',
' _' + '\\/\\\\\\\\\\\\\\\\\\\\\\'.bold.red + '_________' + '\\/\\\\\\'.bold.yellow + '_______' + '\\////\\\\\\'.bold.green + '_________' + ' ',
' _' + '\\/\\\\\\///////'.bold.red + '__________' + '\\/\\\\\\'.bold.yellow + '__________' + '\\////\\\\\\'.bold.green + '______' + ' ',
' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '_____________' + '\\////\\\\\\'.bold.green + '___' + ' ',
' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '______' + '/\\\\\\'.bold.green + '______' + '\\//\\\\\\'.bold.green + '__',
' _' + '\\/\\\\\\'.bold.red + '______________' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.yellow + '_' + '\\///\\\\\\\\\\\\\\\\\\\\\\/'.bold.green + '___',
' _' + '\\///'.bold.red + '______________' + '\\///////////'.bold.yellow + '____' + '\\///////////'.bold.green + '_____',
''
].join('\n');
console.log(content);
};
function hasArgv(argv, search){
var pos = argv.indexOf(search);
var ret = false;
while(pos > -1){
argv.splice(pos, 1);
pos = argv.indexOf(search);
ret = true;
}
return ret;
}
//run cli tools
fis.cli.run = function(argv){
fis.processCWD = process.cwd();
if(hasArgv(argv, '--no-color')){
fis.cli.colors.mode = 'none';
}
var first = argv[2];
if(argv.length < 3 || first === '-h' || first === '--help'){
fis.cli.help();
} else if(first === '-v' || first === '--version'){
fis.cli.version();
} else if(first[0] === '-'){
fis.cli.help();
} else {
//register command
var commander = fis.cli.commander = require('commander');
var cmd = fis.require('command', argv[2]);
cmd.register(
commander
.command(cmd.name || first)
.usage(cmd.usage)
.description(cmd.desc)
);
commander.parse(argv);
}
};