@automattic/vip 2.30.0-dev1 → 2.31.0-dev1

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 (63) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/assets/dev-env.lando.template.yml.ejs +7 -2
  3. package/dist/bin/vip-dev-env-create.js +4 -1
  4. package/dist/bin/vip-dev-env-sync-sql.js +11 -18
  5. package/dist/bin/vip-export-sql.js +12 -11
  6. package/dist/bin/vip-import-sql.js +2 -2
  7. package/dist/bin/vip-import-validate-sql.js +2 -2
  8. package/dist/bin/vip-whoami.js +7 -10
  9. package/dist/bin/vip-wp.js +7 -5
  10. package/dist/bin/vip.js +9 -6
  11. package/dist/commands/dev-env-sync-sql.js +29 -15
  12. package/dist/commands/export-sql.js +1 -1
  13. package/dist/lib/analytics/clients/pendo.js +11 -20
  14. package/dist/lib/analytics/clients/tracks.js +12 -12
  15. package/dist/lib/analytics/index.js +9 -12
  16. package/dist/lib/api/app.js +10 -13
  17. package/dist/lib/api/cache-purge.js +3 -10
  18. package/dist/lib/api/feature-flags.js +6 -3
  19. package/dist/lib/api/http.js +10 -18
  20. package/dist/lib/api/user.js +3 -8
  21. package/dist/lib/api.js +13 -16
  22. package/dist/lib/app-logs/app-logs.js +3 -6
  23. package/dist/lib/app.js +2 -0
  24. package/dist/lib/cli/apiConfig.js +10 -7
  25. package/dist/lib/cli/config.js +2 -3
  26. package/dist/lib/cli/envAlias.js +11 -9
  27. package/dist/lib/cli/exit.js +4 -7
  28. package/dist/lib/cli/format.js +25 -26
  29. package/dist/lib/cli/progress.js +7 -3
  30. package/dist/lib/cli/prompt.js +3 -2
  31. package/dist/lib/client-file-uploader.js +86 -87
  32. package/dist/lib/config/software.js +18 -12
  33. package/dist/lib/dev-environment/dev-environment-cli.js +47 -3
  34. package/dist/lib/dev-environment/dev-environment-lando.js +2 -2
  35. package/dist/lib/env.js +16 -13
  36. package/dist/lib/envvar/api-delete.js +2 -0
  37. package/dist/lib/envvar/api-get-all.js +4 -1
  38. package/dist/lib/envvar/api-get.js +3 -1
  39. package/dist/lib/envvar/api-list.js +8 -3
  40. package/dist/lib/envvar/api-set.js +2 -0
  41. package/dist/lib/envvar/api.js +2 -5
  42. package/dist/lib/envvar/input.js +7 -8
  43. package/dist/lib/envvar/read-file.js +4 -7
  44. package/dist/lib/http/proxy-agent.js +5 -4
  45. package/dist/lib/keychain/insecure.js +25 -26
  46. package/dist/lib/keychain/secure.js +5 -2
  47. package/dist/lib/keychain.js +11 -18
  48. package/dist/lib/media-import/status.js +2 -2
  49. package/dist/lib/read-file.js +13 -14
  50. package/dist/lib/search-and-replace.js +17 -26
  51. package/dist/lib/site-import/status.js +4 -3
  52. package/dist/lib/token.js +17 -6
  53. package/dist/lib/tracker.js +13 -14
  54. package/dist/lib/user-error.js +6 -5
  55. package/dist/lib/utils.js +18 -22
  56. package/dist/lib/validations/sql.js +3 -3
  57. package/dist/lib/vip-import-validate-files.js +23 -22
  58. package/npm-shrinkwrap.json +1041 -1230
  59. package/package.json +30 -8
  60. package/tsconfig.json +37 -0
  61. package/dist/lib/analytics/clients/stub.js +0 -16
  62. package/dist/lib/cli/repo.js +0 -61
  63. package/dist/lib/keychain/browser.js +0 -31
