navy 6.0.0 → 7.0.0-alpha.2

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 (149) hide show
  1. package/lib/__tests__/config-provider.js +75 -0
  2. package/lib/__tests__/config.js +130 -0
  3. package/lib/__tests__/driver-logging.js +148 -0
  4. package/lib/__tests__/driver.js +19 -0
  5. package/lib/__tests__/errors.js +49 -0
  6. package/lib/__tests__/http-proxy.js +214 -0
  7. package/lib/__tests__/index.js +25 -0
  8. package/lib/__tests__/service.js +16 -0
  9. package/lib/cli/__tests__/develop.js +239 -0
  10. package/lib/cli/__tests__/external-ip.js +68 -0
  11. package/lib/cli/__tests__/health.js +257 -0
  12. package/lib/cli/__tests__/https.js +210 -0
  13. package/lib/cli/__tests__/import.js +110 -0
  14. package/lib/cli/__tests__/index.js +118 -0
  15. package/lib/cli/__tests__/lan-ip.js +90 -0
  16. package/lib/cli/__tests__/launch.js +179 -0
  17. package/lib/cli/__tests__/live.js +155 -0
  18. package/lib/cli/__tests__/local-ip.js +72 -0
  19. package/lib/cli/__tests__/logs.js +52 -0
  20. package/lib/cli/__tests__/open.js +65 -0
  21. package/lib/cli/__tests__/program.js +472 -0
  22. package/lib/cli/__tests__/ps.js +345 -0
  23. package/lib/cli/__tests__/refresh-config.js +95 -0
  24. package/lib/cli/__tests__/run.js +54 -0
  25. package/lib/cli/__tests__/status.js +204 -0
  26. package/lib/cli/__tests__/updates.js +243 -0
  27. package/lib/cli/__tests__/wait-for-healthy.js +134 -0
  28. package/lib/cli/config/__tests__/index.js +275 -0
  29. package/lib/cli/config/__tests__/wrapper.js +53 -0
  30. package/lib/cli/config/index.js +19 -37
  31. package/lib/cli/config/wrapper.js +0 -6
  32. package/lib/cli/develop.js +7 -21
  33. package/lib/cli/doctor/__tests__/clean-compose-files.js +78 -0
  34. package/lib/cli/doctor/__tests__/index.js +67 -0
  35. package/lib/cli/doctor/__tests__/invalid-compose-config.js +103 -0
  36. package/lib/cli/doctor/__tests__/invalid-state.js +83 -0
  37. package/lib/cli/doctor/__tests__/util.js +91 -0
  38. package/lib/cli/doctor/clean-compose-files.js +5 -13
  39. package/lib/cli/doctor/index.js +0 -12
  40. package/lib/cli/doctor/invalid-compose-config.js +0 -4
  41. package/lib/cli/doctor/invalid-state.js +0 -6
  42. package/lib/cli/doctor/util.js +0 -10
  43. package/lib/cli/external-ip.js +0 -4
  44. package/lib/cli/health.js +0 -12
  45. package/lib/cli/https.js +9 -25
  46. package/lib/cli/import.js +0 -12
  47. package/lib/cli/index.js +0 -9
  48. package/lib/cli/lan-ip.js +2 -8
  49. package/lib/cli/launch.js +0 -9
  50. package/lib/cli/live.js +6 -16
  51. package/lib/cli/local-ip.js +2 -7
  52. package/lib/cli/logs.js +0 -3
  53. package/lib/cli/open.js +2 -7
  54. package/lib/cli/program.js +73 -101
  55. package/lib/cli/ps.js +1 -21
  56. package/lib/cli/refresh-config.js +0 -7
  57. package/lib/cli/run.js +0 -3
  58. package/lib/cli/status.js +0 -11
  59. package/lib/cli/updates.js +0 -22
  60. package/lib/cli/util/__tests__/get-or-initialise-navy.js +66 -0
  61. package/lib/cli/util/__tests__/import.js +123 -0
  62. package/lib/cli/util/__tests__/index.js +17 -0
  63. package/lib/cli/util/__tests__/merge-action-options.js +47 -0
  64. package/lib/cli/util/__tests__/reconfigure.js +78 -0
  65. package/lib/cli/util/get-or-initialise-navy.js +0 -7
  66. package/lib/cli/util/import.js +0 -9
  67. package/lib/cli/util/index.js +0 -2
  68. package/lib/cli/util/merge-action-options.js +20 -0
  69. package/lib/cli/util/reconfigure.js +0 -4
  70. package/lib/cli/wait-for-healthy.js +0 -21
  71. package/lib/client/registry/__tests__/get-credentials.js +62 -0
  72. package/lib/client/registry/__tests__/get-endpoint.js +124 -0
  73. package/lib/client/registry/__tests__/get-fat-manifest.js +67 -0
  74. package/lib/client/registry/__tests__/get-token.js +66 -0
  75. package/lib/client/registry/__tests__/helpers.js +26 -0
  76. package/lib/client/registry/get-credentials.js +3 -9
  77. package/lib/client/registry/get-endpoint.js +29 -63
  78. package/lib/client/registry/get-fat-manifest.js +2 -9
  79. package/lib/client/registry/get-token.js +2 -13
  80. package/lib/client/registry/helpers.js +0 -4
  81. package/lib/config-provider.js +0 -12
  82. package/lib/config-providers/filesystem/__tests__/index.js +176 -0
  83. package/lib/config-providers/filesystem/index.js +5 -23
  84. package/lib/config-providers/npm/__tests__/index.js +226 -0
  85. package/lib/config-providers/npm/__tests__/util.js +1 -2
  86. package/lib/config-providers/npm/index.js +12 -35
  87. package/lib/config-providers/npm/util.js +0 -3
  88. package/lib/config.js +4 -19
  89. package/lib/domain/__tests__/container-image.js +81 -0
  90. package/lib/domain/__tests__/oci-api-specification.js +23 -0
  91. package/lib/domain/container-image.js +8 -21
  92. package/lib/domain/oci-api-specification.js +3 -5
  93. package/lib/driver-logging.js +0 -19
  94. package/lib/driver.js +0 -4
  95. package/lib/drivers/docker-compose/__tests__/client.js +249 -0
  96. package/lib/drivers/docker-compose/__tests__/index.js +430 -0
  97. package/lib/drivers/docker-compose/client.js +0 -16
  98. package/lib/drivers/docker-compose/index.js +7 -49
  99. package/lib/errors.js +0 -10
  100. package/lib/http-proxy.js +28 -23
  101. package/lib/index.js +1 -9
  102. package/lib/middleware/__tests__/add-service-proxy-config.js +258 -0
  103. package/lib/middleware/__tests__/develop.js +120 -0
  104. package/lib/middleware/__tests__/helpers.js +154 -0
  105. package/lib/middleware/__tests__/port-override.js +125 -0
  106. package/lib/middleware/__tests__/set-env-vars.js +94 -0
  107. package/lib/middleware/__tests__/set-image.js +76 -0
  108. package/lib/middleware/__tests__/set-logging-driver.js +94 -0
  109. package/lib/middleware/__tests__/tag-override.js +92 -0
  110. package/lib/middleware/add-service-proxy-config.js +8 -16
  111. package/lib/middleware/develop.js +2 -5
  112. package/lib/middleware/helpers.js +6 -12
  113. package/lib/middleware/port-override.js +5 -8
  114. package/lib/middleware/set-env-vars.js +6 -6
  115. package/lib/middleware/set-image.js +4 -5
  116. package/lib/middleware/set-logging-driver.js +6 -6
  117. package/lib/middleware/tag-override.js +4 -6
  118. package/lib/navy/__tests__/default-middleware.js +40 -0
  119. package/lib/navy/__tests__/index.js +1612 -0
  120. package/lib/navy/__tests__/middleware.js +71 -0
  121. package/lib/navy/__tests__/plugin-interface.js +121 -0
  122. package/lib/navy/__tests__/state.js +103 -0
  123. package/lib/navy/__tests__/util.js +24 -0
  124. package/lib/navy/default-middleware.js +0 -10
  125. package/lib/navy/index.js +83 -138
  126. package/lib/navy/middleware.js +0 -6
  127. package/lib/navy/plugin-interface.js +2 -10
  128. package/lib/navy/state.js +12 -24
  129. package/lib/navy/util.js +0 -1
  130. package/lib/service.js +2 -3
  131. package/lib/util/__tests__/exec-async.js +83 -0
  132. package/lib/util/__tests__/external-ip.js +97 -2
  133. package/lib/util/__tests__/get-lan-ip.js +46 -0
  134. package/lib/util/__tests__/has-update.js +136 -0
  135. package/lib/util/__tests__/https.js +301 -0
  136. package/lib/util/__tests__/navyrc.js +45 -0
  137. package/lib/util/__tests__/service-host.js +63 -5
  138. package/lib/util/__tests__/table.js +44 -0
  139. package/lib/util/docker-client.js +2 -10
  140. package/lib/util/exec-async.js +0 -4
  141. package/lib/util/external-ip.js +8 -12
  142. package/lib/util/fs.js +1 -6
  143. package/lib/util/get-lan-ip.js +0 -5
  144. package/lib/util/has-update.js +2 -14
  145. package/lib/util/https.js +11 -55
  146. package/lib/util/navyrc.js +0 -5
  147. package/lib/util/service-host.js +0 -17
  148. package/lib/util/table.js +0 -6
  149. package/package.json +14 -13
