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
package/lib/navy/index.js CHANGED
@@ -1,1904 +1,581 @@
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
  });
6
- exports.getLaunchedNavyNames = exports.getLaunchedNavies = exports.Navy = undefined;
7
-
8
- var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
9
-
10
- var _defineProperty3 = _interopRequireDefault(_defineProperty2);
11
-
12
- var _extends8 = require('babel-runtime/helpers/extends');
13
-
14
- var _extends9 = _interopRequireDefault(_extends8);
15
-
16
- var _regenerator = require('babel-runtime/regenerator');
17
-
18
- var _regenerator2 = _interopRequireDefault(_regenerator);
19
-
20
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
21
-
22
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
23
-
24
- var _maxSafeInteger = require('babel-runtime/core-js/number/max-safe-integer');
25
-
26
- var _maxSafeInteger2 = _interopRequireDefault(_maxSafeInteger);
27
-
28
- var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
29
-
30
- var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
31
-
32
- var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
33
-
34
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
35
-
36
- var _createClass2 = require('babel-runtime/helpers/createClass');
37
-
38
- var _createClass3 = _interopRequireDefault(_createClass2);
39
-
40
- var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
41
-
42
- var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
43
-
44
- var _inherits2 = require('babel-runtime/helpers/inherits');
45
-
46
- var _inherits3 = _interopRequireDefault(_inherits2);
47
-
48
- /**
49
- * Returns an array of `Navy` instances which are currently imported and launched.
50
- * @public
51
- */
52
- var getLaunchedNavies = exports.getLaunchedNavies = function () {
53
- var _ref35 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee35() {
54
- var navyNames;
55
- return _regenerator2.default.wrap(function _callee35$(_context35) {
56
- while (1) {
57
- switch (_context35.prev = _context35.next) {
58
- case 0:
59
- _context35.prev = 0;
60
- _context35.next = 3;
61
- return _fs2.default.readdirAsync((0, _state.pathToNavys)());
62
-
63
- case 3:
64
- navyNames = _context35.sent;
65
- return _context35.abrupt('return', navyNames.filter(function (node) {
66
- return _fs2.default.lstatSync((0, _state.pathToNavy)(node)).isDirectory();
67
- }).map(function (name) {
68
- return getNavy(name);
69
- }));
70
-
71
- case 7:
72
- _context35.prev = 7;
73
- _context35.t0 = _context35['catch'](0);
74
- return _context35.abrupt('return', []);
75
-
76
- case 10:
77
- case 'end':
78
- return _context35.stop();
79
- }
80
- }
81
- }, _callee35, this, [[0, 7]]);
82
- }));
83
-
84
- return function getLaunchedNavies() {
85
- return _ref35.apply(this, arguments);
86
- };
87
- }();
88
-
89
- /**
90
- * Returns an array of names of Navies which are currently imported and launched.
91
- * @public
92
- */
93
-
94
-
95
- var getLaunchedNavyNames = exports.getLaunchedNavyNames = function () {
96
- var _ref36 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee36() {
97
- return _regenerator2.default.wrap(function _callee36$(_context36) {
98
- while (1) {
99
- switch (_context36.prev = _context36.next) {
100
- case 0:
101
- _context36.prev = 0;
102
- _context36.next = 3;
103
- return _fs2.default.readdirAsync((0, _state.pathToNavys)());
104
-
105
- case 3:
106
- return _context36.abrupt('return', _context36.sent);
107
-
108
- case 6:
109
- _context36.prev = 6;
110
- _context36.t0 = _context36['catch'](0);
111
- return _context36.abrupt('return', []);
112
-
113
- case 9:
114
- case 'end':
115
- return _context36.stop();
116
- }
117
- }
118
- }, _callee36, this, [[0, 6]]);
119
- }));
120
-
121
- return function getLaunchedNavyNames() {
122
- return _ref36.apply(this, arguments);
123
- };
124
- }();
125
-
8
+ exports.Navy = void 0;
9
+ exports.getLaunchedNavies = getLaunchedNavies;
10
+ exports.getLaunchedNavyNames = getLaunchedNavyNames;
126
11
  exports.getNavy = getNavy;
127
12
 
128
- var _invariant = require('invariant');
13
+ var _invariant = _interopRequireDefault(require("invariant"));
129
14
 
130
- var _invariant2 = _interopRequireDefault(_invariant);
15
+ var _eventemitter = require("eventemitter2");
131
16
 
132
- var _eventemitter = require('eventemitter2');
17
+ var _promiseRetry = _interopRequireDefault(require("promise-retry"));
133
18
 
134
- var _promiseRetry = require('promise-retry');
19
+ var _fs = _interopRequireDefault(require("../util/fs"));
135
20
 
136
- var _promiseRetry2 = _interopRequireDefault(_promiseRetry);
21
+ var _driver = require("../driver");
137
22
 
138
- var _fs = require('../util/fs');
23
+ var _configProvider = require("../config-provider");
139
24
 
140
- var _fs2 = _interopRequireDefault(_fs);
25
+ var _util = require("./util");
141
26
 
142
- var _driver = require('../driver');
27
+ var _state = require("./state");
143
28
 
144
- var _configProvider = require('../config-provider');
29
+ var _config = require("../config");
145
30
 
146
- var _util = require('./util');
31
+ var _errors = require("../errors");
147
32
 
148
- var _state = require('./state');
33
+ var _pluginInterface = require("./plugin-interface");
149
34
 
150
- var _config = require('../config');
35
+ var _middleware = require("./middleware");
151
36
 
152
- var _errors = require('../errors');
37
+ var _httpProxy = require("../http-proxy");
153
38
 
154
- var _pluginInterface = require('./plugin-interface');
39
+ var _externalIp = require("../util/external-ip");
155
40
 
156
- var _middleware = require('./middleware');
157
-
158
- var _httpProxy = require('../http-proxy');
159
-
160
- var _externalIp = require('../util/external-ip');
161
-
162
- var _serviceHost = require('../util/service-host');
163
-
164
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
+ var _serviceHost = require("../util/service-host");
165
42
 
166
43
  /**
167
44
  * A Navy instance
168
45
  * @public
169
46
  */
