navy 4.1.2-rc.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/lib/cli/config/index.js +57 -241
  2. package/lib/cli/config/wrapper.js +12 -36
  3. package/lib/cli/develop.js +63 -167
  4. package/lib/cli/doctor/clean-compose-files.js +19 -73
  5. package/lib/cli/doctor/index.js +34 -154
  6. package/lib/cli/doctor/invalid-compose-config.js +20 -110
  7. package/lib/cli/doctor/invalid-state.js +22 -115
  8. package/lib/cli/doctor/util.js +26 -93
  9. package/lib/cli/external-ip.js +9 -39
  10. package/lib/cli/health.js +18 -67
  11. package/lib/cli/https.js +92 -0
  12. package/lib/cli/import.js +22 -59
  13. package/lib/cli/index.js +11 -17
  14. package/lib/cli/lan-ip.js +18 -60
  15. package/lib/cli/launch.js +46 -127
  16. package/lib/cli/live.js +37 -111
  17. package/lib/cli/local-ip.js +16 -53
  18. package/lib/cli/logs.js +7 -35
  19. package/lib/cli/open.js +11 -45
  20. package/lib/cli/program.js +145 -167
  21. package/lib/cli/ps.js +36 -105
  22. package/lib/cli/refresh-config.js +18 -62
  23. package/lib/cli/run.js +8 -39
  24. package/lib/cli/status.js +41 -201
  25. package/lib/cli/updates.js +68 -160
  26. package/lib/cli/util/get-or-initialise-navy.js +14 -57
  27. package/lib/cli/util/import.js +33 -83
  28. package/lib/cli/util/index.js +10 -12
  29. package/lib/cli/util/reconfigure.js +12 -102
  30. package/lib/cli/wait-for-healthy.js +53 -100
  31. package/lib/config-provider.js +25 -127
  32. package/lib/config-providers/filesystem/index.js +58 -235
  33. package/lib/config-providers/npm/__tests__/util.js +3 -6
  34. package/lib/config-providers/npm/index.js +60 -231
  35. package/lib/config-providers/npm/util.js +6 -9
  36. package/lib/config.js +39 -76
  37. package/lib/driver-logging.js +23 -28
  38. package/lib/driver.js +5 -7
  39. package/lib/drivers/docker-compose/client.js +64 -172
  40. package/lib/drivers/docker-compose/index.js +153 -464
  41. package/lib/errors.js +27 -61
  42. package/lib/http-proxy.js +72 -158
  43. package/lib/index.js +26 -29
  44. package/lib/middleware/add-service-proxy-config.js +76 -0
  45. package/lib/middleware/develop.js +9 -23
  46. package/lib/middleware/helpers.js +20 -25
  47. package/lib/middleware/port-override.js +15 -37
  48. package/lib/middleware/set-env-vars.js +14 -18
  49. package/lib/middleware/set-image.js +12 -18
  50. package/lib/middleware/set-logging-driver.js +14 -18
  51. package/lib/middleware/tag-override.js +11 -19
  52. package/lib/navy/default-middleware.js +13 -27
  53. package/lib/navy/index.js +438 -1761
  54. package/lib/navy/middleware.js +15 -100
  55. package/lib/navy/plugin-interface.js +28 -108
  56. package/lib/navy/state.js +58 -147
  57. package/lib/navy/util.js +2 -1
  58. package/lib/service.js +5 -3
  59. package/lib/util/__tests__/external-ip.js +20 -96
  60. package/lib/util/__tests__/registry-client.js +11 -24
  61. package/lib/util/__tests__/service-host.js +19 -116
  62. package/lib/util/docker-client.js +10 -13
  63. package/lib/util/exec-async.js +9 -27
  64. package/lib/util/external-ip.js +48 -126
  65. package/lib/util/fs.js +7 -6
  66. package/lib/util/get-lan-ip.js +15 -52
  67. package/lib/util/has-update.js +23 -73
  68. package/lib/util/https.js +213 -0
  69. package/lib/util/navyrc.js +12 -50
  70. package/lib/util/registry-client.js +41 -112
  71. package/lib/util/service-host.js +40 -129
  72. package/lib/util/table.js +11 -21
  73. package/package.json +14 -14
  74. package/LICENSE +0 -21
  75. package/lib/middleware/add-virtual-hosts.js +0 -147