package/lib/cli/open.js CHANGED
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = _default;
9
-
10
- var _opn = _interopRequireDefault(require("opn"));
11
-
8
+ var _open = _interopRequireDefault(require("open"));
12
9
  var _ = require("../");
13
-
14
10
  async function _default(service, opts) {
15
11
  const navy = (0, _.getNavy)(opts.navy);
16
- (0, _opn.default)(await navy.url(service));
12
+ (0, _open.default)(await navy.url(service));
17
13
  console.log(`🌐 Opening ${service}...`);
18
14
  }
19
-
20
15
  module.exports = exports.default;
@@ -1,24 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
- var _commander = _interopRequireDefault(require("commander"));
11
-
8
+ var _commander = require("commander");
12
9
  var _chalk = _interopRequireDefault(require("chalk"));
13
-
14
10
  var _errors = require("../errors");
15
-
16
11
  var _config = require("../config");
17
-
18
12
  var _driverLogging = require("../driver-logging");
19
-
20
13
  var _configProvider = require("../config-provider");
21
-
14
+ var _mergeActionOptions = require("./util/merge-action-options");
22
15
  const loadingLabelMap = {
23
16
  destroy: 'Destroying services...',
24
17
  start: 'Starting services...',
@@ -33,20 +26,32 @@ const loadingLabelMap = {
33
26
  usePort: 'Setting up port mapping...',
34
27
  resetPort: 'Resetting port mapping...'
35
28
  };
36
-
37
29
  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');
30
+ return stack?.split('\n')?.slice(1)?.join('\n');
31
+ }
32
+ function normaliseLazyRequireArgs(args) {
33
+ if (args.length === 0) return args;
34
+ const last = args[args.length - 1];
35
+ if (!last || typeof last.optsWithGlobals !== 'function') {
36
+ return args;
37
+ }
38
+ const command = last;
39
+ const rest = args.slice(0, -1);
40
+ if (rest.length === 0) {
41
+ return rest;
42
+ }
43
+ const lastOpt = rest[rest.length - 1];
44
+ if (lastOpt && typeof lastOpt === 'object' && !Array.isArray(lastOpt)) {
45
+ return [...rest.slice(0, -1), (0, _mergeActionOptions.mergeActionOptions)(lastOpt, command)];
46
+ }
47
+ return rest;
41
48
  }