170
- var Navy = exports.Navy = function (_EventEmitter) {
171
- (0, _inherits3.default)(Navy, _EventEmitter);
47
+ class Navy extends _eventemitter.EventEmitter2 {
48
+ /**
49
+ * The name of the current Navy.
50
+ * @public
51
+ */
172
52
 
173
53
  /**
174
54
  * The normalised name of the current Navy (name without whitespaces).
175
55
  * @public
176
56
  */
177
- function Navy(name) {
178
- (0, _classCallCheck3.default)(this, Navy);
179
-
180
- var _this = (0, _possibleConstructorReturn3.default)(this, (Navy.__proto__ || (0, _getPrototypeOf2.default)(Navy)).call(this, {
181
- maxListeners: _maxSafeInteger2.default,
57
+ constructor(name) {
58
+ super({
59
+ maxListeners: Number.MAX_SAFE_INTEGER,
182
60
  wildcard: true,
183
61
  delimiter: '.'
184
- }));
185
-
186
- _this.name = name;
187
- _this.normalisedName = (0, _util.normaliseNavyName)(name);
188
-
189
- _this._pluginsLoaded = false;
190
- _this._registeredCommands = {};
191
- _this._registeredMiddleware = [];
192
- return _this;
62
+ });
63
+ this.name = name;
64
+ this.normalisedName = (0, _util.normaliseNavyName)(name);
65
+ this._pluginsLoaded = false;
66
+ this._registeredCommands = {};
67
+ this._registeredMiddleware = [];
193
68
  }
194
69
 
70
+ async ensurePluginsLoaded() {
71
+ if (this._pluginsLoaded) return;
72
+ const navyFile = await this.getNavyFile();
73
+ if (!navyFile) return;
74
+ await (0, _pluginInterface.loadPlugins)(this, navyFile);
75
+ this._pluginsLoaded = true;
76
+ }
195
77
  /**
196
- * The name of the current Navy.
78
+ * Returns the current State for this Navy.
197
79
  * @public
198
80
  */
199
81
 
200
82
 
201
- (0, _createClass3.default)(Navy, [{
202
- key: 'ensurePluginsLoaded',
203
- value: function () {
204
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
205
- var navyFile;
206
- return _regenerator2.default.wrap(function _callee$(_context) {
207
- while (1) {
208
- switch (_context.prev = _context.next) {
209
- case 0:
210
- if (!this._pluginsLoaded) {
211
- _context.next = 2;
212
- break;
213
- }
83
+ async getState() {
84
+ return await (0, _state.getState)(this.normalisedName);
85
+ }
86
+ /**
87
+ * Returns an instance of the driver in use by this navy.
88
+ * Returns null if the navy hasn't been launched yet.
89
+ */
214
90
 
215
- return _context.abrupt('return');
216
91
 
217
- case 2:
218
- _context.next = 4;
219
- return this.getNavyFile();
92
+ async getDriver() {
93
+ const envState = await this.getState();
220
94
 
221
- case 4:
222
- navyFile = _context.sent;
95
+ if (!envState || !envState.driver) {
96
+ return null;
97
+ }
223
98
 
224
- if (navyFile) {
225
- _context.next = 7;
226
- break;
227
- }
99
+ const createDriver = (0, _driver.resolveDriverFromName)(envState.driver);
228
100
 
229
- return _context.abrupt('return');
101
+ if (!createDriver) {
102
+ return null;
103
+ }
230
104
 
231
- case 7:
232
- _context.next = 9;
233
- return (0, _pluginInterface.loadPlugins)(this, navyFile);
105
+ return createDriver(this);
106
+ }
107
+ /**
108
+ * Same as getDriver but will throw an error if the driver cannot be determined.
109
+ */
234
110
 
235
- case 9:
236
111
 
237
- this._pluginsLoaded = true;
112
+ async safeGetDriver() {
113
+ const driver = await this.getDriver();
238
114
 
239
- case 10:
240
- case 'end':
241
- return _context.stop();
242
- }
243
- }
244
- }, _callee, this);
245
- }));
115
+ if (!(await this.isInitialised())) {
116
+ throw new _errors.NavyNotInitialisedError(this.name);
117
+ }
246
118
 
247
- function ensurePluginsLoaded() {
248
- return _ref.apply(this, arguments);
249
- }
119
+ (0, _invariant.default)(driver, "NO_DRIVER: Couldn't determine driver for navy %s", this.name);
120
+ return driver;
121
+ }
250
122
 
251
- return ensurePluginsLoaded;
252
- }()
253
-
254
- /**
255
- * Returns the current State for this Navy.
256
- * @public
257
- */
258
-
259
- }, {
260
- key: 'getState',
261
- value: function () {
262
- var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
263
- return _regenerator2.default.wrap(function _callee2$(_context2) {
264
- while (1) {
265
- switch (_context2.prev = _context2.next) {
266
- case 0:
267
- _context2.next = 2;
268
- return (0, _state.getState)(this.normalisedName);
269
-
270
- case 2:
271
- return _context2.abrupt('return', _context2.sent);
272
-
273
- case 3:
274
- case 'end':
275
- return _context2.stop();
276
- }
277
- }
278
- }, _callee2, this);
279
- }));
123
+ async getConfigProvider() {
124
+ const envState = await this.getState();
280
125
 
281
- function getState() {
282
- return _ref2.apply(this, arguments);
283
- }
126
+ if (!envState || !envState.configProvider) {
127
+ return null;
128
+ }
284
129
 
285
- return getState;
286
- }()
287
-
288
- /**
289
- * Returns an instance of the driver in use by this navy.
290
- * Returns null if the navy hasn't been launched yet.
291
- */
292
-
293
- }, {
294
- key: 'getDriver',
295
- value: function () {
296
- var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
297
- var envState, createDriver;
298
- return _regenerator2.default.wrap(function _callee3$(_context3) {
299
- while (1) {
300
- switch (_context3.prev = _context3.next) {
301
- case 0:
302
- _context3.next = 2;
303
- return this.getState();
304
-
305
- case 2:
306
- envState = _context3.sent;
307
-
308
- if (!(!envState || !envState.driver)) {
309
- _context3.next = 5;
310
- break;
311
- }
312
-
313
- return _context3.abrupt('return', null);
314
-
315
- case 5:
316
- createDriver = (0, _driver.resolveDriverFromName)(envState.driver);
317
-
318
- if (createDriver) {
319
- _context3.next = 8;
320
- break;
321
- }
322
-
323
- return _context3.abrupt('return', null);
324
-
325
- case 8:
326
- return _context3.abrupt('return', createDriver(this));
327
-
328
- case 9:
329
- case 'end':
330
- return _context3.stop();
331
- }
332
- }
333
- }, _callee3, this);
334
- }));
130
+ const createConfigProvider = (0, _configProvider.resolveConfigProviderFromName)(envState.configProvider);
335
131
 
336
- function getDriver() {
337
- return _ref3.apply(this, arguments);
338
- }
132
+ if (!createConfigProvider) {
133
+ return null;
134
+ }
339
135
 
340
- return getDriver;
341
- }()
136
+ return createConfigProvider(this);
137
+ }
342
138
 
343
- /**
344
- * Same as getDriver but will throw an error if the driver cannot be determined.
345
- */
139
+ async getNavyFile() {
140
+ if (!(await this.isInitialised())) {
141
+ throw new _errors.NavyNotInitialisedError(this.name);
142
+ }
346
143
 
347
- }, {
348
- key: 'safeGetDriver',
349
- value: function () {
350
- var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
351
- var driver;
352
- return _regenerator2.default.wrap(function _callee4$(_context4) {
353
- while (1) {
354
- switch (_context4.prev = _context4.next) {
355
- case 0:
356
- _context4.next = 2;
357
- return this.getDriver();
144
+ const configProvider = await this.getConfigProvider();
145
+ (0, _invariant.default)(configProvider, "NO_CONFIG_PROVIDER: Couldn't determine config provider for navy %s", this.name);
146
+ const navyFilePath = await configProvider.getNavyFilePath();
358
147
 
359
- case 2:
360
- driver = _context4.sent;
361
- _context4.next = 5;
362
- return this.isInitialised();
148
+ try {
149
+ // $FlowIgnore: entry point to Navyfile.js has to be dynamic
150
+ return require(navyFilePath);
151
+ } catch (ex) {
152
+ return null;
153
+ }
154
+ }
155
+ /**
156
+ * Saves a new State for this Navy.
157
+ * @public
158
+ */
363
159
 
364
- case 5:
365
- if (_context4.sent) {
366
- _context4.next = 7;
367
- break;
368
- }
369
160
 
370
- throw new _errors.NavyNotInitialisedError(this.name);
161
+ async saveState(state) {
162
+ await (0, _state.saveState)(this.normalisedName, state);
163
+ await (0, _middleware.middlewareRunner)(this, state);
164
+ }
165
+ /**
166
+ * Registers a custom CLI command with the given name and callback function.
167
+ * Any command registered can be run using `navy run [name]`.
168
+ * @public
169
+ */
371
170
 
372
- case 7:
373
171
 
374
- (0, _invariant2.default)(driver, 'NO_DRIVER: Couldn\'t determine driver for navy %s', this.name);
172
+ registerCommand(name, action) {
173
+ this._registeredCommands[name] = action;
174
+ }
175
+ /**
176
+ * Registers a middleware reducer function. See [Writing Plugins](docs/writing-plugins.md).
177
+ * @public
178
+ */
375
179
 
376
- return _context4.abrupt('return', driver);
377
180
 
378
- case 9:
379
- case 'end':
380
- return _context4.stop();
381
- }
382
- }
383
- }, _callee4, this);
384
- }));
181
+ registerMiddleware(middlewareFn) {
182
+ this._registeredMiddleware.push(middlewareFn);
183
+ }
385
184
 
386
- function safeGetDriver() {
387
- return _ref4.apply(this, arguments);
388
- }
185
+ async invokeCommand(name, args) {
186
+ if (!this._registeredCommands[name]) {
187
+ throw new _errors.NavyError('Unknown command "' + name + '"');
188
+ }
389
189
 
390
- return safeGetDriver;
391
- }()
392
- }, {
393
- key: 'getConfigProvider',
394
- value: function () {
395
- var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5() {
396
- var envState, createConfigProvider;
397
- return _regenerator2.default.wrap(function _callee5$(_context5) {
398
- while (1) {
399
- switch (_context5.prev = _context5.next) {
400
- case 0:
401
- _context5.next = 2;
402
- return this.getState();
403
-
404
- case 2:
405
- envState = _context5.sent;
406
-
407
- if (!(!envState || !envState.configProvider)) {
408
- _context5.next = 5;
409
- break;
410
- }
411
-
412
- return _context5.abrupt('return', null);
413
-
414
- case 5:
415
- createConfigProvider = (0, _configProvider.resolveConfigProviderFromName)(envState.configProvider);
416
-
417
- if (createConfigProvider) {
418
- _context5.next = 8;
419
- break;
420
- }
421
-
422
- return _context5.abrupt('return', null);
423
-
424
- case 8:
425
- return _context5.abrupt('return', createConfigProvider(this));
426
-
427
- case 9:
428
- case 'end':
429
- return _context5.stop();
430
- }
431
- }
432
- }, _callee5, this);
433
- }));
190
+ await this._registeredCommands[name](args);
191
+ }
192
+ /**
193
+ * Returns whether this Navy is initialised and ready to launch services.
194
+ * @public
195
+ */
434
196
 
435
- function getConfigProvider() {
436
- return _ref5.apply(this, arguments);
437
- }
438
197
 