@@ -1,40 +1,25 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = void 0;
6
9
 
7
- var _regenerator = require('babel-runtime/regenerator');
8
-
9
- var _regenerator2 = _interopRequireDefault(_regenerator);
10
-
11
- var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
12
-
13
- var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
14
-
15
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
16
-
17
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
10
+ var _commander = _interopRequireDefault(require("commander"));
18
11
 
19
- var _commander = require('commander');
12
+ var _chalk = _interopRequireDefault(require("chalk"));
20
13
 
21
- var _commander2 = _interopRequireDefault(_commander);
14
+ var _errors = require("../errors");
22
15
 
23
- var _chalk = require('chalk');
16
+ var _config = require("../config");
24
17
 
25
- var _chalk2 = _interopRequireDefault(_chalk);
18
+ var _driverLogging = require("../driver-logging");
26
19
 
27
- var _errors = require('../errors');
20
+ var _configProvider = require("../config-provider");
28
21
 
29
- var _config = require('../config');
30
-
31
- var _driverLogging = require('../driver-logging');
32
-
33
- var _configProvider = require('../config-provider');
34
-
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
-
37
- var loadingLabelMap = {
22
+ const loadingLabelMap = {
38
23
  destroy: 'Destroying services...',
39
24
  start: 'Starting services...',
40
25
  stop: 'Stopping services...',
@@ -49,26 +34,30 @@ var loadingLabelMap = {
49
34
  resetPort: 'Resetting port mapping...'
50
35
  };
51
36
 
52
- function removeFirstLineFromStackTrace(ex) {
53
- return ex.stack.split('\n').slice(1).join('\n');
37
+ function removeFirstLineFromStackTrace(stack) {
38
+ var _stack$split, _stack$split$slice;
39
+
40
+ return stack === null || stack === void 0 ? void 0 : (_stack$split = stack.split('\n')) === null || _stack$split === void 0 ? void 0 : (_stack$split$slice = _stack$split.slice(1)) === null || _stack$split$slice === void 0 ? void 0 : _stack$split$slice.join('\n');
54
41
  }
55
42
 
56
43
  function wrapper(res) {
57
44
  if (res.catch) {
58
- res.catch(function (ex) {
59
- (0, _driverLogging.stopDriverLogging)({ success: false });
45
+ res.catch(ex => {
46
+ (0, _driverLogging.stopDriverLogging)({
47
+ success: false
48
+ });
60
49
 
61
50
  if (ex instanceof _errors.NavyError) {
62
51
  ex.prettyPrint();
63
52
  } else if (ex.name === 'Invariant Violation') {
64
53
  console.log();
65
- console.log(_chalk2.default.bgRed(_chalk2.default.bold(' ' + ex.name + ' ')));
54
+ console.log(_chalk.default.bgRed(_chalk.default.bold(' ' + ex.name + ' ')));
66
55
  console.log();
67
56
  console.log(' ' + ex.message.substring(ex.message.indexOf(': ') + 2));
68
57
  console.log();
69
- console.log(' ' + _chalk2.default.blue('Run') + ' ' + _chalk2.default.bold('navy doctor') + ' ' + _chalk2.default.blue('to attempt troubleshooting'));
58
+ console.log(' ' + _chalk.default.blue('Run') + ' ' + _chalk.default.bold('navy doctor') + ' ' + _chalk.default.blue('to attempt troubleshooting'));
70
59
  console.log();
71
- console.log(_chalk2.default.dim(removeFirstLineFromStackTrace(ex.stack)));
60
+ console.log(_chalk.default.dim(removeFirstLineFromStackTrace(ex.stack)));
72
61
  console.log();
73
62
  } else {
74
63
  console.error(ex.stack);
@@ -81,185 +70,174 @@ function wrapper(res) {
81
70
  return res;
82
71
  }
83
72
 
84
- function basicCliWrapper(fnName) {
85
- var wrapperOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
86
-
87
- var driverLogging = wrapperOpts.driverLogging == null ? true : wrapperOpts.driverLogging;
88
-
89
- return function () {
90
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(maybeServices) {
91
- for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
92
- args[_key - 1] = arguments[_key];
93
- }
94
-
95
- var _require, getNavy, opts, otherArgs, envName, navy, returnVal;
96
-
97
- return _regenerator2.default.wrap(function _callee$(_context) {
98
- while (1) {
99
- switch (_context.prev = _context.next) {
100
- case 0:
101
- _require = require('../navy'), getNavy = _require.getNavy;
102
- opts = args.length === 0 ? maybeServices : args[args.length - 1];
103
- otherArgs = args.slice(0, args.length - 1);
104
- envName = opts.navy;
105
-
106
-
107
- if (wrapperOpts.serviceBasedAlias && maybeServices.length) {
108
- console.log('This command should not be called with a list of services. calling \'' + wrapperOpts.serviceBasedAlias + '\' instead');
109
- fnName = wrapperOpts.serviceBasedAlias;
110
- maybeServices = maybeServices.split(' ');
111
- }
112
-
113
- process.on('unhandledRejection', function (ex) {
114
- (0, _driverLogging.stopDriverLogging)({ success: false });
115
-
116
- if (ex instanceof _errors.NavyError) {
117
- ex.prettyPrint();
118
- } else {
119
- console.error(ex.stack);
120
- }
121
-
122
- process.exit();
123
- });
124
-
125
- if (driverLogging) (0, _driverLogging.startDriverLogging)(loadingLabelMap[fnName]);
126
-
127
- navy = getNavy(envName);
128
- _context.next = 10;
129
- return navy.ensurePluginsLoaded();
73
+ function basicCliWrapper(fnName, wrapperOpts = {}) {
74
+ const driverLogging = wrapperOpts.driverLogging == null ? true : wrapperOpts.driverLogging;
75
+ return async function (maybeServices, ...args) {
76
+ const {
77
+ getNavy
78
+ } = require('../navy');
130
79
 
131
- case 10:
132
- _context.next = 12;
133
- return navy.emitAsync('cli.before.' + fnName, fnName);
80
+ const opts = args.length === 0 ? maybeServices : args[args.length - 1];
81
+ const otherArgs = args.slice(0, args.length - 1);
82
+ const envName = opts.navy;
134
83
 
135
- case 12:
136
- _context.next = 14;
137
- return navy[fnName].apply(navy, [Array.isArray(maybeServices) && maybeServices.length === 0 ? undefined : maybeServices].concat((0, _toConsumableArray3.default)(otherArgs)));
84
+ if (wrapperOpts.serviceBasedAlias && maybeServices.length) {
85
+ console.log(`This command should not be called with a list of services. calling '${wrapperOpts.serviceBasedAlias}' instead`);
86
+ fnName = wrapperOpts.serviceBasedAlias;
87
+ maybeServices = maybeServices.split(' ');
88
+ }
138
89
 
139
- case 14:
140
- returnVal = _context.sent;
141
- _context.next = 17;
142
- return navy.emitAsync('cli.after.' + fnName, fnName);
90
+ process.on('unhandledRejection', ex => {
91
+ (0, _driverLogging.stopDriverLogging)({
92
+ success: false
93
+ });
143
94
 
144
- case 17:
145
-
146
- if (driverLogging) (0, _driverLogging.stopDriverLogging)();
95
+ if (ex instanceof _errors.NavyError) {
96
+ ex.prettyPrint();
97
+ } else {
98
+ console.error(ex.stack);
99
+ }
147
100
 
148
- if (!Array.isArray(returnVal)) {
149
- _context.next = 20;
150
- break;
151
- }
101
+ process.exit();
102
+ });
103
+ if (driverLogging) (0, _driverLogging.startDriverLogging)(loadingLabelMap[fnName]);
104
+ const navy = getNavy(envName);
105
+ await navy.ensurePluginsLoaded();
106
+ await navy.emitAsync(`cli.before.${fnName}`, fnName);
107
+ const returnVal = await navy[fnName](Array.isArray(maybeServices) && maybeServices.length === 0 ? undefined : maybeServices, ...otherArgs);
108
+ await navy.emitAsync(`cli.after.${fnName}`, fnName);
109
+ if (driverLogging) (0, _driverLogging.stopDriverLogging)();
110
+
111
+ if (Array.isArray(returnVal)) {
112
+ return console.log(returnVal.join('\n'));
113
+ }
114
+
115
+ if (returnVal != null) {
116
+ console.log(returnVal);
117
+ }
118
+ };
119
+ }
152
120
 
153
- return _context.abrupt('return', console.log(returnVal.join('\n')));
121
+ function lazyRequire(path) {
122
+ return function (...args) {
123
+ const mod = require(path);
154
124
 
155
- case 20:
125
+ return wrapper((mod.default || mod)(...args));
126
+ };
127
+ }
156
128
 
157
- if (returnVal != null) {
158
- console.log(returnVal);
159
- }
129
+ const defaultNavy = process.env.NAVY_NAME || (0, _config.getConfig)().defaultNavy;
160
130
 
161
- case 21:
162
- case 'end':
163
- return _context.stop();
164
- }
165
- }
166
- }, _callee, this);
167
- }));
131
+ const importCommand = _commander.default.command('import').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Imports docker compose configuration from the current working directory and initialises a new navy').action(lazyRequire('./import'));
168
132
 
169
- return function (_x2) {
170
- return _ref.apply(this, arguments);
171
- };
172
- }();
173
- }
133
+ (0, _configProvider.getImportCommandLineOptions)().forEach(opt => importCommand.option(...opt));
174
134
 
175
- function lazyRequire(path) {
176
- return function () {
177
- var mod = require(path);
178
- return wrapper((mod.default || mod).apply(undefined, arguments));
179
- };
180
- }
135
+ _commander.default.command('launch [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Launches the given services in a navy').action(lazyRequire('./launch')).on('--help', () => console.log(`
136
+ This will prompt you for the services that you want to bring up.
137
+ You can optionally provide the names of services to bring up which will disable the interactive prompt.
138
+ `));
181
139
 
182
- var defaultNavy = process.env.NAVY_NAME || (0, _config.getConfig)().defaultNavy;
140
+ _commander.default.command('destroy').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Destroys a navy and all related data and services').action(basicCliWrapper('destroy', {
141
+ serviceBasedAlias: 'kill'
142
+ })).on('--help', () => console.log(`
143
+ This will destroy an entire navy and all of its data and services.
183
144
 
184
- var importCommand = _commander2.default.command('import').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Imports docker compose configuration from the current working directory and initialises a new navy').action(lazyRequire('./import'));
145
+ Examples:
146
+ $ navy destroy # destroy "${defaultNavy}" navy
147
+ $ navy destroy -e dev # destroy "dev" navy
148
+ $ navy destroy -e test # destroy "test" navy
149
+ `));
185
150
 
186
- (0, _configProvider.getImportCommandLineOptions)().forEach(function (opt) {
187
- return importCommand.option.apply(importCommand, (0, _toConsumableArray3.default)(opt));
188
- });
151
+ _commander.default.command('delete').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Removes a navy configuration without removing any docker containers or services').action(basicCliWrapper('delete'));
189
152
 
190
- _commander2.default.command('launch [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Launches the given services in a navy').action(lazyRequire('./launch')).on('--help', function () {
191
- return console.log('\n This will prompt you for the services that you want to bring up.\n You can optionally provide the names of services to bring up which will disable the interactive prompt.\n ');
192
- });
153
+ _commander.default.command('ps').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).option('--json', 'output JSON instead of a table').description('Lists the running services for a navy').action(lazyRequire('./ps'));
193
154
 
194
- _commander2.default.command('destroy').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Destroys a navy and all related data and services').action(basicCliWrapper('destroy', { serviceBasedAlias: 'kill' })).on('--help', function () {
195
- return console.log('\n This will destroy an entire navy and all of its data and services.\n\n Examples:\n $ navy destroy # destroy "' + defaultNavy + '" navy\n $ navy destroy -e dev # destroy "dev" navy\n $ navy destroy -e test # destroy "test" navy\n ');
196
- });
155
+ _commander.default.command('start [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Starts the given services').action(basicCliWrapper('start'));
197
156
 
198
- _commander2.default.command('delete').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Removes a navy configuration without removing any docker containers or services').action(basicCliWrapper('delete'));
157
+ _commander.default.command('stop [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Stops the given services').action(basicCliWrapper('stop'));
199
158
 
200
- _commander2.default.command('ps').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).option('--json', 'output JSON instead of a table').description('Lists the running services for a navy').action(lazyRequire('./ps'));
159
+ _commander.default.command('restart [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Restarts the given services').action(basicCliWrapper('restart'));
201
160
 