42
-
43
49
  function wrapper(res) {
44
50
  if (res.catch) {
45
51
  res.catch(ex => {
46
52
  (0, _driverLogging.stopDriverLogging)({
47
53
  success: false
48
54
  });
49
-
50
55
  if (ex instanceof _errors.NavyError) {
51
56
  ex.prettyPrint();
52
57
  } else if (ex.name === 'Invariant Violation') {
@@ -62,14 +67,11 @@ function wrapper(res) {
62
67
  } else {
63
68
  console.error(ex.stack);
64
69
  }
65
-
66
70
  process.exit(1);
67
71
  });
68
72
  }
69
-
70
73
  return res;
71
74
  }
72
-
73
75
  function basicCliWrapper(fnName, wrapperOpts = {}) {
74
76
  const driverLogging = wrapperOpts.driverLogging == null ? true : wrapperOpts.driverLogging;
75
77
  return async function (maybeServices, ...args) {
@@ -77,27 +79,37 @@ function basicCliWrapper(fnName, wrapperOpts = {}) {
77
79
  getNavy
78
80
  } = require('../navy');
79
81
 
80
- const opts = args.length === 0 ? maybeServices : args[args.length - 1];
82
+ // commander v12 invokes action handlers with a trailing Command instance
83
+ // appended after the parsed options. Strip it and merge global options
84
+ // (e.g. `navy -e dev start`) into the opts object.
85
+ let command = null;
86
+ if (args.length > 0) {
87
+ const last = args[args.length - 1];
88
+ if (last && typeof last.optsWithGlobals === 'function') {
89
+ command = last;
90
+ args = args.slice(0, -1);
91
+ }
92
+ }
93
+ let opts = args.length === 0 ? maybeServices : args[args.length - 1];
81
94
  const otherArgs = args.slice(0, args.length - 1);
95
+ if (command && opts && typeof opts === 'object' && !Array.isArray(opts)) {
96
+ opts = (0, _mergeActionOptions.mergeActionOptions)(opts, command);
97
+ }
82
98
  const envName = opts.navy;
83
-
84
99
  if (wrapperOpts.serviceBasedAlias && maybeServices.length) {
85
100
  console.log(`This command should not be called with a list of services. calling '${wrapperOpts.serviceBasedAlias}' instead`);
86
101
  fnName = wrapperOpts.serviceBasedAlias;
87
102
  maybeServices = maybeServices.split(' ');
88
103
  }
89
-
90
104
  process.on('unhandledRejection', ex => {
91
105
  (0, _driverLogging.stopDriverLogging)({
92
106
  success: false
93
107
  });
94
-
95
108
  if (ex instanceof _errors.NavyError) {
96
109
  ex.prettyPrint();
97
110
  } else {
98
111
  console.error(ex.stack);
99
112
  }
100
-
101
113
  process.exit();
102
114
  });
103
115
  if (driverLogging) (0, _driverLogging.startDriverLogging)(loadingLabelMap[fnName]);
@@ -107,37 +119,30 @@ function basicCliWrapper(fnName, wrapperOpts = {}) {
107
119
  const returnVal = await navy[fnName](Array.isArray(maybeServices) && maybeServices.length === 0 ? undefined : maybeServices, ...otherArgs);
108
120
  await navy.emitAsync(`cli.after.${fnName}`, fnName);
109
121
  if (driverLogging) (0, _driverLogging.stopDriverLogging)();
110
-
111
122
  if (Array.isArray(returnVal)) {
112
123
  return console.log(returnVal.join('\n'));
113
124
  }
114
-
115
125
  if (returnVal != null) {
116
126
  console.log(returnVal);
117
127
  }
118
128
  };
119
129
  }
120
-
121
130
  function lazyRequire(path) {
122
131
  return function (...args) {
123
132
  const mod = require(path);
124
-
125
- return wrapper((mod.default || mod)(...args));
133
+ const normalised = normaliseLazyRequireArgs(args);
134
+ return wrapper((mod.default || mod)(...normalised));
126
135
  };
127
136
  }
128
-
129
137
  const defaultNavy = process.env.NAVY_NAME || (0, _config.getConfig)().defaultNavy;
130
-
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'));
132
-
138
+ _commander.program.option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy);
139
+ const importCommand = _commander.program.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'));
133
140
  (0, _configProvider.getImportCommandLineOptions)().forEach(opt => importCommand.option(...opt));
134
-
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(`
141
+ _commander.program.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
142
  This will prompt you for the services that you want to bring up.
137
143
  You can optionally provide the names of services to bring up which will disable the interactive prompt.
138
144
  `));