439
- return getConfigProvider;
440
- }()
441
- }, {
442
- key: 'getNavyFile',
443
- value: function () {
444
- var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6() {
445
- var configProvider, navyFilePath;
446
- return _regenerator2.default.wrap(function _callee6$(_context6) {
447
- while (1) {
448
- switch (_context6.prev = _context6.next) {
449
- case 0:
450
- _context6.next = 2;
451
- return this.isInitialised();
452
-
453
- case 2:
454
- if (_context6.sent) {
455
- _context6.next = 4;
456
- break;
457
- }
458
-
459
- throw new _errors.NavyNotInitialisedError(this.name);
460
-
461
- case 4:
462
- _context6.next = 6;
463
- return this.getConfigProvider();
464
-
465
- case 6:
466
- configProvider = _context6.sent;
467
-
468
-
469
- (0, _invariant2.default)(configProvider, 'NO_CONFIG_PROVIDER: Couldn\'t determine config provider for navy %s', this.name);
470
-
471
- _context6.next = 10;
472
- return configProvider.getNavyFilePath();
473
-
474
- case 10:
475
- navyFilePath = _context6.sent;
476
- _context6.prev = 11;
477
- return _context6.abrupt('return', require(navyFilePath));
478
-
479
- case 15:
480
- _context6.prev = 15;
481
- _context6.t0 = _context6['catch'](11);
482
- return _context6.abrupt('return', null);
483
-
484
- case 18:
485
- case 'end':
486
- return _context6.stop();
487
- }
488
- }
489
- }, _callee6, this, [[11, 15]]);
490
- }));
198
+ async isInitialised() {
199
+ return (await this.getState()) != null;
200
+ }
201
+ /**
202
+ * Initialises this Navy with the given State.
203
+ * @public
204
+ */
491
205
 
492
- function getNavyFile() {
493
- return _ref6.apply(this, arguments);
494
- }
495
206
 
496
- return getNavyFile;
497
- }()
498
-
499
- /**
500
- * Saves a new State for this Navy.
501
- * @public
502
- */
503
-
504
- }, {
505
- key: 'saveState',
506
- value: function () {
507
- var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(state) {
508
- return _regenerator2.default.wrap(function _callee7$(_context7) {
509
- while (1) {
510
- switch (_context7.prev = _context7.next) {
511
- case 0:
512
- _context7.next = 2;
513
- return (0, _state.saveState)(this.normalisedName, state);
514
-
515
- case 2:
516
- _context7.next = 4;
517
- return (0, _middleware.middlewareRunner)(this, state);
518
-
519
- case 4:
520
- case 'end':
521
- return _context7.stop();
522
- }
523
- }
524
- }, _callee7, this);
525
- }));
207
+ async initialise(opts) {
208
+ const state = {
209
+ services: {},
210
+ ...opts,
211
+ driver: 'docker-compose'
212
+ };
213
+ await (0, _state.saveState)(this.normalisedName, state);
214
+ }
215
+ /**
216
+ * Deletes the state for this Navy. It won't be possible to interact with this Navy after calling this function
217
+ * unless you re-initialise it.
218
+ * @public
219
+ */
526
220
 
527
- function saveState(_x) {
528
- return _ref7.apply(this, arguments);
529
- }
530
221
 
531
- return saveState;
532
- }()
222
+ async delete() {
223
+ await (0, _state.deleteState)(this.normalisedName);
224
+ }
225
+ /**
226
+ * Launches the given services for this Navy.
227
+ * @public
228
+ */
229
+
230
+
231
+ async launch(serviceNames, opts) {
232
+ if (!serviceNames) serviceNames = await this.getLaunchedServiceNames();
233
+ const availableServices = await (await this.safeGetDriver()).getAvailableServiceNames();
234
+ const validServiceNames = serviceNames.filter(serviceName => {
235
+ if (availableServices.indexOf(serviceName) !== -1) {
236
+ return true;
237
+ }
533
238
 
534
- /**
535
- * Registers a custom CLI command with the given name and callback function.
536
- * Any command registered can be run using `navy run [name]`.
537
- * @public
538
- */
239
+ console.log(`Unknown service name: ${serviceName}`);
240
+ return false;
241
+ });
242
+ const allServiceNamesInvalid = serviceNames.length > 0 && validServiceNames.length === 0;
539
243
 
540
- }, {
541
- key: 'registerCommand',
542
- value: function registerCommand(name, action) {
543
- this._registeredCommands[name] = action;
244
+ if (allServiceNamesInvalid) {
245
+ return;
544
246
  }
545
247
 
546
- /**
547
- * Registers a middleware reducer function. See [Writing Plugins](docs/writing-plugins.md).
548
- * @public
549
- */
248
+ const state = await this.getState();
550
249
 
551
- }, {
552
- key: 'registerMiddleware',
553
- value: function registerMiddleware(middlewareFn) {
554
- this._registeredMiddleware.push(middlewareFn);
250
+ if (state) {
251
+ await (0, _middleware.middlewareRunner)(this, state);
555
252
  }
556
- }, {
557
- key: 'invokeCommand',
558
- value: function () {
559
- var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(name, args) {
560
- return _regenerator2.default.wrap(function _callee8$(_context8) {
561
- while (1) {
562
- switch (_context8.prev = _context8.next) {
563
- case 0:
564
- if (this._registeredCommands[name]) {
565
- _context8.next = 2;
566
- break;
567
- }
568
-
569
- throw new _errors.NavyError('Unknown command "' + name + '"');
570
-
571
- case 2:
572
- _context8.next = 4;
573
- return this._registeredCommands[name](args);
574
-
575
- case 4:
576
- case 'end':
577
- return _context8.stop();
578
- }
579
- }
580
- }, _callee8, this);
581
- }));
582
253
 
583
- function invokeCommand(_x2, _x3) {
584
- return _ref8.apply(this, arguments);
585
- }
254
+ await (await this.safeGetDriver()).launch(validServiceNames, opts);
255
+ await (0, _httpProxy.reconfigureHTTPProxy)();
256
+ }
257
+ /**
258
+ * @deprecated
259
+ */
586
260
 
587
- return invokeCommand;
588
- }()
589
-
590
- /**
591
- * Returns whether this Navy is initialised and ready to launch services.
592
- * @public
593
- */
594
-
595
- }, {
596
- key: 'isInitialised',
597
- value: function () {
598
- var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9() {
599
- return _regenerator2.default.wrap(function _callee9$(_context9) {
600
- while (1) {
601
- switch (_context9.prev = _context9.next) {
602
- case 0:
603
- _context9.next = 2;
604
- return this.getState();
605
-
606
- case 2:
607
- _context9.t0 = _context9.sent;
608
- return _context9.abrupt('return', _context9.t0 != null);
609
-
610
- case 4:
611
- case 'end':
612
- return _context9.stop();
613
- }
614
- }
615
- }, _callee9, this);
616
- }));
617
261
 
618
- function isInitialised() {
619
- return _ref9.apply(this, arguments);
620
- }
262
+ async relaunch(opts) {
263
+ return await this.reconfigure(opts);
264
+ }
265
+ /**
266
+ * Relaunches (reconfigures) all of the services running in this Navy.
267
+ * This will pick up any changes to the compose configuration.
268
+ * @public
269
+ */
621
270
 
622
- return isInitialised;
623
- }()
624
-
625
- /**
626
- * Initialises this Navy with the given State.
627
- * @public
628
- */
629
-
630
- }, {
631
- key: 'initialise',
632
- value: function () {
633
- var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(opts) {
634
- var state;
635
- return _regenerator2.default.wrap(function _callee10$(_context10) {
636
- while (1) {
637
- switch (_context10.prev = _context10.next) {
638
- case 0:
639
- state = (0, _extends9.default)({
640
- services: {}
641
- }, opts, {
642
- driver: 'docker-compose'
643
- });
644
- _context10.next = 3;
645
- return (0, _state.saveState)(this.normalisedName, state);
646
-
647
- case 3:
648
- case 'end':
649
- return _context10.stop();
650
- }
651
- }
652
- }, _callee10, this);
653
- }));
654
271
 
655
- function initialise(_x4) {
656
- return _ref10.apply(this, arguments);
657
- }
272
+ async reconfigure(opts) {
273
+ const services = await this.getLaunchedServiceNames();
658
274
 
659
- return initialise;
660
- }()
661
-
662
- /**
663
- * Deletes the state for this Navy. It won't be possible to interact with this Navy after calling this function
664
- * unless you re-initialise it.
665
- * @public
666
- */
667
-
668
- }, {
669
- key: 'delete',
670
- value: function () {
671
- var _ref11 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee11() {
672
- return _regenerator2.default.wrap(function _callee11$(_context11) {
673
- while (1) {
674
- switch (_context11.prev = _context11.next) {
675
- case 0:
676
- _context11.next = 2;
677
- return (0, _state.deleteState)(this.normalisedName);
678
-
679
- case 2:
680
- case 'end':
681
- return _context11.stop();
682
- }
683
- }
684
- }, _callee11, this);
685
- }));
275
+ if (services.length === 0) {
276
+ return;
277
+ }
686
278
 
