UNPKG

1.51 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5var program = require('commander');
6var bundlib = require('..');
7
8var version = require('../package.json').version;
9
10function _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
26function _continueIgnored(value) {
27 if (value && value.then) {
28 return value.then(_empty);
29 }
30}
31
32function _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
46function _awaitIgnored(value, direct) {
47 if (!direct) {
48 return value && value.then ? value.then(_empty) : Promise.resolve();
49 }
50}
51
52function _empty() { }
53
54program
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 // tslint:disable-next-line: no-console
70 console.error(err && err.message);
71 }));
72
73 }))
74 .parse(process.argv);
75
76//# sourceMappingURL=bundlib.js.map