1 | #!/usr/bin/env node
|
2 |
|
3 | var _ = require('lodash');
|
4 | var chalk = require('chalk');
|
5 | var miaow = require('../index');
|
6 | var mutil = require('miaow-util');
|
7 | var path = require('path');
|
8 | var argv = require('yargs')
|
9 | .options({
|
10 | 'w': {
|
11 | alias: 'watch',
|
12 | describe: '监听文件变化实时编译',
|
13 | type: 'boolean'
|
14 | },
|
15 |
|
16 | 'e': {
|
17 | alias: 'environment',
|
18 | describe: '启用哪个环境配置',
|
19 | type: 'string'
|
20 | },
|
21 |
|
22 | 'c': {
|
23 | alias: 'configPath',
|
24 | describe: '配置文件路径',
|
25 | type: 'string'
|
26 | }
|
27 | })
|
28 | .argv;
|
29 |
|
30 | var options = _.pick(argv, ['environment', 'configPath']);
|
31 |
|
32 | if (argv._.length) {
|
33 | options.cwd = path.resolve(process.cwd(), argv._[0]);
|
34 |
|
35 | if (argv._[1]) {
|
36 | options.output = path.resolve(process.cwd(), argv._[1]);
|
37 | }
|
38 | }
|
39 |
|
40 | if (argv.watch) {
|
41 | miaow.watch(options);
|
42 | } else {
|
43 | miaow.compile(options, function (err, cache) {
|
44 | if (err) {
|
45 | mutil.log(chalk.red.bold('编译失败'));
|
46 |
|
47 | err.showStack = false;
|
48 | console.error(err.toString());
|
49 | process.exit(1);
|
50 | return;
|
51 | }
|
52 |
|
53 | cache.destroy();
|
54 | process.exit(0);
|
55 | });
|
56 | }
|