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