687
- function _delete() {
688
- return _ref11.apply(this, arguments);
689
- }
279
+ await this.launch(undefined, opts);
280
+ }
281
+ /**
282
+ * Destroys all of the services in this Navy and deletes the state.
283
+ * @public
284
+ */
690
285
 
691
- return _delete;
692
- }()
693
-
694
- /**
695
- * Launches the given services for this Navy.
696
- * @public
697
- */
698
-
699
- }, {
700
- key: 'launch',
701
- value: function () {
702
- var _ref12 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee12(serviceNames, opts) {
703
- var availableServices, validServiceNames, allServiceNamesInvalid, state;
704
- return _regenerator2.default.wrap(function _callee12$(_context12) {
705
- while (1) {
706
- switch (_context12.prev = _context12.next) {
707
- case 0:
708
- if (serviceNames) {
709
- _context12.next = 4;
710
- break;
711
- }
712
-
713
- _context12.next = 3;
714
- return this.getLaunchedServiceNames();
715
-
716
- case 3:
717
- serviceNames = _context12.sent;
718
-
719
- case 4:
720
- _context12.next = 6;
721
- return this.safeGetDriver();
722
-
723
- case 6:
724
- _context12.next = 8;
725
- return _context12.sent.getAvailableServiceNames();
726
-
727
- case 8:
728
- availableServices = _context12.sent;
729
- validServiceNames = serviceNames.filter(function (serviceName) {
730
- if (availableServices.indexOf(serviceName) !== -1) {
731
- return true;
732
- }
733
- console.log('Unknown service name: ' + serviceName);
734
- return false;
735
- });
736
- allServiceNamesInvalid = serviceNames.length > 0 && validServiceNames.length === 0;
737
-
738
- if (!allServiceNamesInvalid) {
739
- _context12.next = 13;
740
- break;
741
- }
742
-
743
- return _context12.abrupt('return');
744
-
745
- case 13:
746
- _context12.next = 15;
747
- return this.getState();
748
-
749
- case 15:
750
- state = _context12.sent;
751
-
752
- if (!state) {
753
- _context12.next = 19;
754
- break;
755
- }
756
-
757
- _context12.next = 19;
758
- return (0, _middleware.middlewareRunner)(this, state);
759
-
760
- case 19:
761
- _context12.next = 21;
762
- return this.safeGetDriver();
763
-
764
- case 21:
765
- _context12.t0 = validServiceNames;
766
- _context12.t1 = opts;
767
- _context12.next = 25;
768
- return _context12.sent.launch(_context12.t0, _context12.t1);
769
-
770
- case 25:
771
- _context12.next = 27;
772
- return (0, _httpProxy.reconfigureHTTPProxy)();
773
-
774
- case 27:
775
- case 'end':
776
- return _context12.stop();
777
- }
778
- }
779
- }, _callee12, this);
780
- }));
781
286
 
782
- function launch(_x5, _x6) {
783
- return _ref12.apply(this, arguments);
784
- }
287
+ async destroy() {
288
+ if (!(await this.isInitialised())) {
289
+ throw new _errors.NavyNotInitialisedError(this.name);
290
+ }
785
291
 
786
- return launch;
787
- }()
788
-
789
- /**
790
- * @deprecated
791
- */
792
-
793
- }, {
794
- key: 'relaunch',
795
- value: function () {
796
- var _ref13 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee13(opts) {
797
- return _regenerator2.default.wrap(function _callee13$(_context13) {
798
- while (1) {
799
- switch (_context13.prev = _context13.next) {
800
- case 0:
801
- _context13.next = 2;
802
- return this.reconfigure(opts);
803
-
804
- case 2:
805
- return _context13.abrupt('return', _context13.sent);
806
-
807
- case 3:
808
- case 'end':
809
- return _context13.stop();
810
- }
811
- }
812
- }, _callee13, this);
813
- }));
292
+ await (0, _httpProxy.reconfigureHTTPProxy)({
293
+ navies: (await getLaunchedNavyNames()).filter(navy => navy !== this.normalisedName)
294
+ });
814
295
 
815
- function relaunch(_x7) {
816
- return _ref13.apply(this, arguments);
817
- }
296
+ try {
297
+ await (await this.safeGetDriver()).destroy();
298
+ } catch (ex) {}
818
299
 
819
- return relaunch;
820
- }()
821
-
822
- /**
823
- * Relaunches (reconfigures) all of the services running in this Navy.
824
- * This will pick up any changes to the compose configuration.
825
- * @public
826
- */
827
-
828
- }, {
829
- key: 'reconfigure',
830
- value: function () {
831
- var _ref14 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee14(opts) {
832
- var services;
833
- return _regenerator2.default.wrap(function _callee14$(_context14) {
834
- while (1) {
835
- switch (_context14.prev = _context14.next) {
836
- case 0:
837
- _context14.next = 2;
838
- return this.getLaunchedServiceNames();
839
-
840
- case 2:
841
- services = _context14.sent;
842
-
843
- if (!(services.length === 0)) {
844
- _context14.next = 5;
845
- break;
846
- }
847
-
848
- return _context14.abrupt('return');
849
-
850
- case 5:
851
- _context14.next = 7;
852
- return this.launch(undefined, opts);
853
-
854
- case 7:
855
- case 'end':
856
- return _context14.stop();
857
- }
858
- }
859
- }, _callee14, this);
860
- }));
300
+ await this.delete();
301
+ }
302
+ /**
303
+ * Returns a list of launched services for this Navy.
304
+ * @public
305
+ */
861
306
 
862
- function reconfigure(_x8) {
863
- return _ref14.apply(this, arguments);
864
- }
865
307
 
866
- return reconfigure;
867
- }()
868
-
869
- /**
870
- * Destroys all of the services in this Navy and deletes the state.
871
- * @public
872
- */
873
-
874
- }, {
875
- key: 'destroy',
876
- value: function () {
877
- var _ref15 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee15() {
878
- var _this2 = this;
879
-
880
- return _regenerator2.default.wrap(function _callee15$(_context15) {
881
- while (1) {
882
- switch (_context15.prev = _context15.next) {
883
- case 0:
884
- _context15.next = 2;
885
- return this.isInitialised();
886
-
887
- case 2:
888
- if (_context15.sent) {
889
- _context15.next = 4;
890
- break;
891
- }
892
-
893
- throw new _errors.NavyNotInitialisedError(this.name);
894
-
895
- case 4:
896
- _context15.t0 = _httpProxy.reconfigureHTTPProxy;
897
- _context15.next = 7;
898
- return getLaunchedNavyNames();
899
-
900
- case 7:
901
- _context15.t1 = function (navy) {
902
- return navy !== _this2.normalisedName;
903
- };
904
-
905
- _context15.t2 = _context15.sent.filter(_context15.t1);
906
- _context15.t3 = {
907
- navies: _context15.t2
908
- };
909
- _context15.next = 12;
910
- return (0, _context15.t0)(_context15.t3);
911
-
912
- case 12:
913
- _context15.prev = 12;
914
- _context15.next = 15;
915
- return this.safeGetDriver();
916
-
917
- case 15:
918
- _context15.next = 17;
919
- return _context15.sent.destroy();
920
-
921
- case 17:
922
- _context15.next = 21;
923
- break;
924
-
925
- case 19:
926
- _context15.prev = 19;
927
- _context15.t4 = _context15['catch'](12);
928
-
929
- case 21:
930
- _context15.next = 23;
931
- return this.delete();
932
-
933
- case 23:
934
- case 'end':
935
- return _context15.stop();
936
- }
937
- }
938
- }, _callee15, this, [[12, 19]]);
939
- }));
308
+ async ps() {
309
+ return await (await this.safeGetDriver()).ps();
310
+ }
311
+ /**
312
+ * Starts the given services.
313
+ * @public
314
+ */
940
315
 
941
- function destroy() {
942
- return _ref15.apply(this, arguments);
943
- }
944
316
 
945
- return destroy;
946
- }()
947
-
948
- /**
949
- * Returns a list of launched services for this Navy.
950
- * @public
951
- */
952
-
953
- }, {
954
- key: 'ps',
955
- value: function () {
956
- var _ref16 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee16() {
957
- return _regenerator2.default.wrap(function _callee16$(_context16) {
958
- while (1) {
959
- switch (_context16.prev = _context16.next) {
960
- case 0:
961
- _context16.next = 2;
962
- return this.safeGetDriver();
963
-
964
- case 2:
965
- _context16.next = 4;
966
- return _context16.sent.ps();
967
-
968
- case 4:
969
- return _context16.abrupt('return', _context16.sent);
970
-
971
- case 5:
972
- case 'end':
973
- return _context16.stop();
974
- }
975
- }
976
- }, _callee16, this);
977
- }));
317
+ async start(services) {
318
+ if (!services) services = await this.getLaunchedServiceNames();
319
+ await (0, _httpProxy.reconfigureHTTPProxy)();
320
+ await (await this.safeGetDriver()).start(services);
321
+ }
322
+ /**
323
+ * Stops the given services.
324
+ * @public
325
+ */
978
326
 