139
-
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', {
145
+ _commander.program.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
146
  serviceBasedAlias: 'kill'
142
147
  })).on('--help', () => console.log(`
143
148
  This will destroy an entire navy and all of its data and services.
@@ -147,36 +152,21 @@ _commander.default.command('destroy').option('-e, --navy [env]', `set the navy n
147
152
  $ navy destroy -e dev # destroy "dev" navy
148
153
  $ navy destroy -e test # destroy "test" navy
149
154
  `));
150
-
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'));
152
-
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'));
154
-
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'));
156
-
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'));
158
-
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'));
160
-
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'));
162
-
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'));
164
-
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'));
166
-
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'));
168
-
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'));
170
-
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'));
172
-
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'));
174
-
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'));
176
-
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'));
178
-
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(`
155
+ _commander.program.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'));
156
+ _commander.program.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'));
157
+ _commander.program.command('start [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Starts the given services').action(basicCliWrapper('start'));
158
+ _commander.program.command('stop [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Stops the given services').action(basicCliWrapper('stop'));
159
+ _commander.program.command('restart [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Restarts the given services').action(basicCliWrapper('restart'));
160
+ _commander.program.command('kill [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Kills the given services').action(basicCliWrapper('kill'));
161
+ _commander.program.command('rm [services...]').option('-e, --navy [env]', `set the navy name to be used [${defaultNavy}]`, defaultNavy).description('Removes the given services').action(basicCliWrapper('rm'));
162
+ _commander.program.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'));
163
+ _commander.program.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'));
164
+ _commander.program.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'));
165
+ _commander.program.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'));
166
+ _commander.program.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'));
167
+ _commander.program.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'));
168
+ _commander.program.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'));
169
+ _commander.program.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
170
  Examples:
181
171
  List urls of services that listen on https:
182
172
  $ navy https
@@ -187,57 +177,39 @@ _commander.default.command('https [services...]').option('-e, --navy [env]', `se
187
177
  Disable https for mywebservice
188
178
  $ navy https -d mywebservice
189
179
  `));
190
-
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'));
192
-
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'));
194
-
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', {
180
+ _commander.program.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'));
181
+ _commander.program.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'));
182
+ _commander.program.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
183
  driverLogging: false
197
184
  })).on('--help', () => console.log(`
198
185
  Examples:
199
186
  $ navy url mywebserver
200
187
  http://mywebserver.dev.127.0.0.1.nip.io
201
188
  `));