202
- _commander2.default.command('start [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Starts the given services').action(basicCliWrapper('start'));
161
+ _commander.default.command('kill [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Kills the given services').action(basicCliWrapper('kill'));
203
162
 
204
- _commander2.default.command('stop [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Stops the given services').action(basicCliWrapper('stop'));
163
+ _commander.default.command('rm [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Removes the given services').action(basicCliWrapper('rm'));
205
164
 
206
- _commander2.default.command('restart [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Restarts the given services').action(basicCliWrapper('restart'));
165
+ _commander.default.command('update [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Pulls the given services\' images from their respective registries and relaunches the services').action(basicCliWrapper('update'));
207
166
 
208
- _commander2.default.command('kill [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Kills the given services').action(basicCliWrapper('kill'));
167
+ _commander.default.command('updates').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Checks for updates for all the launched services').action(lazyRequire('./updates'));
209
168
 
210
- _commander2.default.command('rm [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Removes the given services').action(basicCliWrapper('rm'));
169
+ _commander.default.command('logs [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Streams logs for the given services').action(lazyRequire('./logs'));
211
170
 
212
- _commander2.default.command('update [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Pulls the given services\' images from their respective registries and relaunches the services').action(basicCliWrapper('update'));
171
+ _commander.default.command('health').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Shows the health status for all of the launched services').action(lazyRequire('./health'));
213
172
 
