1 | #!/usr/bin/env node
|
2 |
|
3 | var q = require('q');
|
4 | q.longStackSupport = true;
|
5 |
|
6 | var nextUpdate = require('../src/next-update');
|
7 | var program = require('../src/cli-options');
|
8 |
|
9 | var pkg = require('../package.json');
|
10 | var info = pkg.name + '@' + pkg.version + ' - ' + pkg.description;
|
11 |
|
12 | var report = require('../src/report').report;
|
13 | var revert = require('../src/revert');
|
14 |
|
15 | if (program.available) {
|
16 | nextUpdate.available(program.module, {
|
17 | color: program.color
|
18 | });
|
19 | } else if (program.revert) {
|
20 | revert(program.module)
|
21 | .then(function () {
|
22 | console.log('done reverting');
|
23 | }, function (error) {
|
24 | console.error('error while reverting\n', error);
|
25 | });
|
26 | } else {
|
27 | if (!program.tldr) {
|
28 | console.log(info);
|
29 | }
|
30 |
|
31 | var updateNotifier = require('update-notifier');
|
32 | updateNotifier({
|
33 | pkg: pkg,
|
34 | name: pkg.name,
|
35 | version: pkg.version
|
36 | }).notify();
|
37 |
|
38 | var opts = {
|
39 | names: program.module,
|
40 | latest: program.latest,
|
41 | testCommand: program.test,
|
42 | all: program.all,
|
43 | color: program.color,
|
44 | keep: program.keep,
|
45 | allow: program.allowed || program.allow,
|
46 | type: program.type,
|
47 | tldr: program.tldr
|
48 | };
|
49 |
|
50 | var checkCurrent = nextUpdate.checkCurrentInstall.bind(null, opts);
|
51 | var checkCurrentState = program.skip ? q : checkCurrent;
|
52 | var checkUpdates = nextUpdate.checkAllUpdates.bind(null, opts);
|
53 |
|
54 | var reportTestResults = function reportTestResults(results) {
|
55 | if (Array.isArray(results)) {
|
56 | return report(results, {
|
57 | useColors: program.color,
|
58 | keptUpdates: program.keep,
|
59 | changedLog: program['changed-log']
|
60 | });
|
61 | }
|
62 | };
|
63 |
|
64 | checkCurrentState()
|
65 | .then(checkUpdates)
|
66 | .then(reportTestResults)
|
67 | .catch(function (error) {
|
68 | console.error('ERROR testing next working updates');
|
69 | if (error.stack) {
|
70 | console.error(error.stack);
|
71 | }
|
72 | process.exit(1);
|
73 | });
|
74 | }
|