979
- function ps() {
980
- return _ref16.apply(this, arguments);
981
- }
982
327
 
983
- return ps;
984
- }()
985
-
986
- /**
987
- * Starts the given services.
988
- * @public
989
- */
990
-
991
- }, {
992
- key: 'start',
993
- value: function () {
994
- var _ref17 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee17(services) {
995
- return _regenerator2.default.wrap(function _callee17$(_context17) {
996
- while (1) {
997
- switch (_context17.prev = _context17.next) {
998
- case 0:
999
- if (services) {
1000
- _context17.next = 4;
1001
- break;
1002
- }
1003
-
1004
- _context17.next = 3;
1005
- return this.getLaunchedServiceNames();
1006
-
1007
- case 3:
1008
- services = _context17.sent;
1009
-
1010
- case 4:
1011
- _context17.next = 6;
1012
- return (0, _httpProxy.reconfigureHTTPProxy)();
1013
-
1014
- case 6:
1015
- _context17.next = 8;
1016
- return this.safeGetDriver();
1017
-
1018
- case 8:
1019
- _context17.t0 = services;
1020
- _context17.next = 11;
1021
- return _context17.sent.start(_context17.t0);
1022
-
1023
- case 11:
1024
- case 'end':
1025
- return _context17.stop();
1026
- }
1027
- }
1028
- }, _callee17, this);
1029
- }));
328
+ async stop(services) {
329
+ if (!services) services = await this.getLaunchedServiceNames();
330
+ await (await this.safeGetDriver()).stop(services);
331
+ }
332
+ /**
333
+ * Restarts the given services.
334
+ * @public
335
+ */
1030
336
 
1031
- function start(_x9) {
1032
- return _ref17.apply(this, arguments);
1033
- }
1034
337
 
1035
- return start;
1036
- }()
1037
-
1038
- /**
1039
- * Stops the given services.
1040
- * @public
1041
- */
1042
-
1043
- }, {
1044
- key: 'stop',
1045
- value: function () {
1046
- var _ref18 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee18(services) {
1047
- return _regenerator2.default.wrap(function _callee18$(_context18) {
1048
- while (1) {
1049
- switch (_context18.prev = _context18.next) {
1050
- case 0:
1051
- if (services) {
1052
- _context18.next = 4;
1053
- break;
1054
- }
1055
-
1056
- _context18.next = 3;
1057
- return this.getLaunchedServiceNames();
1058
-
1059
- case 3:
1060
- services = _context18.sent;
1061
-
1062
- case 4:
1063
- _context18.next = 6;
1064
- return this.safeGetDriver();
1065
-
1066
- case 6:
1067
- _context18.t0 = services;
1068
- _context18.next = 9;
1069
- return _context18.sent.stop(_context18.t0);
1070
-
1071
- case 9:
1072
- case 'end':
1073
- return _context18.stop();
1074
- }
1075
- }
1076
- }, _callee18, this);
1077
- }));
338
+ async restart(services) {
339
+ if (!services) services = await this.getLaunchedServiceNames();
340
+ await (await this.safeGetDriver()).restart(services);
341
+ }
342
+ /**
343
+ * Forcefully stops the given services.
344
+ * @public
345
+ */
1078
346
 
1079
- function stop(_x10) {
1080
- return _ref18.apply(this, arguments);
1081
- }
1082
347
 
1083
- return stop;
1084
- }()
1085
-
1086
- /**
1087
- * Restarts the given services.
1088
- * @public
1089
- */
1090
-
1091
- }, {
1092
- key: 'restart',
1093
- value: function () {
1094
- var _ref19 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee19(services) {
1095
- return _regenerator2.default.wrap(function _callee19$(_context19) {
1096
- while (1) {
1097
- switch (_context19.prev = _context19.next) {
1098
- case 0:
1099
- if (services) {
1100
- _context19.next = 4;
1101
- break;
1102
- }
1103
-
1104
- _context19.next = 3;
1105
- return this.getLaunchedServiceNames();
1106
-
1107
- case 3:
1108
- services = _context19.sent;
1109
-
1110
- case 4:
1111
- _context19.next = 6;
1112
- return this.safeGetDriver();
1113
-
1114
- case 6:
1115
- _context19.t0 = services;
1116
- _context19.next = 9;
1117
- return _context19.sent.restart(_context19.t0);
1118
-
1119
- case 9:
1120
- case 'end':
1121
- return _context19.stop();
1122
- }
1123
- }
1124
- }, _callee19, this);
1125
- }));
348
+ async kill(services) {
349
+ if (!services) services = await this.getLaunchedServiceNames();
350
+ await (await this.safeGetDriver()).kill(services);
351
+ }
352
+ /**
353
+ * Removes the given services. Requires the services to be stopped first.
354
+ * @public
355
+ */
1126
356
 
1127
- function restart(_x11) {
1128
- return _ref19.apply(this, arguments);
1129
- }
1130
357
 
1131
- return restart;
1132
- }()
1133
-
1134
- /**
1135
- * Forcefully stops the given services.
1136
- * @public
1137
- */
1138
-
1139
- }, {
1140
- key: 'kill',
1141
- value: function () {
1142
- var _ref20 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee20(services) {
1143
- return _regenerator2.default.wrap(function _callee20$(_context20) {
1144
- while (1) {
1145
- switch (_context20.prev = _context20.next) {
1146
- case 0:
1147
- if (services) {
1148
- _context20.next = 4;
1149
- break;
1150
- }
1151
-
1152
- _context20.next = 3;
1153
- return this.getLaunchedServiceNames();
1154
-
1155
- case 3:
1156
- services = _context20.sent;
1157
-
1158
- case 4:
1159
- _context20.next = 6;
1160
- return this.safeGetDriver();
1161
-
1162
- case 6:
1163
- _context20.t0 = services;
1164
- _context20.next = 9;
1165
- return _context20.sent.kill(_context20.t0);
1166
-
1167
- case 9:
1168
- case 'end':
1169
- return _context20.stop();
1170
- }
1171
- }
1172
- }, _callee20, this);
1173
- }));
358
+ async rm(services) {
359
+ if (!services) services = await this.getLaunchedServiceNames();
360
+ await (await this.safeGetDriver()).rm(services);
361
+ }
362
+ /**
363
+ * Makes sure the images for the given services are up to date, and restarts any running
364
+ * services with new images.
365
+ * @public
366
+ */
1174
367
 
1175
- function kill(_x12) {
1176
- return _ref20.apply(this, arguments);
1177
- }
1178
368
 
1179
- return kill;
1180
- }()
1181
-
1182
- /**
1183
- * Removes the given services. Requires the services to be stopped first.
1184
- * @public
1185
- */
1186
-
1187
- }, {
1188
- key: 'rm',
1189
- value: function () {
1190
- var _ref21 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee21(services) {
1191
- return _regenerator2.default.wrap(function _callee21$(_context21) {
1192
- while (1) {
1193
- switch (_context21.prev = _context21.next) {
1194
- case 0:
1195
- if (services) {
1196
- _context21.next = 4;
1197
- break;
1198
- }
1199
-
1200
- _context21.next = 3;
1201
- return this.getLaunchedServiceNames();
1202
-
1203
- case 3:
1204
- services = _context21.sent;
1205
-
1206
- case 4:
1207
- _context21.next = 6;
1208
- return this.safeGetDriver();
1209
-
1210
- case 6:
1211
- _context21.t0 = services;
1212
- _context21.next = 9;
1213
- return _context21.sent.rm(_context21.t0);
1214
-
1215
- case 9:
1216
- case 'end':
1217
- return _context21.stop();
1218
- }
1219
- }
1220
- }, _callee21, this);
1221
- }));
369
+ async update(services) {
370
+ // update all images by default
371
+ if (!services) services = await this.getAvailableServiceNames();
372
+ await (await this.safeGetDriver()).update(services);
373
+ }
1222
374
 
1223
- function rm(_x13) {
1224
- return _ref21.apply(this, arguments);
1225
- }
375
+ async spawnLogStream(services) {
376
+ if (!services) services = await this.getLaunchedServiceNames();
377
+ await (await this.safeGetDriver()).spawnLogStream(services);
378
+ }
379
+ /**
380
+ * Locks down the given service to the given docker image tag.
381
+ * @public
382
+ */
1226
383
 