202
-
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(`
189
+ _commander.program.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
190
  Examples:
205
191
  $ navy open mywebserver
206
192
  Opening mywebserver...
207
193
  `));
208
-
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', {
194
+ _commander.program.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
195
  driverLogging: false
211
196
  })).on('--help', () => console.log(`
212
197
  Examples:
213
198
  $ navy port mywebserver 80
214
199
  35821
215
200
  `));
216
-
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', {
201
+ _commander.program.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
202
  driverLogging: false
219
203
  }));
220
-
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'));
222
-
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'));
224
-
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'));
226
-
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'));
228
-
229
- _commander.default.command('status').option('--json', 'output JSON instead of a table').description('List all of the imported navies').action(lazyRequire('./status'));
230
-
231
- _commander.default.command('doctor').description('Identifies and tries to fix some common issues which might cause Navy to stop working').action(lazyRequire('./doctor'));
232
-
233
- _commander.default.command('config').description('Modify and get Navy global config - run `navy config` for help').action(lazyRequire('./config/wrapper'));
234
-
235
- _commander.default.command('external-ip').description('Prints the external IP which services are accessible on').action(lazyRequire('./external-ip'));
236
-
237
- _commander.default.command('use-lan-ip').description('Use your LAN ip address for connecting to Navy services').action(lazyRequire('./lan-ip'));
238
-
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'));
240
-
241
- var _default = _commander.default;
242
- exports.default = _default;
204
+ _commander.program.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'));
205
+ _commander.program.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'));
206
+ _commander.program.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'));
207
+ _commander.program.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'));
208
+ _commander.program.command('status').option('--json', 'output JSON instead of a table').description('List all of the imported navies').action(lazyRequire('./status'));
209
+ _commander.program.command('doctor').description('Identifies and tries to fix some common issues which might cause Navy to stop working').action(lazyRequire('./doctor'));
210
+ _commander.program.command('config').description('Modify and get Navy global config - run `navy config` for help').action(lazyRequire('./config/wrapper'));
211
+ _commander.program.command('external-ip').description('Prints the external IP which services are accessible on').action(lazyRequire('./external-ip'));
212
+ _commander.program.command('use-lan-ip').description('Use your LAN ip address for connecting to Navy services').action(lazyRequire('./lan-ip'));
213
+ _commander.program.command('use-local-ip').description('Use your local ip address (127.0.0.1) for connecting to Navy services').action(lazyRequire('./local-ip'));
214
+ var _default = exports.default = _commander.program;
243
215
  module.exports = exports.default;
