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