1227
- return rm;
1228
- }()
1229
-
1230
- /**
1231
- * Makes sure the images for the given services are up to date, and restarts any running
1232
- * services with new images.
1233
- * @public
1234
- */
1235
-
1236
- }, {
1237
- key: 'update',
1238
- value: function () {
1239
- var _ref22 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee22(services) {
1240
- return _regenerator2.default.wrap(function _callee22$(_context22) {
1241
- while (1) {
1242
- switch (_context22.prev = _context22.next) {
1243
- case 0:
1244
- if (services) {
1245
- _context22.next = 4;
1246
- break;
1247
- }
1248
-
1249
- _context22.next = 3;
1250
- return this.getAvailableServiceNames();
1251
-
1252
- case 3:
1253
- services = _context22.sent;
1254
-
1255
- case 4:
1256
- _context22.next = 6;
1257
- return this.safeGetDriver();
1258
-
1259
- case 6:
1260
- _context22.t0 = services;
1261
- _context22.next = 9;
1262
- return _context22.sent.update(_context22.t0);
1263
-
1264
- case 9:
1265
- case 'end':
1266
- return _context22.stop();
1267
- }
1268
- }
1269
- }, _callee22, this);
1270
- }));
1271
384
 
1272
- function update(_x14) {
1273
- return _ref22.apply(this, arguments);
385
+ async useTag(service, tag) {
386
+ const state = (await this.getState()) || {};
387
+ await this.saveState({ ...state,
388
+ services: { ...state.services,
389
+ [service]: { ...(state.services || {})[service],
390
+ _tag: tag
391
+ }
1274
392
  }
393
+ });
394
+ await this.kill([service]);
395
+ await this.update([service]); // pull and launch
396
+ }
397
+ /**
398
+ * Resets the version of the given service if `useTag` was used.
399
+ * @public
400
+ */
1275
401
 
1276
- return update;
1277
- }()
1278
- }, {
1279
- key: 'spawnLogStream',
1280
- value: function () {
1281
- var _ref23 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee23(services) {
1282
- return _regenerator2.default.wrap(function _callee23$(_context23) {
1283
- while (1) {
1284
- switch (_context23.prev = _context23.next) {
1285
- case 0:
1286
- if (services) {
1287
- _context23.next = 4;
1288
- break;
1289
- }
1290
-
1291
- _context23.next = 3;
1292
- return this.getLaunchedServiceNames();
1293
-
1294
- case 3:
1295
- services = _context23.sent;
1296
-
1297
- case 4:
1298
- _context23.next = 6;
1299
- return this.safeGetDriver();
1300
-
1301
- case 6:
1302
- _context23.t0 = services;
1303
- _context23.next = 9;
1304
- return _context23.sent.spawnLogStream(_context23.t0);
1305
-
1306
- case 9:
1307
- case 'end':
1308
- return _context23.stop();
1309
- }
1310
- }
1311
- }, _callee23, this);
1312
- }));
1313
402
 
1314
- function spawnLogStream(_x15) {
1315
- return _ref23.apply(this, arguments);
403
+ async resetTag(service) {
404
+ const state = (await this.getState()) || {};
405
+ await this.saveState({ ...state,
406
+ services: { ...state.services,
407
+ [service]: { ...(state.services || {})[service],
408
+ _tag: undefined
409
+ }
1316
410
  }
411
+ });
412
+ await this.kill([service]);
413
+ await this.launch([service], {
414
+ noDeps: true
415
+ });
416
+ }
1317
417
 
1318
- return spawnLogStream;
1319
- }()
1320
-
1321
- /**
1322
- * Locks down the given service to the given docker image tag.
1323
- * @public
1324
- */
1325
-
1326
- }, {
1327
- key: 'useTag',
1328
- value: function () {
1329
- var _ref24 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee24(service, tag) {
1330
- var state;
1331
- return _regenerator2.default.wrap(function _callee24$(_context24) {
1332
- while (1) {
1333
- switch (_context24.prev = _context24.next) {
1334
- case 0:
1335
- _context24.next = 2;
1336
- return this.getState();
1337
-
1338
- case 2:
1339
- _context24.t0 = _context24.sent;
1340
-
1341
- if (_context24.t0) {
1342
- _context24.next = 5;
1343
- break;
1344
- }
1345
-
1346
- _context24.t0 = {};
1347
-
1348
- case 5:
1349
- state = _context24.t0;
1350
- _context24.next = 8;
1351
- return this.saveState((0, _extends9.default)({}, state, {
1352
- services: (0, _extends9.default)({}, state.services, (0, _defineProperty3.default)({}, service, (0, _extends9.default)({}, (state.services || {})[service], {
1353
- _tag: tag
1354
- })))
1355
- }));
1356
-
1357
- case 8:
1358
- _context24.next = 10;
1359
- return this.kill([service]);
1360
-
1361
- case 10:
1362
- _context24.next = 12;
1363
- return this.update([service]);
1364
-
1365
- case 12:
1366
- case 'end':
1367
- return _context24.stop();
1368
- }
418
+ async usePort(service, privatePort, externalPort) {
419
+ const state = (await this.getState()) || {};
420
+ await this.saveState({ ...state,
421
+ services: { ...state.services,
422
+ [service]: { ...(state.services || {})[service],
423
+ _ports: { ...((state.services || {})[service] || {})._ports,
424
+ [privatePort]: externalPort
1369
425
  }
1370
- }, _callee24, this);
1371
- }));
1372
-
1373
- function useTag(_x16, _x17) {
1374
- return _ref24.apply(this, arguments);
426
+ }
1375
427
  }
428
+ });
429
+ await this.kill([service]);
430
+ await this.launch([service], {
431
+ noDeps: true
432
+ });
433
+ }
1376
434
 
1377
- return useTag;
1378
- }()
1379
-
1380
- /**
1381
- * Resets the version of the given service if `useTag` was used.
1382
- * @public
1383
- */
1384
-
1385
- }, {
1386
- key: 'resetTag',
1387
- value: function () {
1388
- var _ref25 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee25(service) {
1389
- var state;
1390
- return _regenerator2.default.wrap(function _callee25$(_context25) {
1391
- while (1) {
1392
- switch (_context25.prev = _context25.next) {
1393
- case 0:
1394
- _context25.next = 2;
1395
- return this.getState();
1396
-
1397
- case 2:
1398
- _context25.t0 = _context25.sent;
1399
-
1400
- if (_context25.t0) {
1401
- _context25.next = 5;
1402
- break;
1403
- }
1404
-
1405
- _context25.t0 = {};
1406
-
1407
- case 5:
1408
- state = _context25.t0;
1409
- _context25.next = 8;
1410
- return this.saveState((0, _extends9.default)({}, state, {
1411
- services: (0, _extends9.default)({}, state.services, (0, _defineProperty3.default)({}, service, (0, _extends9.default)({}, (state.services || {})[service], {
1412
- _tag: undefined
1413
- })))
1414
- }));
1415
-
1416
- case 8:
1417
- _context25.next = 10;
1418
- return this.kill([service]);
1419
-
1420
- case 10:
1421
- _context25.next = 12;
1422
- return this.launch([service], { noDeps: true });
1423
-
1424
- case 12:
1425
- case 'end':
1426
- return _context25.stop();
1427
- }
435
+ async resetPort(service, privatePort) {
436
+ const state = (await this.getState()) || {};
437
+ await this.saveState({ ...state,
438
+ services: { ...state.services,
439
+ [service]: { ...(state.services || {})[service],
440
+ _ports: { ...((state.services || {})[service] || {})._ports,
441
+ [privatePort]: undefined
1428
442
  }
1429
- }, _callee25, this);
1430
- }));
1431
-
1432
- function resetTag(_x18) {
1433
- return _ref25.apply(this, arguments);
443
+ }
1434
444
  }
445
+ });
446
+ await this.kill([service]);
447
+ await this.launch([service], {
448
+ noDeps: true
449
+ });
450
+ }
451
+ /**
452
+ * Waits for the given services to be healthy. Resolves when all services are healthy.
453
+ * @public
454
+ */
1435
455
 
1436
- return resetTag;
1437
- }()
1438
- }, {
1439
- key: 'usePort',
1440
- value: function () {
1441
- var _ref26 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee26(service, privatePort, externalPort) {
1442
- var state;
1443
- return _regenerator2.default.wrap(function _callee26$(_context26) {
1444
- while (1) {
1445
- switch (_context26.prev = _context26.next) {
1446
- case 0:
1447
- _context26.next = 2;
1448
- return this.getState();
1449
-
1450
- case 2:
1451
- _context26.t0 = _context26.sent;
1452
-
1453
- if (_context26.t0) {
1454
- _context26.next = 5;
1455
- break;
1456
- }
1457
-
1458
- _context26.t0 = {};
1459
-
1460
- case 5:
1461
- state = _context26.t0;
1462
- _context26.next = 8;
1463
- return this.saveState((0, _extends9.default)({}, state, {
1464
- services: (0, _extends9.default)({}, state.services, (0, _defineProperty3.default)({}, service, (0, _extends9.default)({}, (state.services || {})[service], {
1465
- _ports: (0, _extends9.default)({}, ((state.services || {})[service] || {})._ports, (0, _defineProperty3.default)({}, privatePort, externalPort))
1466
- })))
1467
- }));
1468
-
1469
- case 8:
1470
- _context26.next = 10;
1471
- return this.kill([service]);
1472
-
1473
- case 10:
1474
- _context26.next = 12;
1475
- return this.launch([service], { noDeps: true });
1476
-
1477
- case 12:
1478
- case 'end':
1479
- return _context26.stop();
1480
- }
1481
- }
1482
- }, _callee26, this);
1483
- }));
1484
456
 