214
- _commander2.default.command('updates').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Checks for updates for all the launched services').action(lazyRequire('./updates'));
173
+ _commander.default.command('wait-for-healthy [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Waits for the given services to be healthy').action(lazyRequire('./wait-for-healthy'));
215
174
 
216
- _commander2.default.command('logs [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Streams logs for the given services').action(lazyRequire('./logs'));
175
+ _commander.default.command('use-tag <service> <tag>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Uses a specific tag for the given service').action(basicCliWrapper('useTag'));
217
176
 
218
- _commander2.default.command('health').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Shows the health status for all of the launched services').action(lazyRequire('./health'));
177
+ _commander.default.command('reset-tag <service>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Resets any tag override on the given service').action(basicCliWrapper('resetTag'));
219
178
 
220
- _commander2.default.command('wait-for-healthy [services...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Waits for the given services to be healthy').action(lazyRequire('./wait-for-healthy'));
179
+ _commander.default.command('https [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).option('-d, --disable <service>', 'disable https (deletes cert) for a given service', null).description('Prints or enables HTTPS services').action(lazyRequire('./https')).on('--help', () => console.log(`
180
+ Examples:
181
+ List urls of services that listen on https:
182
+ $ navy https
221
183
 
222
- _commander2.default.command('use-tag <service> <tag>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Uses a specific tag for the given service').action(basicCliWrapper('useTag'));
184
+ Enable https for mywebservice and anotherwebservice services
185
+ $ navy https mywebservice anotherwebservice
223
186
 
224
- _commander2.default.command('reset-tag <service>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Resets any tag override on the given service').action(basicCliWrapper('resetTag'));
187
+ Disable https for mywebservice
188
+ $ navy https -d mywebservice
189
+ `));
225
190
 
226
- _commander2.default.command('use-port <service> <internal> <external>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Uses a specific external port for the given service and internal port').action(basicCliWrapper('usePort'));
191
+ _commander.default.command('use-port <service> <internal> <external>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Uses a specific external port for the given service and internal port').action(basicCliWrapper('usePort'));
227
192
 
228
- _commander2.default.command('reset-port <service> <internal>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Resets a specific external port mapping set by use-port').action(basicCliWrapper('resetPort'));
193
+ _commander.default.command('reset-port <service> <internal>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Resets a specific external port mapping set by use-port').action(basicCliWrapper('resetPort'));
229
194
 
230
- _commander2.default.command('url <service>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Prints the external URL for the given service if it is a web service').action(basicCliWrapper('url', { driverLogging: false })).on('--help', function () {
231
- return console.log('\n Examples:\n $ navy url mywebserver\n http://mywebserver.dev.127.0.0.1.nip.io\n ');
232
- });
195
+ _commander.default.command('url <service>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Prints the external URL for the given service if it is a web service').action(basicCliWrapper('url', {
196
+ driverLogging: false
197
+ })).on('--help', () => console.log(`
198
+ Examples:
199
+ $ navy url mywebserver
200
+ http://mywebserver.dev.127.0.0.1.nip.io
201
+ `));
233
202
 
234
- _commander2.default.command('open <service>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Opens the given service in the default web browser, if the service is configured with a URL').action(lazyRequire('./open')).on('--help', function () {
235
- return console.log('\n Examples:\n $ navy open mywebserver\n Opening mywebserver...\n ');
236
- });
203
+ _commander.default.command('open <service>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Opens the given service in the default web browser, if the service is configured with a URL').action(lazyRequire('./open')).on('--help', () => console.log(`
204
+ Examples:
205
+ $ navy open mywebserver
206
+ Opening mywebserver...
207
+ `));
237
208
 
238
- _commander2.default.command('port <service> <port>').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Prints the external port for the given internal port of the given service').action(basicCliWrapper('port', { driverLogging: false })).on('--help', function () {
239
- return console.log('\n Examples:\n $ navy port mywebserver 80\n 35821\n ');
240
- });
209
+ _commander.default.command('port <service> <port>').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Prints the external port for the given internal port of the given service').action(basicCliWrapper('port', {
210
+ driverLogging: false
211
+ })).on('--help', () => console.log(`
212
+ Examples:
213
+ $ navy port mywebserver 80
214
+ 35821
215
+ `));
241
216
 
242
- _commander2.default.command('available-services').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Prints the names of the services that are launched or can be launched').action(basicCliWrapper('getAvailableServiceNames', { driverLogging: false }));
217
+ _commander.default.command('available-services').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Prints the names of the services that are launched or can be launched').action(basicCliWrapper('getAvailableServiceNames', {
218
+ driverLogging: false
219
+ }));
243
220
 
244
- _commander2.default.command('develop [service]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Puts the given service into development using the current working directory').action(lazyRequire('./develop'));
221
+ _commander.default.command('develop [service]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Puts the given service into development using the current working directory').action(lazyRequire('./develop'));
245
222
 
246
- _commander2.default.command('live [service]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Takes the given service out of development').action(lazyRequire('./live'));
223
+ _commander.default.command('live [service]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Takes the given service out of development').action(lazyRequire('./live'));
247
224
 
248
- _commander2.default.command('run <name> [args...]').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Runs a named command specific to the given Navy').action(lazyRequire('./run'));
225
+ _commander.default.command('run <name> [args...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Runs a named command specific to the given Navy').action(lazyRequire('./run'));
249
226
 
250
- _commander2.default.command('refresh-config').option('-e, --navy [env]', 'set the navy name to be used [' + defaultNavy + ']', defaultNavy).description('Refreshes the configuration for the given Navy').action(lazyRequire('./refresh-config'));
227
+ _commander.default.command('refresh-config').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Refreshes the configuration for the given Navy').action(lazyRequire('./refresh-config'));
251
228
 
252
- _commander2.default.command('status').option('--json', 'output JSON instead of a table').description('List all of the imported navies').action(lazyRequire('./status'));
229
+ _commander.default.command('status').option('--json', 'output JSON instead of a table').description('List all of the imported navies').action(lazyRequire('./status'));
253
230
 
254
- _commander2.default.command('doctor').description('Identifies and tries to fix some common issues which might cause Navy to stop working').action(lazyRequire('./doctor'));
231
+ _commander.default.command('doctor').description('Identifies and tries to fix some common issues which might cause Navy to stop working').action(lazyRequire('./doctor'));
255
232
 
256
- _commander2.default.command('config').description('Modify and get Navy global config - run `navy config` for help').action(lazyRequire('./config/wrapper'));
233
+ _commander.default.command('config').description('Modify and get Navy global config - run `navy config` for help').action(lazyRequire('./config/wrapper'));
257
234
 
258
- _commander2.default.command('external-ip').description('Prints the external IP which services are accessible on').action(lazyRequire('./external-ip'));
235
+ _commander.default.command('external-ip').description('Prints the external IP which services are accessible on').action(lazyRequire('./external-ip'));
259
236
 
260
- _commander2.default.command('use-lan-ip').description('Use your LAN ip address for connecting to Navy services').action(lazyRequire('./lan-ip'));
237
+ _commander.default.command('use-lan-ip').description('Use your LAN ip address for connecting to Navy services').action(lazyRequire('./lan-ip'));
261
238
 
262
- _commander2.default.command('use-local-ip').description('Use your local ip address (127.0.0.1) for connecting to Navy services').action(lazyRequire('./local-ip'));
239
+ _commander.default.command('use-local-ip').description('Use your local ip address (127.0.0.1) for connecting to Navy services').action(lazyRequire('./local-ip'));
263
240
 
264
- exports.default = _commander2.default;
241
+ var _default = _commander.default;
242
+ exports.default = _default;
265
243
  module.exports = exports.default;
package/lib/cli/ps.js CHANGED
@@ -1,57 +1,34 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = _default;
6
9
 
7
- var _regenerator = require('babel-runtime/regenerator');
8
-
9
- var _regenerator2 = _interopRequireDefault(_regenerator);
10
-
11
- var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
12
-
13
- var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
14
-
15
- var _stringify = require('babel-runtime/core-js/json/stringify');
16
-
17
- var _stringify2 = _interopRequireDefault(_stringify);
18
-
19
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
20
-
21
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
22
-
23
- var _keys = require('babel-runtime/core-js/object/keys');
24
-
25
- var _keys2 = _interopRequireDefault(_keys);
26
-
27
- var _chalk = require('chalk');
28
-
29
- var _chalk2 = _interopRequireDefault(_chalk);
10
+ var _chalk = _interopRequireDefault(require("chalk"));
30
11
 
31
- var _ = require('../');
12
+ var _ = require("../");
32
13
 
33
- var _serviceHost = require('../util/service-host');
14
+ var _serviceHost = require("../util/service-host");
34
15
 
35
- var _table = require('../util/table');
16
+ var _table = _interopRequireDefault(require("../util/table"));
36
17
 
37
- var _table2 = _interopRequireDefault(_table);
38
-
39
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
-
41
- var SMALL_WINDOW_COLUMNS = 185;
18
+ const SMALL_WINDOW_COLUMNS = 185;
42
19
 
43
20
  function getStatus(service, state) {
44
- var statusString = service.status === 'exited' ? _chalk2.default.red(service.status) : service.status;
21
+ let statusString = service.status === 'exited' ? _chalk.default.red(service.status) : service.status;
45
22
 
46
23
  if (state && state.services && state.services[service.name]) {
47
- var serviceState = state.services[service.name];
24
+ const serviceState = state.services[service.name];
48
25
 
49
26
  if (serviceState._develop) {
50
- statusString += ' ' + _chalk2.default.yellow('(development)');
27
+ statusString += ' ' + _chalk.default.yellow('(development)');
51
28
  }
52
29
 
53
30
  if (serviceState._tag) {
54
- statusString += ' ' + _chalk2.default.cyan('@ ' + serviceState._tag);
31
+ statusString += ' ' + _chalk.default.cyan(`@ ${serviceState._tag}`);
55
32
  }
56
33
  }
57
34
 
@@ -63,77 +40,31 @@ function getPorts(service) {
63
40
  return '-';
64
41
  }
65
42
 
66
- var ports = service.raw.NetworkSettings.Ports;
67
- var portKeys = (0, _keys2.default)(ports);
68
-
69
- return portKeys.map(function (portKey) {
70
- return ports[portKey] ? ports[portKey].map(function (conf) {
71
- return conf.HostPort;
72
- }).join(', ') + '->' + portKey : portKey;
43
+ const ports = service.raw.NetworkSettings.Ports;
44
+ const portKeys = Object.keys(ports);
45
+ return portKeys.map(portKey => {
46
+ return ports[portKey] ? `${ports[portKey].map(conf => conf.HostPort).join(', ')}->${portKey}` : portKey;
73
47
  }).join(', ');
74
48
  }
75
49
 
76
- var getDisplayUrl = function getDisplayUrl(serviceUrl) {
77
- return serviceUrl != null ? serviceUrl : '-';
78
- };
79
-
80
- exports.default = function () {
81
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(opts) {
82
- var navy, ps, state, isSmallConsole;
83
- return _regenerator2.default.wrap(function _callee$(_context) {
84
- while (1) {
85
- switch (_context.prev = _context.next) {
86
- case 0:
87
- navy = (0, _.getNavy)(opts.navy);
88
- _context.next = 3;
89
- return navy.ps();
90
-
91
- case 3:
92
- ps = _context.sent;
93
- _context.next = 6;
94
- return navy.getState();
95
-
96
- case 6:
97
- state = _context.sent;
98
-
99
-
100
- // $FlowIgnore getWindowSize not on type
101
- isSmallConsole = process.stdout.isTTY && process.stdout.getWindowSize()[0] < SMALL_WINDOW_COLUMNS;
102
-
103
- if (!opts.json) {
104
- _context.next = 10;
105
- break;
106
- }
107
-
108
- return _context.abrupt('return', console.log((0, _stringify2.default)(ps, null, 2)));
109
-
110
- case 10:
111
- if (!isSmallConsole) {
112
- _context.next = 12;
113
- break;
114
- }
115
-
116
- return _context.abrupt('return', console.log((0, _table2.default)([['ID', 'NAME', 'STATUS', 'PORTS', 'URL']].concat((0, _toConsumableArray3.default)(ps.map(function (service) {
117
- return [service.id.substring(0, 12), service.name, getStatus(service, state), getPorts(service), getDisplayUrl((0, _serviceHost.getUrlFromService)(service))];
118
- }))))));
119
-
120
- case 12:
121
-
122
- console.log((0, _table2.default)([['ID', 'NAME', 'IMAGE', 'STATUS', 'PORTS', 'URL']].concat((0, _toConsumableArray3.default)(ps.map(function (service) {
123
- return [service.id.substring(0, 12), service.name, service.image, getStatus(service, state), getPorts(service), getDisplayUrl((0, _serviceHost.getUrlFromService)(service))];
124
- })))));
125
-
126
- case 13:
127
- case 'end':
128
- return _context.stop();
129
- }
130
- }
131
- }, _callee, this);
132
- }));
133
-
134
- return function (_x) {
135
- return _ref.apply(this, arguments);
136
- };
137
- }();
50
+ const getDisplayUrl = serviceUrl => serviceUrl != null ? serviceUrl : '-';
51
+
52
+ async function _default(opts) {
53
+ const navy = (0, _.getNavy)(opts.navy);
54
+ const ps = await navy.ps();
55
+ const state = await navy.getState(); // $FlowIgnore getWindowSize not on type
56
+
57
+ const isSmallConsole = process.stdout.isTTY && process.stdout.getWindowSize()[0] < SMALL_WINDOW_COLUMNS;
58
+
59
+ if (opts.json) {
60
+ return console.log(JSON.stringify(ps, null, 2));
61
+ }
62
+
63
+ if (isSmallConsole) {
64
+ return console.log((0, _table.default)([['ID', 'NAME', 'STATUS', 'PORTS', 'URL'], ...ps.map(service => [service.id.substring(0, 12), service.name, getStatus(service, state), getPorts(service), getDisplayUrl((0, _serviceHost.getUrlFromService)(service))])]));
65
+ }
66
+
67
+ console.log((0, _table.default)([['ID', 'NAME', 'IMAGE', 'STATUS', 'PORTS', 'URL'], ...ps.map(service => [service.id.substring(0, 12), service.name, service.image, getStatus(service, state), getPorts(service), getDisplayUrl((0, _serviceHost.getUrlFromService)(service))])]));
68
+ }
138
69
 
139
70
  module.exports = exports.default;