@@ -10,20 +10,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * External dependencies
12
12
  */
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
16
- async function _default(app, fields, fragments) {
17
- if (!fields) {
18
- fields = 'id,name';
19
- }
20
- if (!fragments) {
21
- fragments = '';
22
- }
17
+
18
+ async function _default(app, fields = 'id,name', fragments = '') {
23
19
  const api = await (0, _api.default)();
24
- if (isNaN(app)) {
20
+ if (isNaN(+app)) {
21
+ var _res$data$apps, _res$data$apps$edges;
25
22
  const res = await api.query({
26
- // $FlowFixMe: gql template is not supported by flow
27
23
  query: (0, _graphqlTag.default)`query App( $name: String ) {
28
24
  apps( first: 1, name: $name ) {
29
25
  total,
@@ -38,14 +34,15 @@ async function _default(app, fields, fragments) {
38
34
  name: app
39
35
  }
40
36
  });
41
- if (!res || !res.data || !res.data.apps || !res.data.apps.edges || !res.data.apps.edges.length) {
37
+ if (!((_res$data$apps = res.data.apps) !== null && _res$data$apps !== void 0 && (_res$data$apps$edges = _res$data$apps.edges) !== null && _res$data$apps$edges !== void 0 && _res$data$apps$edges.length)) {
42
38
  return {};
43
39
  }
44
40
  return res.data.apps.edges[0];
45
41
  }
46
- app = parseInt(app, 10);
42
+ if (typeof app === 'string') {
43
+ app = parseInt(app, 10);
44
+ }
47
45
  const res = await api.query({
48
- // $FlowFixMe: gql template is not supported by flow
49
46
  query: (0, _graphqlTag.default)`query App( $id: Int ) {
50
47
  app( id: $id ){
51
48
  ${fields}
@@ -56,7 +53,7 @@ async function _default(app, fields, fragments) {
56
53
  id: app
57
54
  }
58
55
  });
59
- if (!res || !res.data || !res.data.app) {
56
+ if (!res.data.app) {
60
57
  return {};
61
58
  }
62
59
  return res.data.app;
@@ -8,10 +8,7 @@ exports.purgeCache = purgeCache;
8
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
9
  var _api = _interopRequireDefault(require("../../lib/api"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- /**
12
- *
13
- * @format
14
- */
11
+ // @format
15
12
 
16
13
  /**
17
14
  * External dependencies
@@ -54,6 +51,7 @@ const appQuery = `
54
51
  `;
55
52
  exports.appQuery = appQuery;
56
53
  async function purgeCache(appId, envId, urls) {
54
+ var _response$data$purgeP, _response$data;
57
55
  const api = await (0, _api.default)();
58
56
  const variables = {
59
57
  appId,
@@ -64,10 +62,5 @@ async function purgeCache(appId, envId, urls) {
64
62
  mutation,
65
63
  variables
66
64
  });
67
- const {
68
- data: {
69
- purgePageCache
70
- }
71
- } = response;
72
- return purgePageCache;
65
+ return (_response$data$purgeP = (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.purgePageCache) !== null && _response$data$purgeP !== void 0 ? _response$data$purgeP : null;
73
66
  }
@@ -10,11 +10,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * External dependencies
12
12
  */
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
17
+
16
18
  let api;
17
- (0, _api.default)().then(client => {
19
+
20
+ // If Token.get() fails, we may have an unhandled rejection
21
+ void (0, _api.default)().then(client => {
18
22
  api = client;
19
23
  });
20
24
  const isVipQuery = (0, _graphqlTag.default)`
@@ -25,9 +29,8 @@ const isVipQuery = (0, _graphqlTag.default)`
25
29
  }
26
30
  `;
27
31
  async function get() {
28
- const res = await api.query({
32
+ return await api.query({
29
33
  query: isVipQuery,
30
34
  fetchPolicy: 'cache-first'
31
35
  });
32
- return res;
33
36
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
8
+ var _debug = _interopRequireDefault(require("debug"));
8
9
  var _token = _interopRequireDefault(require("../../lib/token"));
9
10
  var _env = _interopRequireDefault(require("../../lib/env"));
10
11
  var _proxyAgent = require("../../lib/http/proxy-agent");
@@ -18,8 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
19
  * Internal dependencies
19
20
  */
20
21
 
21
- const debug = require('debug')('@automattic/vip:http');
22
-
22
+ const debug = (0, _debug.default)('@automattic/vip:http');
23
23
  /**
24
24
  * Call the Public API with an arbitrary path (e.g. to connect to REST endpoints).
25
25
  * This will include the token in an Authorization header so requests are "logged-in."
@@ -31,6 +31,7 @@ const debug = require('debug')('@automattic/vip:http');
31
31
  * @return {Promise} Return value of the `fetch` call
32
32
  */
33
33
  var _default = async (path, options = {}) => {
34
+ var _options$headers;
34
35
  let url = path;
35
36
 
36
37
  // For convenience, we support just passing in the path to this function...
@@ -39,27 +40,18 @@ var _default = async (path, options = {}) => {
39
40
  url = `${_api.API_HOST}${path}`;
40
41
  }
41
42
  const authToken = await _token.default.get();
42
- const headers = {
43
- 'User-Agent': _env.default.userAgent,
44
- Authorization: authToken ? `Bearer ${authToken.raw}` : null
45
- };
46
43
  const proxyAgent = (0, _proxyAgent.createProxyAgent)(url);
47
44
  debug('running fetch', url);
48
45
  return (0, _nodeFetch.default)(url, {
49
46
  ...options,
50
- ...{
51
- agent: proxyAgent,
52
- headers: {
53
- ...headers,
54
- ...{
55
- 'Content-Type': 'application/json'
56
- },
57
- ...options.headers
58
- }
47
+ agent: proxyAgent !== null && proxyAgent !== void 0 ? proxyAgent : undefined,
48
+ headers: {
49
+ Authorization: `Bearer ${authToken.raw}`,
50
+ 'User-Agent': _env.default.userAgent,
51
+ 'Content-Type': 'application/json',
52
+ ...((_options$headers = options.headers) !== null && _options$headers !== void 0 ? _options$headers : {})
59
53
  },
60
- ...{
61
- body: typeof options.body === 'object' ? JSON.stringify(options.body) : options.body
62
- }
54
+ body: typeof options.body === 'object' ? JSON.stringify(options.body) : options.body
63
55
  });
64
56
  };
65
57
  exports.default = _default;
@@ -7,10 +7,7 @@ exports.getCurrentUserInfo = getCurrentUserInfo;
7
7
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
8
8
  var _api = _interopRequireDefault(require("../../lib/api"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /**
11
- *
12
- * @format
13
- */
10
+ // @format
14
11
 
15
12
  /**
16
13
  * External dependencies
@@ -41,10 +38,8 @@ async function getCurrentUserInfo() {
41
38
  query: QUERY_CURRENT_USER
42
39
  });
43
40
  const {
44
- data: {
45
- me
46
- }
47
- } = response;
41
+ me
42
+ } = response.data;
48
43
  if (!me) {
49
44
  throw new Error('The API did not return any information about the user.');
50
45
  }
package/dist/lib/api.js CHANGED
@@ -15,11 +15,9 @@ var _chalk = _interopRequireDefault(require("chalk"));
15
15
  var _token = _interopRequireDefault(require("./token"));
16
16
  var _env = _interopRequireDefault(require("./env"));
17
17
  var _proxyAgent = require("../lib/http/proxy-agent");
18
+ var _http = _interopRequireDefault(require("./api/http"));
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- /**
20
- *
21
- * @format
22
- */
20
+ // @format
23
21
 
24
22
  /**
25
23
  * External dependencies
@@ -31,8 +29,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
31
29
 
32
30
  // Config
33
31
  const PRODUCTION_API_HOST = 'https://api.wpvip.com';
32
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
34
33
  exports.PRODUCTION_API_HOST = PRODUCTION_API_HOST;
35
- const API_HOST = process.env.API_HOST || PRODUCTION_API_HOST;
34
+ const API_HOST = process.env.API_HOST || PRODUCTION_API_HOST; // NOSONAR
36
35
  exports.API_HOST = API_HOST;
37
36
  const API_URL = `${API_HOST}/graphql`;
38
37
  exports.API_URL = API_URL;
@@ -49,22 +48,22 @@ async function API({
49
48
  const authToken = await _token.default.get();
50
49
  const headers = {
51
50
  'User-Agent': _env.default.userAgent,
52
- Authorization: authToken ? `Bearer ${authToken.raw}` : null
51
+ Authorization: `Bearer ${authToken.raw}`
53
52
  };
54
53
  const errorLink = (0, _error.onError)(({
55
54
  networkError,
56
55
  graphQLErrors
57
56
  }) => {
58
- if (networkError && networkError.statusCode === 401) {
57
+ if (networkError && 'statusCode' in networkError && networkError.statusCode === 401) {
59
58
  console.error(_chalk.default.red('Unauthorized:'), 'You are unauthorized to perform this request, please logout with `vip logout` then try again.');
60
- process.exit();
59
+ process.exit(1);
61
60
  }
62
- if (graphQLErrors && graphQLErrors.length && globalGraphQLErrorHandlingEnabled) {
61
+ if (graphQLErrors !== null && graphQLErrors !== void 0 && graphQLErrors.length && globalGraphQLErrorHandlingEnabled) {
63
62
  graphQLErrors.forEach(error => {
64
63
  console.error(_chalk.default.red('Error:'), error.message);
65
64
  });
66
65
  if (exitOnError) {
67
- process.exit();
66
+ process.exit(1);
68
67
  }
69
68
  }
70
69
  });
@@ -75,22 +74,20 @@ async function API({
75
74
  };
76
75
  });
77
76
  const authLink = new _core2.ApolloLink((operation, forward) => {
78
- const {
79
- token
80
- } = operation.getContext();
77
+ const ctx = operation.getContext();
78
+ const token = ctx.token;
81
79
  operation.setContext({
82
80
  headers: {
83
- Authorization: token ? `Bearer ${token.raw}` : null
81
+ Authorization: `Bearer ${token.raw}`
84
82
  }
85
83
  });
86
84
  return forward(operation);
87
85
  });
88
86
  const proxyAgent = (0, _proxyAgent.createProxyAgent)(API_URL);
89
- const http = require("./api/http").default;
90
87
  const httpLink = new _core.HttpLink({
91
88
  uri: API_URL,
92
89
  headers,
93
- fetch: http,
90
+ fetch: _http.default,
94
91
  fetchOptions: {
95
92
  agent: proxyAgent
96
93
  }
@@ -8,10 +8,7 @@ exports.getRecentLogs = getRecentLogs;
8
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
9
  var _api = _interopRequireDefault(require("../../lib/api"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- /**
12
- *
13
- * @format
14
- */
11
+ // @format
15
12
 
16
13
  /**
17
14
  * External dependencies
@@ -41,7 +38,7 @@ const QUERY_ENVIRONMENT_LOGS = (0, _graphqlTag.default)`
41
38
  }
42
39
  `;
43
40
  async function getRecentLogs(appId, envId, type, limit, after) {
44
- var _response$data, _response$data$app, _response$data$app$en;
41
+ var _response$data$app, _response$data$app$en, _response$data$app$en2;
45
42
  const api = await (0, _api.default)({
46
43
  exitOnError: false
47
44
  });
@@ -55,7 +52,7 @@ async function getRecentLogs(appId, envId, type, limit, after) {
55
52
  after
56
53
  }
57
54
  });
58
- const logs = response === null || response === void 0 ? void 0 : (_response$data = response.data) === null || _response$data === void 0 ? void 0 : (_response$data$app = _response$data.app) === null || _response$data$app === void 0 ? void 0 : (_response$data$app$en = _response$data$app.environments[0]) === null || _response$data$app$en === void 0 ? void 0 : _response$data$app$en.logs;
55
+ const logs = (_response$data$app = response.data.app) === null || _response$data$app === void 0 ? void 0 : (_response$data$app$en = _response$data$app.environments) === null || _response$data$app$en === void 0 ? void 0 : (_response$data$app$en2 = _response$data$app$en[0]) === null || _response$data$app$en2 === void 0 ? void 0 : _response$data$app$en2.logs;
59
56
  if (!(logs !== null && logs !== void 0 && logs.nodes)) {
60
57
  throw new Error('Unable to query logs');
61
58
  }
package/dist/lib/app.js CHANGED
@@ -9,9 +9,11 @@ var _vipgo = require("./constants/vipgo");
9
9
  /**
10
10
  * External dependencies
11
11
  */
12
+
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
16
+
15
17
  /**
16
18
  * Is this a WordPress application?
17
19
  *
@@ -14,12 +14,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
16
  // @format
17
+
17
18
  /**
18
19
  * External dependencies
19
20
  */
21
+
20
22
  /**
21
23
  * Internal dependencies
22
24
  */
25
+
23
26
  async function checkFeatureEnabled(featureName, exitOnFalse = false) {
24
27
  // TODO: eventually let's look at more feature flags coming from the public api,
25
28
  // for now, let's see if the user of the CLI is VIP
@@ -29,9 +32,9 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
29
32
  });
30
33
  let isVIP;
31
34
  try {
32
- var _res$data, _res$data$me;
35
+ var _res$data$me;
33
36
  const res = await featureFlags.get();
34
- if ((res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : (_res$data$me = _res$data.me) === null || _res$data$me === void 0 ? void 0 : _res$data$me.isVIP) !== undefined) {
37
+ if ((res === null || res === void 0 ? void 0 : (_res$data$me = res.data.me) === null || _res$data$me === void 0 ? void 0 : _res$data$me.isVIP) !== undefined) {
35
38
  isVIP = res.data.me.isVIP;
36
39
  } else {
37
40
  isVIP = false;
@@ -43,9 +46,9 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
43
46
  exitOnFalse,
44
47
  error: message
45
48
  });
46
- exit.withError('Failed to determine if feature is enabled' + message);
49
+ exit.withError(`Failed to determine if feature is enabled: ${message}`);
47
50
  }
48
- if (exitOnFalse === true && isVIP === false) {
51
+ if (exitOnFalse && isVIP === false) {
49
52
  exit.withError('The feature you are attempting to use is not currently enabled.');
50
53
  }
51
54
  return isVIP === true;
@@ -56,10 +59,10 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
56
59
  // - It is mocked globally in jest.setupMocks.js.
57
60
  async function checkIfUserIsVip() {
58
61
  const token = await _token.default.get();
59
- if (token && token.valid()) {
60
- var _res$data2, _res$data2$me;
62
+ if (token.valid()) {
63
+ var _res$data$me2;
61
64
  const res = await featureFlags.get();
62
- return !!(res !== null && res !== void 0 && (_res$data2 = res.data) !== null && _res$data2 !== void 0 && (_res$data2$me = _res$data2.me) !== null && _res$data2$me !== void 0 && _res$data2$me.isVIP);
65
+ return !!(res !== null && res !== void 0 && (_res$data$me2 = res.data.me) !== null && _res$data$me2 !== void 0 && _res$data$me2.isVIP);
63
66
  }
64
67
  return false;
65
68
  }
@@ -11,7 +11,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
  */
12
12
 
13
13
  const debug = (0, _debug.default)('@automattic/vip:lib:cli:config');
14
- let configFromFile = {};
14
+ let configFromFile;
15
15
  try {
16
16
  // Get `local` config first; this will only exist in dev as it's npmignore-d.
17
17
  configFromFile = require("../../../config/config.local.json");
@@ -21,6 +21,5 @@ try {
21
21
  configFromFile = require("../../../config/config.publish.json");
22
22
  debug('Loaded config data from config.publish.json');
23
23
  }
24
- const config = Object.assign({}, configFromFile);
25
- var _default = config;
24
+ var _default = configFromFile;
26
25
  exports.default = _default;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isAlias = isAlias;
7
+ exports.parseEnvAlias = parseEnvAlias;
8
+ exports.parseEnvAliasFromArgv = parseEnvAliasFromArgv;
3
9
  /**
4
10
  * External dependencies
5
11
  */
12
+
6
13
  function isAlias(alias) {
7
14
  return /^@[A-Za-z0-9.-]+$/.test(alias);
8
15
  }
@@ -12,7 +19,7 @@ function parseEnvAlias(alias) {
12
19
  }
13
20
 
14
21
  // Remove the '@'
15
- const stripped = alias.substr(1).toLowerCase();
22
+ const stripped = alias.slice(1).toLowerCase();
16
23
 
17
24
  // in JS, .split() with a limit discards the extra ones, so can't use it
18
25
  // Also convert to lowercase because mixed case environment names would cause problems
@@ -20,7 +27,7 @@ function parseEnvAlias(alias) {
20
27
  let env;
21
28
 
22
29
  // Rejoin the env on '.' (if present), to handle instance names (env.instance-01)
23
- if (rest && rest.length) {
30
+ if (rest.length) {
24
31
  env = rest.join('.');
25
32
  }
26
33
  return {
@@ -47,7 +54,7 @@ function parseEnvAliasFromArgv(processArgv) {
47
54
  }
48
55
 
49
56
  // If we did have an alias, split it up into app/env
50
- const parsedAlias = module.exports.parseEnvAlias(alias);
57
+ const parsedAlias = parseEnvAlias(alias);
51
58
 
52
59
  // Splice out the alias
53
60
  argv.splice(argv.indexOf(alias), 1);
@@ -55,9 +62,4 @@ function parseEnvAliasFromArgv(processArgv) {
55
62
  argv,
56
63
  ...parsedAlias
57
64
  };
58
- }
59
- module.exports = {
60
- isAlias,
61
- parseEnvAlias,
62
- parseEnvAliasFromArgv
63
- };
65
+ }
@@ -4,13 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.withError = withError;
7
- var _chalk = _interopRequireDefault(require("chalk"));
7
+ var _chalk = require("chalk");
8
8
  var _env = _interopRequireDefault(require("../../lib/env"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /**
11
- *
12
- * @format
13
- */
10
+ // @format
14
11
 
15
12
  /**
16
13
  * External dependencies
@@ -21,11 +18,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
21
18
  */
22
19
 
23
20
  function withError(message) {
24
- console.error(`${_chalk.default.red('Error: ')} ${message.toString().replace(/^Error:\s*/, '')}`);
21
+ console.error(`${(0, _chalk.red)('Error: ')} ${message.toString().replace(/^Error:\s*/, '')}`);
25
22
 
26
23
  // Debug ouput is printed below error output both for information
27
24
  // hierarchy and to make it more likely that the user copies it to their
28
25
  // clipboard when dragging across output.
29
- console.log(`${_chalk.default.yellow('Debug: ')} VIP-CLI v${_env.default.app.version}, Node ${_env.default.node.version}, ${_env.default.os.name} ${_env.default.os.version}`);
26
+ console.log(`${(0, _chalk.yellow)('Debug: ')} VIP-CLI v${_env.default.app.version}, Node ${_env.default.node.version}, ${_env.default.os.name} ${_env.default.os.version}`);
30
27
  process.exit(1);
31
28
  }
@@ -8,7 +8,7 @@ exports.capitalize = capitalize;
8
8
  exports.formatBytes = void 0;
9
9
  exports.formatData = formatData;
10
10
  exports.formatEnvironment = formatEnvironment;
11
- exports.formatSearchReplaceValues = void 0;
11
+ exports.formatSearchReplaceValues = formatSearchReplaceValues;
12
12
  exports.getGlyphForStatus = getGlyphForStatus;
13
13
  exports.isJson = isJson;
14
14
  exports.isJsonObject = isJsonObject;
@@ -16,13 +16,17 @@ exports.keyValue = keyValue;
16
16
  exports.requoteArgs = requoteArgs;
17
17
  exports.table = table;
18
18
  var _chalk = _interopRequireDefault(require("chalk"));
19
+ var _json2csv = require("json2csv");
20
+ var _cliTable = _interopRequireDefault(require("cli-table"));
19
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
- /** @format */
22
+ // @format
23
+
21
24
  /**
22
25
  * External dependencies
23
26
  */
27
+
24
28
  function formatData(data, format) {
25
- if (!data || !data.length) {
29
+ if (!data.length) {
26
30
  return '';
27
31
  }
28
32
  switch (format) {
@@ -50,32 +54,26 @@ function ids(data) {
50
54
  if (0 > fields.indexOf('id')) {
51
55
  return 'No ID field found';
52
56
  }
53
- const id = [];
54
- data.forEach(datum => id.push(datum.id));
57
+ const id = data.map(datum => datum.id);
55
58
  return id.join(' ');
56
59
  }
57
60
  function csv(data) {
58
- const {
59
- Parser
60
- } = require('json2csv');
61
61
  const fields = Object.keys(data[0]);
62
- const parser = new Parser({
62
+ const parser = new _json2csv.Parser({
63
63
  fields: formatFields(fields)
64
64
  });
65
65
  return parser.parse(data);
66
66
  }
67
67
  function table(data) {
68
- const Table = require('cli-table');
69
68
  const fields = Object.keys(data[0]);
70
- const dataTable = new Table({
69
+ const dataTable = new _cliTable.default({
71
70
  head: formatFields(fields),
72
71
  style: {
73
72
  head: ['blueBright']
74
73
  }
75
74
  });
76
75
  data.forEach(datum => {
77
- const row = [];
78
- fields.forEach(field => row.push(datum[field]));
76
+ const row = fields.map(field => datum[field].toString());
79
77
  dataTable.push(row);
80
78
  });
81
79
  return dataTable.toString();
@@ -95,11 +93,15 @@ function keyValue(values) {
95
93
  key,
96
94
  value
97
95
  } of values) {
98
- let formattedValue = value;
96
+ let formattedValue;
99
97
  switch (key.toLowerCase()) {
98
+ // NOSONAR
100
99
  case 'environment':
101
100
  formattedValue = formatEnvironment(value);
102
101
  break;
102
+ default:
103
+ formattedValue = value;
104
+ break;
103
105
  }
104
106
  lines.push(`+ ${key}: ${formattedValue}`);
105
107
  }
@@ -109,7 +111,7 @@ function keyValue(values) {
109
111
  function requoteArgs(args) {
110
112
  return args.map(arg => {
111
113
  if (arg.includes('--') && arg.includes('=') && arg.includes(' ')) {
112
- return arg.replace(/^--(.*)=(.*)$/, '--$1="$2"');
114
+ return arg.replace(/^--([^=]*)=(.*)$/, '--$1="$2"');
113
115
  }
114
116
  if (arg.includes(' ') && !isJsonObject(arg)) {
115
117
  return `"${arg}"`;
@@ -123,10 +125,10 @@ function isJsonObject(str) {
123
125
  function isJson(str) {
124
126
  try {
125
127
  JSON.parse(str);
128
+ return true;
126
129
  } catch (error) {
127
130
  return false;
128
131
  }
129
- return true;
130
132
  }
131
133
  function capitalize(str) {
132
134
  if (typeof str !== 'string' || !str.length) {
@@ -154,8 +156,6 @@ class RunningSprite {
154
156
  exports.RunningSprite = RunningSprite;
155
157
  function getGlyphForStatus(status, runningSprite) {
156
158
  switch (status) {
157
- default:
158
- return '';
159
159
  case 'pending':
160
160
  return '○';
161
161
  case 'running':
@@ -168,24 +168,23 @@ function getGlyphForStatus(status, runningSprite) {
168
168
  return _chalk.default.yellow('✕');
169
169
  case 'skipped':
170
170
  return _chalk.default.green('-');
171
+ default:
172
+ return '';
171
173
  }
172
174
  }
173
175
 
174
176
  // Format Search and Replace values to output
175
- const formatSearchReplaceValues = (values, message) => {
177
+ function formatSearchReplaceValues(values, message) {
176
178
  // Convert single pair S-R values to arrays
177
179
  const searchReplaceValues = typeof values === 'string' ? [values] : values;
178
- const formattedOutput = searchReplaceValues.map(pairs => {
180
+ return searchReplaceValues.map(pairs => {
179
181
  // Turn each S-R pair into its own array, then trim away whitespace
180
182
  const [from, to] = pairs.split(',').map(pair => pair.trim());
181
- const output = message(from, to);
182
- return output;
183
+ return message(from, to);
183
184
  });
184
- return formattedOutput;
185
- };
185
+ }
186
186
 
187
187
  // Format bytes into kilobytes, megabytes, etc based on the size
188
- exports.formatSearchReplaceValues = formatSearchReplaceValues;
189
188
  const formatBytes = (bytes, decimals = 2) => {
190
189
  if (0 === bytes) {
191
190
  return '0 Bytes';
@@ -194,6 +193,6 @@ const formatBytes = (bytes, decimals = 2) => {
194
193
  const dm = decimals < 0 ? 0 : decimals;
195
194
  const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB'];
196
195
  const idx = Math.floor(Math.log(bytes) / Math.log(bytesMultiplier));
197
- return parseFloat((bytes / Math.pow(bytesMultiplier, idx)).toFixed(dm)) + ' ' + sizes[idx];
196
+ return `${parseFloat((bytes / Math.pow(bytesMultiplier, idx)).toFixed(dm))} ${sizes[idx]}`;
198
197
  };
199
198
  exports.formatBytes = formatBytes;
@@ -6,13 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.ProgressTracker = void 0;
7
7
  var _singleLineLog = require("single-line-log");
8
8
  var _format = require("../../lib/cli/format");
9
- /** @format */
9
+ // @format
10
+
10
11
  /**
11
12
  * External dependencies
12
13
  */
14
+
13
15
  /**
14
16
  * Internal dependencies
15
17
  */
18
+
16
19
  const PRINT_INTERVAL = process.env.DEBUG ? 5000 : 200; // How often the report is printed. Mainly affects the "spinner" animation.
17
20
  const COMPLETED_STEP_SLUGS = ['success', 'skipped'];
18
21
  class ProgressTracker {
@@ -27,6 +30,7 @@ class ProgressTracker {
27
30
  constructor(steps) {
28
31
  this.runningSprite = new _format.RunningSprite();
29
32
  this.hasFailure = false;
33
+ this.hasPrinted = false;
30
34
  this.stepsFromCaller = this.mapSteps(steps);
31
35
  this.stepsFromServer = new Map();
32
36
  this.prefix = '';
@@ -127,9 +131,9 @@ class ProgressTracker {
127
131
  }
128
132
  }
129
133
  allStepsSucceeded() {
130
- return ![...this.getSteps().values()].some(({
134
+ return [...this.getSteps().values()].every(({
131
135
  status
132
- }) => status !== 'success');
136
+ }) => status === 'success');
133
137
  }
134
138
  setStatusForStepId(stepId, status) {
135
139
  const step = this.stepsFromCaller.get(stepId);