1485
- function usePort(_x19, _x20, _x21) {
1486
- return _ref26.apply(this, arguments);
1487
- }
457
+ async waitForHealthy(services, progressCallback, retryConfig = {
458
+ factor: 1.1,
459
+ retries: 30,
460
+ minTimeout: 200
461
+ }) {
462
+ if (services == null) {
463
+ services = (await this.ps()).filter(service => service && service.raw && service.raw.State.Health).map(service => service.name);
464
+ }
1488
465
 
1489
- return usePort;
1490
- }()
1491
- }, {
1492
- key: 'resetPort',
1493
- value: function () {
1494
- var _ref27 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee27(service, privatePort) {
1495
- var state;
1496
- return _regenerator2.default.wrap(function _callee27$(_context27) {
1497
- while (1) {
1498
- switch (_context27.prev = _context27.next) {
1499
- case 0:
1500
- _context27.next = 2;
1501
- return this.getState();
1502
-
1503
- case 2:
1504
- _context27.t0 = _context27.sent;
1505
-
1506
- if (_context27.t0) {
1507
- _context27.next = 5;
1508
- break;
1509
- }
1510
-
1511
- _context27.t0 = {};
1512
-
1513
- case 5:
1514
- state = _context27.t0;
1515
- _context27.next = 8;
1516
- return this.saveState((0, _extends9.default)({}, state, {
1517
- services: (0, _extends9.default)({}, state.services, (0, _defineProperty3.default)({}, service, (0, _extends9.default)({}, (state.services || {})[service], {
1518
- _ports: (0, _extends9.default)({}, ((state.services || {})[service] || {})._ports, (0, _defineProperty3.default)({}, privatePort, undefined))
1519
- })))
1520
- }));
1521
-
1522
- case 8:
1523
- _context27.next = 10;
1524
- return this.kill([service]);
1525
-
1526
- case 10:
1527
- _context27.next = 12;
1528
- return this.launch([service], { noDeps: true });
1529
-
1530
- case 12:
1531
- case 'end':
1532
- return _context27.stop();
1533
- }
1534
- }
1535
- }, _callee27, this);
1536
- }));
466
+ try {
467
+ await (0, _promiseRetry.default)(retryConfig, async retry => {
468
+ const ps = await this.ps();
469
+ const specifiedServices = ps.filter(service => services && services.indexOf(service.name) !== -1);
470
+ const servicesWithoutHealthInfo = specifiedServices.filter(service => !service.raw || !service.raw.State.Health).map(service => service.name);
1537
471
 
1538
- function resetPort(_x22, _x23) {
1539
- return _ref27.apply(this, arguments);
1540
- }
472
+ if (servicesWithoutHealthInfo.length > 0) {
473
+ throw new _errors.NavyError('The specified services don\'t have health checks: ' + servicesWithoutHealthInfo.join(', '));
474
+ }
1541
475
 
1542
- return resetPort;
1543
- }()
1544
-
1545
- /**
1546
- * Waits for the given services to be healthy. Resolves when all services are healthy.
1547
- * @public
1548
- */
1549
-
1550
- }, {
1551
- key: 'waitForHealthy',
1552
- value: function () {
1553
- var _ref28 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee29(services, progressCallback) {
1554
- var _this3 = this;
1555
-
1556
- var retryConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { factor: 1.1, retries: 30, minTimeout: 200 };
1557
- return _regenerator2.default.wrap(function _callee29$(_context29) {
1558
- while (1) {
1559
- switch (_context29.prev = _context29.next) {
1560
- case 0:
1561
- if (!(services == null)) {
1562
- _context29.next = 6;
1563
- break;
1564
- }
1565
-
1566
- _context29.next = 3;
1567
- return this.ps();
1568
-
1569
- case 3:
1570
- _context29.t0 = function (service) {
1571
- return service && service.raw && service.raw.State.Health;
1572
- };
1573
-
1574
- _context29.t1 = function (service) {
1575
- return service.name;
1576
- };
1577
-
1578
- services = _context29.sent.filter(_context29.t0).map(_context29.t1);
1579
-
1580
- case 6:
1581
- _context29.prev = 6;
1582
- _context29.next = 9;
1583
- return (0, _promiseRetry2.default)(retryConfig, function () {
1584
- var _ref29 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee28(retry) {
1585
- var ps, specifiedServices, servicesWithoutHealthInfo, serviceHealth, unhealthy;
1586
- return _regenerator2.default.wrap(function _callee28$(_context28) {
1587
- while (1) {
1588
- switch (_context28.prev = _context28.next) {
1589
- case 0:
1590
- _context28.next = 2;
1591
- return _this3.ps();
1592
-
1593
- case 2:
1594
- ps = _context28.sent;
1595
- specifiedServices = ps.filter(function (service) {
1596
- return services && services.indexOf(service.name) !== -1;
1597
- });
1598
- servicesWithoutHealthInfo = specifiedServices.filter(function (service) {
1599
- return !service.raw || !service.raw.State.Health;
1600
- }).map(function (service) {
1601
- return service.name;
1602
- });
1603
-
1604
- if (!(servicesWithoutHealthInfo.length > 0)) {
1605
- _context28.next = 7;
1606
- break;
1607
- }
1608
-
1609
- throw new _errors.NavyError('The specified services don\'t have health checks: ' + servicesWithoutHealthInfo.join(', '));
1610
-
1611
- case 7:
1612
- serviceHealth = specifiedServices.map(function (service) {
1613
- return {
1614
- service: service.name,
1615
- health: service.raw && service.raw.State.Health.Status
1616
- };
1617
- });
1618
-
1619
-
1620
- if (progressCallback) progressCallback(serviceHealth);
1621
-
1622
- unhealthy = serviceHealth.filter(function (service) {
1623
- return service.health !== 'healthy';
1624
- });
1625
-
1626
-
1627
- if (unhealthy.length !== 0) {
1628
- retry('Timed out waiting for services to be healthy. Unhealthy services: ' + unhealthy.map(function (s) {
1629
- return s.service;
1630
- }).join(', '));
1631
- }
1632
-
1633
- case 11:
1634
- case 'end':
1635
- return _context28.stop();
1636
- }
1637
- }
1638
- }, _callee28, _this3);
1639
- }));
1640
-
1641
- return function (_x27) {
1642
- return _ref29.apply(this, arguments);
1643
- };
1644
- }());
1645
-
1646
- case 9:
1647
- _context29.next = 14;
1648
- break;
1649
-
1650
- case 11:
1651
- _context29.prev = 11;
1652
- _context29.t2 = _context29['catch'](6);
1653
- throw new _errors.NavyError(_context29.t2.message);
1654
-
1655
- case 14:
1656
- return _context29.abrupt('return', true);
1657
-
1658
- case 15:
1659
- case 'end':
1660
- return _context29.stop();
1661
- }
1662
- }
1663
- }, _callee29, this, [[6, 11]]);
1664
- }));
476
+ const serviceHealth = specifiedServices.map(service => ({
477
+ service: service.name,
478
+ health: service.raw && service.raw.State.Health.Status
479
+ }));
480
+ if (progressCallback) progressCallback(serviceHealth);
481
+ const unhealthy = serviceHealth.filter(service => service.health !== 'healthy');
1665
482
 
1666
- function waitForHealthy(_x24, _x25) {
1667
- return _ref28.apply(this, arguments);
1668
- }
483
+ if (unhealthy.length !== 0) {
484
+ retry('Timed out waiting for services to be healthy. Unhealthy services: ' + unhealthy.map(s => s.service).join(', '));
485
+ }
486
+ });
487
+ } catch (e) {
488
+ throw new _errors.NavyError(e.message);
489
+ }
1669
490
 
1670
- return waitForHealthy;
1671
- }()
1672
-
1673
- /**
1674
- * Returns the external IP for accessing Docker and running services.
1675
- * @public
1676
- */
1677
-
1678
- }, {
1679
- key: 'externalIP',
1680
- value: function () {
1681
- var _ref30 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee30() {
1682
- var config;
1683
- return _regenerator2.default.wrap(function _callee30$(_context30) {
1684
- while (1) {
1685
- switch (_context30.prev = _context30.next) {
1686
- case 0:
1687
- _context30.next = 2;
1688
- return (0, _config.getConfig)();
1689
-
1690
- case 2:
1691
- config = _context30.sent;
1692
- _context30.next = 5;
1693
- return (0, _externalIp.getExternalIP)(config.externalIP);
1694
-
1695
- case 5:
1696
- return _context30.abrupt('return', _context30.sent);
1697
-
1698
- case 6:
1699
- case 'end':
1700
- return _context30.stop();
1701
- }
1702
- }
1703
- }, _callee30, this);
1704
- }));
491
+ return true;
492
+ }
493
+ /**
494
+ * Returns the external IP for accessing Docker and running services.
495
+ * @public
496
+ */
1705
497
 
