1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var program = require('commander');
|
6 | var bundlib = require('..');
|
7 |
|
8 | var version = require('../package.json').version;
|
9 |
|
10 | function _async(f) {
|
11 | return function () {
|
12 | var arguments$1 = arguments;
|
13 |
|
14 | for (var args = [], i = 0; i < arguments.length; i++) {
|
15 | args[i] = arguments$1[i];
|
16 | }
|
17 |
|
18 | try {
|
19 | return Promise.resolve(f.apply(this, args));
|
20 | } catch (e) {
|
21 | return Promise.reject(e);
|
22 | }
|
23 | };
|
24 | }
|
25 |
|
26 | function _continueIgnored(value) {
|
27 | if (value && value.then) {
|
28 | return value.then(_empty);
|
29 | }
|
30 | }
|
31 |
|
32 | function _catch(body, recover) {
|
33 | try {
|
34 | var result = body();
|
35 | } catch (e) {
|
36 | return recover(e);
|
37 | }
|
38 |
|
39 | if (result && result.then) {
|
40 | return result.then(void 0, recover);
|
41 | }
|
42 |
|
43 | return result;
|
44 | }
|
45 |
|
46 | function _awaitIgnored(value, direct) {
|
47 | if (!direct) {
|
48 | return value && value.then ? value.then(_empty) : Promise.resolve();
|
49 | }
|
50 | }
|
51 |
|
52 | function _empty() { }
|
53 |
|
54 | program
|
55 | .version(version, "-v, --version")
|
56 | .option("-d, --dev", "create development builds")
|
57 | .option("-w, --watch", "run bundlib in watch mode")
|
58 | .action(_async(function () {
|
59 |
|
60 | var dev = program.dev;
|
61 | var watch = program.watch;
|
62 |
|
63 | return _continueIgnored(_catch(function () {
|
64 | return _awaitIgnored(bundlib.bundlib(process.cwd(), {
|
65 | dev: dev,
|
66 | watch: watch
|
67 | }));
|
68 | }, function (err) {
|
69 |
|
70 | console.error(err && err.message);
|
71 | }));
|
72 |
|
73 | }))
|
74 | .parse(process.argv);
|
75 |
|
76 |
|