UNPKG

1.11 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3var _ = require('lodash');
4var chalk = require('chalk');
5var miaow = require('../index');
6var mutil = require('miaow-util');
7var path = require('path');
8var 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
30var options = _.pick(argv, ['environment', 'configPath']);
31
32if (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
40if (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}