package/lib/cli/ps.js CHANGED
@@ -1,70 +1,50 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = _default;
9
-
10
8
  var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
9
  var _ = require("../");
13
-
14
10
  var _serviceHost = require("../util/service-host");
15
-
16
11
  var _table = _interopRequireDefault(require("../util/table"));
17
-
18
12
  const SMALL_WINDOW_COLUMNS = 185;
19
-
20
13
  function getStatus(service, state) {
21
14
  let statusString = service.status === 'exited' ? _chalk.default.red(service.status) : service.status;
22
-
23
15
  if (state && state.services && state.services[service.name]) {
24
16
  const serviceState = state.services[service.name];
25
-
26
17
  if (serviceState._develop) {
27
18
  statusString += ' ' + _chalk.default.yellow('(development)');
28
19
  }
29
-
30
20
  if (serviceState._tag) {
31
21
  statusString += ' ' + _chalk.default.cyan(`@ ${serviceState._tag}`);
32
22
  }
33
23
  }
34
-
35
24
  return statusString;
36
25
  }
37
-
38
26
  function getPorts(service) {
39
27
  if (!service || !service.raw || !service.raw.NetworkSettings || !service.raw.NetworkSettings.Ports) {
40
28
  return '-';
41
29
  }
42
-
43
30
  const ports = service.raw.NetworkSettings.Ports;
44
31
  const portKeys = Object.keys(ports);
45
32
  return portKeys.map(portKey => {
46
33
  return ports[portKey] ? `${ports[portKey].map(conf => conf.HostPort).join(', ')}->${portKey}` : portKey;
47
34
  }).join(', ');
48
35
  }
49
-
50
36
  const getDisplayUrl = serviceUrl => serviceUrl != null ? serviceUrl : '-';
51
-
52
37
  async function _default(opts) {
53
38
  const navy = (0, _.getNavy)(opts.navy);
54
39
  const ps = await navy.ps();
55
- const state = await navy.getState(); // $FlowIgnore getWindowSize not on type
56
-
40
+ const state = await navy.getState();
57
41
  const isSmallConsole = process.stdout.isTTY && process.stdout.getWindowSize()[0] < SMALL_WINDOW_COLUMNS;
58
-
59
42
  if (opts.json) {
60
43
  return console.log(JSON.stringify(ps, null, 2));
61
44
  }
62
-
63
45
  if (isSmallConsole) {
64
46
  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
47
  }
66
-
67
48
  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
49
  }
69
-
70
50
  module.exports = exports.default;
@@ -1,20 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = _default;
9
-
10
8
  var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
9
  var _invariant = _interopRequireDefault(require("invariant"));
13
-
14
10
  var _ = require("../");
15
-
16
11
  var _driverLogging = require("../driver-logging");
