UNPKG

1.53 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5var program = require('commander');
6var repo = require('./..');
7
8var version = "0.5.0";
9
10function _empty() {}
11
12function _awaitIgnored(value, direct) {
13 if (!direct) {
14 return value && value.then ? value.then(_empty) : Promise.resolve();
15 }
16}
17
18function _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
32function _continueIgnored(value) {
33 if (value && value.then) {
34 return value.then(_empty);
35 }
36}
37
38function _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
54program.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 // tslint:disable-next-line: no-console
66 console.error(err && err.message);
67 }));
68})).parse(process.argv);