1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict';
|
7 |
|
8 |
|
9 | var fis = module.exports = require('fis-kernel');
|
10 |
|
11 |
|
12 | fis.config.merge({
|
13 | modules : {
|
14 | preprocessor: {
|
15 | js: 'components',
|
16 | css: 'components',
|
17 | html: 'components'
|
18 | },
|
19 | postprocessor : {
|
20 | js : 'jswrapper'
|
21 | },
|
22 | optimizer : {
|
23 | js : 'uglify-js',
|
24 | css : 'clean-css',
|
25 | png : 'png-compressor'
|
26 | },
|
27 | spriter : 'csssprites',
|
28 | packager : 'map',
|
29 | deploy : 'default',
|
30 | prepackager: 'derived'
|
31 | }
|
32 | });
|
33 |
|
34 |
|
35 | fis.cli = {};
|
36 |
|
37 | fis.cli.name = 'fis';
|
38 |
|
39 |
|
40 | fis.cli.colors = require('colors');
|
41 |
|
42 |
|
43 | fis.cli.commander = null;
|
44 |
|
45 |
|
46 | fis.cli.info = fis.util.readJSON(__dirname + '/package.json');
|
47 |
|
48 |
|
49 | fis.cli.help = function(){
|
50 | var content = [
|
51 | '',
|
52 | ' Usage: ' + fis.cli.name + ' <command>',
|
53 | '',
|
54 | ' Commands:',
|
55 | ''
|
56 | ];
|
57 |
|
58 | fis.cli.help.commands.forEach(function(name){
|
59 | var cmd = fis.require('command', name);
|
60 | name = cmd.name || name;
|
61 | name = fis.util.pad(name, 12);
|
62 | content.push(' ' + name + (cmd.desc || ''));
|
63 | });
|
64 |
|
65 | content = content.concat([
|
66 | '',
|
67 | ' Options:',
|
68 | '',
|
69 | ' -h, --help output usage information',
|
70 | ' -v, --version output the version number',
|
71 | ' --no-color disable colored output',
|
72 | ''
|
73 | ]);
|
74 | console.log(content.join('\n'));
|
75 | };
|
76 |
|
77 | fis.cli.help.commands = [ 'release', 'install', 'server' ];
|
78 |
|
79 |
|
80 | fis.cli.version = function(){
|
81 | var content = [
|
82 | '',
|
83 | ' v' + fis.cli.info.version,
|
84 | '',
|
85 | ' __' + '/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'.bold.red + '__' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.yellow + '_____' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.green + '___',
|
86 | ' _' + '\\/\\\\\\///////////'.bold.red + '__' + '\\/////\\\\\\///'.bold.yellow + '____' + '/\\\\\\/////////\\\\\\'.bold.green + '_' + ' ',
|
87 | ' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '______' + '\\//\\\\\\'.bold.green + '______' + '\\///'.bold.green + '__',
|
88 | ' _' + '\\/\\\\\\\\\\\\\\\\\\\\\\'.bold.red + '_________' + '\\/\\\\\\'.bold.yellow + '_______' + '\\////\\\\\\'.bold.green + '_________' + ' ',
|
89 | ' _' + '\\/\\\\\\///////'.bold.red + '__________' + '\\/\\\\\\'.bold.yellow + '__________' + '\\////\\\\\\'.bold.green + '______' + ' ',
|
90 | ' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '_____________' + '\\////\\\\\\'.bold.green + '___' + ' ',
|
91 | ' _' + '\\/\\\\\\'.bold.red + '_________________' + '\\/\\\\\\'.bold.yellow + '______' + '/\\\\\\'.bold.green + '______' + '\\//\\\\\\'.bold.green + '__',
|
92 | ' _' + '\\/\\\\\\'.bold.red + '______________' + '/\\\\\\\\\\\\\\\\\\\\\\'.bold.yellow + '_' + '\\///\\\\\\\\\\\\\\\\\\\\\\/'.bold.green + '___',
|
93 | ' _' + '\\///'.bold.red + '______________' + '\\///////////'.bold.yellow + '____' + '\\///////////'.bold.green + '_____',
|
94 | ''
|
95 | ].join('\n');
|
96 | console.log(content);
|
97 | };
|
98 |
|
99 | function hasArgv(argv, search){
|
100 | var pos = argv.indexOf(search);
|
101 | var ret = false;
|
102 | while(pos > -1){
|
103 | argv.splice(pos, 1);
|
104 | pos = argv.indexOf(search);
|
105 | ret = true;
|
106 | }
|
107 | return ret;
|
108 | }
|
109 |
|
110 |
|
111 | fis.cli.run = function(argv){
|
112 |
|
113 | fis.processCWD = process.cwd();
|
114 |
|
115 | if(hasArgv(argv, '--no-color')){
|
116 | fis.cli.colors.mode = 'none';
|
117 | }
|
118 |
|
119 | var first = argv[2];
|
120 | if(argv.length < 3 || first === '-h' || first === '--help'){
|
121 | fis.cli.help();
|
122 | } else if(first === '-v' || first === '--version'){
|
123 | fis.cli.version();
|
124 | } else if(first[0] === '-'){
|
125 | fis.cli.help();
|
126 | } else {
|
127 |
|
128 | var commander = fis.cli.commander = require('commander');
|
129 | var cmd = fis.require('command', argv[2]);
|
130 | cmd.register(
|
131 | commander
|
132 | .command(cmd.name || first)
|
133 | .usage(cmd.usage)
|
134 | .description(cmd.desc)
|
135 | );
|
136 | commander.parse(argv);
|
137 | }
|
138 | };
|