17
-
18
12
  async function _default(opts) {
19
13
  const navy = (0, _.getNavy)(opts.navy);
20
14
  const configProvider = await navy.getConfigProvider();
@@ -25,5 +19,4 @@ async function _default(opts) {
25
19
  (0, _driverLogging.stopDriverLogging)();
26
20
  console.log(_chalk.default.green(`Config refreshed for Navy "${opts.navy}"`));
27
21
  }
28
-
29
22
  module.exports = exports.default;
package/lib/cli/run.js CHANGED
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  var _ = require("../");
9
-
10
8
  async function _default(name, args, opts) {
11
9
  const navy = (0, _.getNavy)(opts.navy);
12
10
  await navy.ensurePluginsLoaded();
13
11
  await navy.invokeCommand(name, args);
14
12
  }
15
-
16
13
  module.exports = exports.default;
package/lib/cli/status.js CHANGED
@@ -1,31 +1,22 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = _default;
9
-
10
8
  var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
9
  var _ = require("../");
13
-
14
10
  var _table = _interopRequireDefault(require("../util/table"));
15
-
16
11
  var _config = require("../config");
17
-
18
12
  function formatNavyName(navy, defaultNavy) {
19
13
  if (navy.name === defaultNavy) {
20
14
  return `${navy.name} ${_chalk.default.cyan('(default)')}`;
21
15
  }
22
-
23
16
  return navy.name;
24
17
  }
25
-
26
18
  async function _default(opts) {
27
19
  const navies = await (0, _.getLaunchedNavies)();
28
-
29
20
  if (opts.json) {
30
21
  return console.log(JSON.stringify(await Promise.all(navies.map(async navy => {
31
22
  const ps = await navy.ps();
@@ -43,7 +34,6 @@ async function _default(opts) {
43
34
  };
44
35
  })), null, 2));
45
36
  }
46
-
47
37
  const config = await (0, _config.getConfig)();
48
38
  const {
49
39
  defaultNavy
@@ -57,5 +47,4 @@ async function _default(opts) {
57
47
  }));
58
48
  console.log((0, _table.default)([['NAME', 'ACTIVE', 'SERVICES', 'CONFIG PROVIDER', 'CONFIG LOCATION', 'URL'], ...rows]));
59
49
  }
60
-
61
50
  module.exports = exports.default;
@@ -1,29 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = _default;
9
-
10
8
  var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
9
  var _readline = _interopRequireDefault(require("readline"));
13
-
14
10
  var _cliSpinners = require("cli-spinners");
15
-
16
11
  var _ = require("../");
17
-
18
12
  var _table = _interopRequireDefault(require("../util/table"));
19
-
20
13
  var _hasUpdate = _interopRequireDefault(require("../util/has-update"));
21
-
22
14
  const debug = require('debug')('navy:updates');
23
-
24
15
  let spinnerIndex = 0;
25
16
  let spinnerFrame = _cliSpinners.dots.frames[0];