1706
- function externalIP() {
1707
- return _ref30.apply(this, arguments);
1708
- }
1709
498
 
1710
- return externalIP;
1711
- }()
1712
-
1713
- /**
1714
- * Returns the external port for the given service and internal private port.
1715
- * @public
1716
- */
1717
-
1718
- }, {
1719
- key: 'port',
1720
- value: function () {
1721
- var _ref31 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee31(service, privatePort) {
1722
- var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
1723
- return _regenerator2.default.wrap(function _callee31$(_context31) {
1724
- while (1) {
1725
- switch (_context31.prev = _context31.next) {
1726
- case 0:
1727
- _context31.next = 2;
1728
- return this.safeGetDriver();
1729
-
1730
- case 2:
1731
- _context31.t0 = service;
1732
- _context31.t1 = privatePort;
1733
- _context31.t2 = index;
1734
- _context31.next = 7;
1735
- return _context31.sent.port(_context31.t0, _context31.t1, _context31.t2);
1736
-
1737
- case 7:
1738
- return _context31.abrupt('return', _context31.sent);
1739
-
1740
- case 8:
1741
- case 'end':
1742
- return _context31.stop();
1743
- }
1744
- }
1745
- }, _callee31, this);
1746
- }));
499
+ async externalIP() {
500
+ const config = await (0, _config.getConfig)();
501
+ return await (0, _externalIp.getExternalIP)(config.externalIP);
502
+ }
503
+ /**
504
+ * Returns the external port for the given service and internal private port.
505
+ * @public
506
+ */
1747
507
 
1748
- function port(_x28, _x29) {
1749
- return _ref31.apply(this, arguments);
1750
- }
1751
508
 
1752
- return port;
1753
- }()
1754
-
1755
- /**
1756
- * Returns the URL for the given service which can be used to access it if it exposes
1757
- * a HTTP server.
1758
- * @public
1759
- */
1760
-
1761
- }, {
1762
- key: 'url',
1763
- value: function () {
1764
- var _ref32 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee32(service) {
1765
- var ps;
1766
- return _regenerator2.default.wrap(function _callee32$(_context32) {
1767
- while (1) {
1768
- switch (_context32.prev = _context32.next) {
1769
- case 0:
1770
- _context32.next = 2;
1771
- return this.safeGetDriver();
1772
-
1773
- case 2:
1774
- _context32.t0 = service;
1775
- _context32.next = 5;
1776
- return _context32.sent.ps(_context32.t0);
1777
-
1778
- case 5:
1779
- ps = _context32.sent;
1780
- _context32.t1 = (0, _serviceHost.getUrlFromService)(ps.pop());
1781
-
1782
- if (_context32.t1) {
1783
- _context32.next = 15;
1784
- break;
1785
- }
1786
-
1787
- _context32.t2 = _serviceHost.createUrlForService;
1788
- _context32.t3 = service;
1789
- _context32.t4 = this.normalisedName;
1790
- _context32.next = 13;
1791
- return this.externalIP();
1792
-
1793
- case 13:
1794
- _context32.t5 = _context32.sent;
1795
- _context32.t1 = (0, _context32.t2)(_context32.t3, _context32.t4, _context32.t5);
1796
-
1797
- case 15:
1798
- return _context32.abrupt('return', _context32.t1);
1799
-
1800
- case 16:
1801
- case 'end':
1802
- return _context32.stop();
1803
- }
1804
- }
1805
- }, _callee32, this);
1806
- }));
509
+ async port(service, privatePort, index = 1) {
510
+ return await (await this.safeGetDriver()).port(service, privatePort, index);
511
+ }
512
+ /**
513
+ * Returns the URL for the given service which can be used to access it if it exposes
514
+ * a HTTP server.
515
+ * @public
516
+ */
1807
517
 
1808
- function url(_x31) {
1809
- return _ref32.apply(this, arguments);
1810
- }
1811
518
 
1812
- return url;
1813
- }()
1814
-
1815
- /**
1816
- * Returns an array of the names of the launched services for this Navy.
1817
- * @public
1818
- */
1819
-
1820
- }, {
1821
- key: 'getLaunchedServiceNames',
1822
- value: function () {
1823
- var _ref33 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee33() {
1824
- return _regenerator2.default.wrap(function _callee33$(_context33) {
1825
- while (1) {
1826
- switch (_context33.prev = _context33.next) {
1827
- case 0:
1828
- _context33.next = 2;
1829
- return this.safeGetDriver();
1830
-
1831
- case 2:
1832
- _context33.next = 4;
1833
- return _context33.sent.getLaunchedServiceNames();
1834
-
1835
- case 4:
1836
- return _context33.abrupt('return', _context33.sent);
1837
-
1838
- case 5:
1839
- case 'end':
1840
- return _context33.stop();
1841
- }
1842
- }
1843
- }, _callee33, this);
1844
- }));
519
+ async url(service) {
520
+ const ps = await (await this.safeGetDriver()).ps(service);
521
+ return (0, _serviceHost.getUrlFromService)(ps.pop()) || (0, _serviceHost.createUrlForService)(service, this.normalisedName, await this.externalIP());
522
+ }
523
+ /**
524
+ * Returns an array of the names of the launched services for this Navy.
525
+ * @public
526
+ */
1845
527
 
1846
- function getLaunchedServiceNames() {
1847
- return _ref33.apply(this, arguments);
1848
- }
1849
528
 
1850
- return getLaunchedServiceNames;
1851
- }()
1852
-
1853
- /**
1854
- * Returns an array of the names of all of the possible services for this Navy.
1855
- * @public
1856
- */
1857
-
1858
- }, {
1859
- key: 'getAvailableServiceNames',
1860
- value: function () {
1861
- var _ref34 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee34() {
1862
- return _regenerator2.default.wrap(function _callee34$(_context34) {
1863
- while (1) {
1864
- switch (_context34.prev = _context34.next) {
1865
- case 0:
1866
- _context34.next = 2;
1867
- return this.safeGetDriver();
1868
-
1869
- case 2:
1870
- _context34.next = 4;
1871
- return _context34.sent.getAvailableServiceNames();
1872
-
1873
- case 4:
1874
- return _context34.abrupt('return', _context34.sent);
1875
-
1876
- case 5:
1877
- case 'end':
1878
- return _context34.stop();
1879
- }
1880
- }
1881
- }, _callee34, this);
1882
- }));
529
+ async getLaunchedServiceNames() {
530
+ return await (await this.safeGetDriver()).getLaunchedServiceNames();
531
+ }
532
+ /**
533
+ * Returns an array of the names of all of the possible services for this Navy.
534
+ * @public
535
+ */
1883
536
 
1884
- function getAvailableServiceNames() {
1885
- return _ref34.apply(this, arguments);
1886
- }
1887
537
 
1888
- return getAvailableServiceNames;
1889
- }()
1890
- }]);
1891
- return Navy;
1892
- }(_eventemitter.EventEmitter2);
538
+ async getAvailableServiceNames() {
539
+ return await (await this.safeGetDriver()).getAvailableServiceNames();
540
+ }
1893
541
 
542
+ }
1894
543
  /**
1895
544
  * Returns a `Navy` instance from the given Navy name.
1896
545
  * @public
1897
546
  */
1898
547
 
1899
548
 
1900
- function getNavy(navyName) {
1901
- (0, _invariant2.default)(navyName, 'NO_NAVY_PROVIDED: No Navy provided');
549
+ exports.Navy = Navy;
1902
550
 
551
+ function getNavy(navyName) {
552
+ (0, _invariant.default)(navyName, "NO_NAVY_PROVIDED: No Navy provided");
1903
553
  return new Navy(navyName);
554
+ }
555
+ /**
556
+ * Returns an array of `Navy` instances which are currently imported and launched.
557
+ * @public
558
+ */
559
+
560
+
561
+ async function getLaunchedNavies() {
562
+ try {
563
+ const navyNames = await _fs.default.readdirAsync((0, _state.pathToNavys)());
564
+ return navyNames.filter(node => _fs.default.lstatSync((0, _state.pathToNavy)(node)).isDirectory()).map(name => getNavy(name));
565
+ } catch (ex) {
566
+ return [];
567
+ }
568
+ }
569
+ /**
570
+ * Returns an array of names of Navies which are currently imported and launched.
571
+ * @public
572
+ */
573
+
574
+
575
+ async function getLaunchedNavyNames() {
576
+ try {
577
+ return await _fs.default.readdirAsync((0, _state.pathToNavys)());
578
+ } catch (ex) {
579
+ return [];
580
+ }
1904
581
  }