26
-
27
17
  function renderStatus(status) {
28
18
  if (status == null) {
29
19
  return _chalk.default.yellow(spinnerFrame) + ' ' + _chalk.default.dim('Checking...');
@@ -39,42 +29,32 @@ function renderStatus(status) {
39
29
  return _chalk.default.green('✔ Up to date');
40
30
  }
41
31
  }
42
-
43
32
  async function _default(opts) {
44
33
  const navy = (0, _.getNavy)(opts.navy);
45
34
  const navyFile = await navy.getNavyFile();
46
35
  const ps = await navy.ps();
47
36
  const updateStatus = {};
48
37
  let drawnLines = 0;
49
-
50
38
  function draw() {
51
39
  drawnLines = 0;
52
40
  const buffer = (0, _table.default)([['NAME', 'IMAGE', 'UPDATES'], ...ps.map(service => [service.name, service.image, renderStatus(updateStatus[service.id])])]);
53
41
  drawnLines = buffer.split('\n').length;
54
42
  console.log(buffer);
55
43
  }
56
-
57
44
  function redraw() {
58
45
  _readline.default.clearLine(process.stdout, 0);
59
-
60
46
  _readline.default.cursorTo(process.stdout, 0);
61
-
62
47
  for (let i = 0; i < drawnLines; i++) {
63
48
  _readline.default.moveCursor(process.stdout, 0, -1);
64
-
65
49
  _readline.default.clearLine(process.stdout, 0);
66
50
  }
67
-
68
51
  draw();
69
52
  }
70
-
71
53
  const spinner = setInterval(() => {
72
54
  spinnerIndex++;
73
-
74
55
  if (spinnerIndex >= _cliSpinners.dots.frames.length) {
75
56
  spinnerIndex = 0;
76
57
  }
77
-
78
58
  spinnerFrame = _cliSpinners.dots.frames[spinnerIndex];
79
59
  redraw();
80
60
  }, _cliSpinners.dots.interval);
@@ -84,7 +64,6 @@ async function _default(opts) {
84
64
  if (!service || !service.raw || !service.raw.Image) {
85
65
  return updateStatus[service.id] = 'NO_IMAGE';
86
66
  }
87
-
88
67
  updateStatus[service.id] = await (0, _hasUpdate.default)(service.image, service.raw.Image, navyFile);
89
68
  } catch (ex) {
90
69
  debug('Error checking update for', service.name, ex.stack || ex.message);
@@ -94,5 +73,4 @@ async function _default(opts) {
94
73
  redraw();
95
74
  clearInterval(spinner);
96
75
  }
97
-
98
76
  module.exports = exports.default;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _chai = require("chai");
5
+ var _sinon = _interopRequireDefault(require("sinon"));
6
+ var _proxyquire = _interopRequireDefault(require("proxyquire"));
7
+ /* eslint-env mocha */
8
+
9
+ describe('cli/util/get-or-initialise-navy', function () {
10
+ let sandbox;
11
+ let getNavyStub;
12
+ let importNavyStub;
13
+ let getImportOptionsForCLIStub;
14
+ let navyStub;
15
+ let getOrInitialiseNavy;
16
+ beforeEach(function () {
17
+ sandbox = _sinon.default.createSandbox();
18
+ navyStub = {
19
+ isInitialised: sandbox.stub()
20
+ };
21
+ getNavyStub = sandbox.stub().returns(navyStub);
22
+ importNavyStub = sandbox.stub().resolves();
23
+ getImportOptionsForCLIStub = sandbox.stub().resolves({
24
+ configProvider: 'filesystem',
25
+ path: '/cwd'
26
+ });
27
+ getOrInitialiseNavy = _proxyquire.default.noCallThru()('../get-or-initialise-navy', {
28
+ '../../': {
29
+ getNavy: getNavyStub
30
+ },
31
+ './import': {
32
+ importNavy: importNavyStub
33
+ },
34
+ '../../config-providers/filesystem': {
35
+ getImportOptionsForCLI: getImportOptionsForCLIStub
36
+ }
37
+ }).getOrInitialiseNavy;
38
+ });
39
+ afterEach(function () {
40
+ sandbox.restore();
41
+ });
42
+ describe('getOrInitialiseNavy', function () {
43
+ it('should return the navy without importing when already initialised', async function () {
44
+ navyStub.isInitialised.resolves(true);
45
+ const result = await getOrInitialiseNavy('env-1');
46
+ (0, _chai.expect)(result).to.equal(navyStub);
47
+ (0, _chai.expect)(getNavyStub.calledOnce).to.equal(true);
48
+ (0, _chai.expect)(getNavyStub.firstCall.args[0]).to.equal('env-1');
49
+ (0, _chai.expect)(importNavyStub.called).to.equal(false);
50
+ (0, _chai.expect)(getImportOptionsForCLIStub.called).to.equal(false);
51
+ });
52
+ it('should import the navy using filesystem provider opts when not initialised', async function () {
53
+ navyStub.isInitialised.resolves(false);
54
+ const result = await getOrInitialiseNavy('env-2');
55
+ (0, _chai.expect)(result).to.equal(navyStub);
56
+ (0, _chai.expect)(getImportOptionsForCLIStub.calledOnce).to.equal(true);
57
+ (0, _chai.expect)(getImportOptionsForCLIStub.firstCall.args[0]).to.eql({});
58
+ (0, _chai.expect)(importNavyStub.calledOnce).to.equal(true);
59
+ (0, _chai.expect)(importNavyStub.firstCall.args[0]).to.equal(navyStub);
60
+ (0, _chai.expect)(importNavyStub.firstCall.args[1]).to.eql({
61
+ configProvider: 'filesystem',
62
+ path: '/cwd'
63
+ });
64
+ });
65
+ });
66
+ });