@automattic/vip 2.25.1 → 2.26.1

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 (76) hide show
  1. package/CHANGELOG.md +27 -7
  2. package/assets/dev-env.lando.template.yml.ejs +18 -4
  3. package/automattic-vip-2.26.1.tgz +0 -0
  4. package/dist/bin/vip-config-software-get.js +1 -1
  5. package/dist/bin/vip-dev-env-create.js +2 -1
  6. package/dist/bin/vip-dev-env-import-sql.js +8 -67
  7. package/dist/bin/vip-dev-env-info.js +2 -1
  8. package/dist/bin/vip-dev-env-start.js +1 -1
  9. package/dist/bin/vip-dev-env-update.js +3 -3
  10. package/dist/bin/vip-import-media-abort.js +2 -2
  11. package/dist/bin/vip-import-sql.js +7 -7
  12. package/dist/bin/vip-import-validate-files.js +2 -4
  13. package/dist/bin/vip-logs.js +10 -1
  14. package/dist/bin/vip-sync.js +1 -1
  15. package/dist/bin/vip-validate-preflight.js +2 -2
  16. package/dist/bin/vip-wp.js +4 -4
  17. package/dist/commands/dev-env-import-sql.js +94 -0
  18. package/dist/commands/dev-env-sync-sql.js +184 -0
  19. package/dist/commands/export-sql.js +360 -0
  20. package/dist/lib/analytics/clients/pendo.js +1 -1
  21. package/dist/lib/analytics/clients/stub.js +1 -2
  22. package/dist/lib/analytics/index.js +0 -2
  23. package/dist/lib/api/app.js +1 -1
  24. package/dist/lib/api/cache-purge.js +1 -1
  25. package/dist/lib/api/feature-flags.js +1 -1
  26. package/dist/lib/api/http.js +7 -7
  27. package/dist/lib/api/user.js +1 -1
  28. package/dist/lib/api.js +1 -1
  29. package/dist/lib/app-logs/app-logs.js +1 -1
  30. package/dist/lib/app.js +6 -6
  31. package/dist/lib/cli/apiConfig.js +21 -28
  32. package/dist/lib/cli/command.js +91 -81
  33. package/dist/lib/cli/envAlias.js +15 -10
  34. package/dist/lib/cli/exit.js +1 -1
  35. package/dist/lib/cli/format.js +22 -7
  36. package/dist/lib/cli/progress.js +1 -2
  37. package/dist/lib/cli/prompt.js +1 -3
  38. package/dist/lib/cli/repo.js +0 -1
  39. package/dist/lib/client-file-uploader.js +32 -19
  40. package/dist/lib/config/software.js +0 -2
  41. package/dist/lib/constants/dev-environment.js +0 -1
  42. package/dist/lib/dev-environment/dev-environment-cli.js +32 -17
  43. package/dist/lib/dev-environment/dev-environment-core.js +57 -22
  44. package/dist/lib/dev-environment/dev-environment-lando.js +124 -40
  45. package/dist/lib/envvar/api-delete.js +1 -1
  46. package/dist/lib/envvar/api-get-all.js +1 -1
  47. package/dist/lib/envvar/api-get.js +1 -1
  48. package/dist/lib/envvar/api-list.js +1 -1
  49. package/dist/lib/envvar/api-set.js +1 -1
  50. package/dist/lib/envvar/api.js +1 -1
  51. package/dist/lib/envvar/logging.js +1 -1
  52. package/dist/lib/envvar/read-file.js +1 -1
  53. package/dist/lib/http/proxy-agent.js +5 -6
  54. package/dist/lib/keychain/secure.js +0 -6
  55. package/dist/lib/keychain.js +6 -1
  56. package/dist/lib/logout.js +3 -3
  57. package/dist/lib/media-import/media-file-import.js +1 -1
  58. package/dist/lib/media-import/progress.js +2 -2
  59. package/dist/lib/media-import/status.js +6 -5
  60. package/dist/lib/read-file.js +1 -1
  61. package/dist/lib/rollbar.js +1 -1
  62. package/dist/lib/search-and-replace.js +13 -16
  63. package/dist/lib/site-import/db-file-import.js +1 -1
  64. package/dist/lib/site-import/status.js +6 -5
  65. package/dist/lib/tracker.js +2 -2
  66. package/dist/lib/utils.js +69 -0
  67. package/dist/lib/validations/is-multi-site-sql-dump.js +3 -40
  68. package/dist/lib/validations/is-multi-site.js +4 -5
  69. package/dist/lib/validations/is-multisite-domain-mapped.js +15 -18
  70. package/dist/lib/validations/line-by-line.js +4 -14
  71. package/dist/lib/validations/site-type.js +5 -5
  72. package/dist/lib/validations/sql.js +16 -16
  73. package/dist/lib/validations/utils.js +2 -2
  74. package/dist/lib/vip-import-validate-files.js +44 -44
  75. package/npm-shrinkwrap.json +20971 -4078
  76. package/package.json +10 -16
package/dist/lib/app.js CHANGED
@@ -9,15 +9,14 @@ var _vipgo = require("./constants/vipgo");
9
9
  /**
10
10
  * External dependencies
11
11
  */
12
-
13
12
  /**
14
13
  * Internal dependencies
15
14
  */
16
-
17
15
  /**
18
16
  * Is this a WordPress application?
19
- * @param {int} appTypeId application type ID
20
- * @constructor
17
+ *
18
+ * @param {number} appTypeId application type ID
19
+ * @return {boolean} Whether this a WordPress application
21
20
  */
22
21
  function isAppWordPress(appTypeId) {
23
22
  return _vipgo.WORDPRESS_SITE_TYPE_IDS.includes(appTypeId);
@@ -25,8 +24,9 @@ function isAppWordPress(appTypeId) {
25
24
 
26
25
  /**
27
26
  * Is this a Nodejs application?
28
- * @param {int} appTypeId application type ID
29
- * @constructor
27
+ *
28
+ * @param {number} appTypeId application type ID
29
+ * @return {boolean} Whether this a Node.js application
30
30
  */
31
31
  function isAppNodejs(appTypeId) {
32
32
  return _vipgo.NODEJS_SITE_TYPE_IDS.includes(appTypeId);
@@ -6,26 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.checkFeatureEnabled = checkFeatureEnabled;
7
7
  exports.checkIfUserIsVip = checkIfUserIsVip;
8
8
  exports.exitWhenFeatureDisabled = exitWhenFeatureDisabled;
9
- var _tracker = require("../tracker");
9
+ var _tracker = require("../../lib/tracker");
10
10
  var exit = _interopRequireWildcard(require("./exit"));
11
- var featureFlags = _interopRequireWildcard(require("../api/feature-flags"));
12
- var _token = _interopRequireDefault(require("../token"));
11
+ var featureFlags = _interopRequireWildcard(require("../../lib/api/feature-flags"));
12
+ var _token = _interopRequireDefault(require("../../lib/token"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
- /**
17
- *
18
- * @format
19
- */
20
-
16
+ // @format
21
17
  /**
22
18
  * External dependencies
23
19
  */
24
-
25
20
  /**
26
21
  * Internal dependencies
27
22
  */
28
-
29
23
  async function checkFeatureEnabled(featureName, exitOnFalse = false) {
30
24
  // TODO: eventually let's look at more feature flags coming from the public api,
31
25
  // for now, let's see if the user of the CLI is VIP
@@ -33,25 +27,24 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
33
27
  featureName,
34
28
  exitOnFalse
35
29
  });
36
- const isVIP = await new Promise(async resolve => {
37
- try {
38
- var _res$data, _res$data$me;
39
- const res = await featureFlags.get();
40
- 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) {
41
- resolve(res.data.me.isVIP);
42
- } else {
43
- resolve(false);
44
- }
45
- } catch (err) {
46
- const message = err.toString();
47
- await (0, _tracker.trackEvent)('checkFeatureEnabled_fetch_error', {
48
- featureName,
49
- exitOnFalse,
50
- error: message
51
- });
52
- exit.withError('Failed to determine if feature is enabled' + message);
30
+ let isVIP;
31
+ try {
32
+ var _res$data, _res$data$me;
33
+ 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) {
35
+ isVIP = res.data.me.isVIP;
36
+ } else {
37
+ isVIP = false;
53
38
  }
54
- });
39
+ } catch (err) {
40
+ const message = err.toString();
41
+ await (0, _tracker.trackEvent)('checkFeatureEnabled_fetch_error', {
42
+ featureName,
43
+ exitOnFalse,
44
+ error: message
45
+ });
46
+ exit.withError('Failed to determine if feature is enabled' + message);
47
+ }
55
48
  if (exitOnFalse === true && isVIP === false) {
56
49
  exit.withError('The feature you are attempting to use is not currently enabled.');
57
50
  }
@@ -12,11 +12,11 @@ var _chalk = _interopRequireDefault(require("chalk"));
12
12
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
13
  var _updateNotifier = _interopRequireDefault(require("update-notifier"));
14
14
  var _prompt = require("./prompt");
15
- var _api = _interopRequireDefault(require("../api"));
16
- var _app = _interopRequireDefault(require("../api/app"));
15
+ var _api = _interopRequireDefault(require("../../lib/api"));
16
+ var _app = _interopRequireDefault(require("../../lib/api/app"));
17
17
  var _format = require("./format");
18
18
  var _package = _interopRequireDefault(require("../../../package.json"));
19
- var _tracker = require("../tracker");
19
+ var _tracker = require("../../lib/tracker");
20
20
  var _envAlias = require("./envAlias");
21
21
  var _rollbar = require("../rollbar");
22
22
  var exit = _interopRequireWildcard(require("./exit"));
@@ -28,7 +28,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
28
28
  /**
29
29
  * External dependencies
30
30
  */
31
- /* eslint-enable no-duplicate-imports */
31
+ /**
32
+ * Internal dependencies
33
+ */
32
34
  function uncaughtError(err) {
33
35
  // Error raised when trying to write to an already closed stream
34
36
  if (err.code === 'EPIPE') {
@@ -45,6 +47,8 @@ process.on('uncaughtException', uncaughtError);
45
47
  process.on('unhandledRejection', uncaughtError);
46
48
  let _opts = {};
47
49
  let alreadyConfirmedDebugAttachment = false;
50
+
51
+ // eslint-disable-next-line complexity
48
52
  _args.default.argv = async function (argv, cb) {
49
53
  if (process.execArgv.includes('--inspect') && !alreadyConfirmedDebugAttachment) {
50
54
  await (0, _enquirer.prompt)({
@@ -321,106 +325,112 @@ _args.default.argv = async function (argv, cb) {
321
325
  }
322
326
  switch (_opts.module) {
323
327
  case 'import-sql':
324
- const site = options.env;
325
- if (site && site.primaryDomain) {
326
- const primaryDomainName = site.primaryDomain.name;
327
- info.push({
328
- key: 'Primary Domain Name',
329
- value: primaryDomainName
330
- });
331
- }
328
+ {
329
+ const site = options.env;
330
+ if (site && site.primaryDomain) {
331
+ const primaryDomainName = site.primaryDomain.name;
332
+ info.push({
333
+ key: 'Primary Domain Name',
334
+ value: primaryDomainName
335
+ });
336
+ }
332
337
 
333
- // Site launched details
334
- const haveLaunchedField = site.hasOwnProperty('launched');
335
- if (haveLaunchedField) {
336
- const launched = site.launched ? '✅ Yes' : `${_chalk.default.red('x')} No`;
337
- info.push({
338
- key: 'Launched?',
339
- value: `${_chalk.default.cyan(launched)}`
340
- });
341
- }
342
- this.sub && info.push({
343
- key: 'SQL File',
344
- value: `${_chalk.default.blueBright(this.sub)}`
345
- });
346
- options.skipValidate = options.hasOwnProperty('skipValidate') && !!options.skipValidate && !['false', 'no'].includes(options.skipValidate);
347
- if (options.skipValidate) {
348
- info.push({
349
- key: 'Pre-Upload Validations',
350
- value: _chalk.default.red('SKIPPED!')
351
- });
352
- }
338
+ // Site launched details
339
+ const haveLaunchedField = Object.prototype.hasOwnProperty.call(site, 'launched');
340
+ if (haveLaunchedField) {
341
+ const launched = site.launched ? '✅ Yes' : `${_chalk.default.red('x')} No`;
342
+ info.push({
343
+ key: 'Launched?',
344
+ value: `${_chalk.default.cyan(launched)}`
345
+ });
346
+ }
347
+ if (this.sub) {
348
+ info.push({
349
+ key: 'SQL File',
350
+ value: `${_chalk.default.blueBright(this.sub)}`
351
+ });
352
+ }
353
+ options.skipValidate = Object.prototype.hasOwnProperty.call(options, 'skipValidate') && !!options.skipValidate && !['false', 'no'].includes(options.skipValidate);
354
+ if (options.skipValidate) {
355
+ info.push({
356
+ key: 'Pre-Upload Validations',
357
+ value: _chalk.default.red('SKIPPED!')
358
+ });
359
+ }
353
360
 
354
- // Show S-R params if the `search-replace` flag is set
355
- const searchReplace = options.searchReplace;
356
- const assignSRValues = (from, to) => {
357
- const pairs = {
358
- From: `${from}`,
359
- To: `${to}`
361
+ // Show S-R params if the `search-replace` flag is set
362
+ const searchReplace = options.searchReplace;
363
+ const assignSRValues = (from, to) => {
364
+ const pairs = {
365
+ From: `${from}`,
366
+ To: `${to}`
367
+ };
368
+ return pairs;
360
369
  };
361
- return pairs;
362
- };
363
- if (searchReplace) {
364
- const searchReplaceValues = (0, _format.formatSearchReplaceValues)(searchReplace, assignSRValues);
370
+ if (searchReplace) {
371
+ const searchReplaceValues = (0, _format.formatSearchReplaceValues)(searchReplace, assignSRValues);
365
372
 
366
- // Format data into a user-friendly table
367
- info.push({
368
- key: 'Replacements',
369
- value: '\n' + (0, _format.formatData)(searchReplaceValues, 'table')
370
- });
373
+ // Format data into a user-friendly table
374
+ info.push({
375
+ key: 'Replacements',
376
+ value: '\n' + (0, _format.formatData)(searchReplaceValues, 'table')
377
+ });
378
+ }
379
+ break;
371
380
  }
372
- break;
373
381
  case 'sync':
374
- const {
375
- backup,
376
- canSync,
377
- errors
378
- } = options.env.syncPreview;
379
- if (!canSync) {
380
- // User can not sync due to some error(s)
381
- // Shows the first error in the array
382
- exit.withError(`Could not sync to this environment: ${errors[0].message}`);
383
- }
384
-
385
- // remove __typename from replacements.
386
- // can not be deleted afterwards if deconstructed
387
- const replacements = options.env.syncPreview.replacements.map(rep => {
382
+ {
388
383
  const {
389
- from,
390
- to
391
- } = rep;
392
- return {
393
- from,
394
- to
395
- };
396
- });
397
- if (backup) {
384
+ backup,
385
+ canSync,
386
+ errors
387
+ } = options.env.syncPreview;
388
+ if (!canSync) {
389
+ // User can not sync due to some error(s)
390
+ // Shows the first error in the array
391
+ exit.withError(`Could not sync to this environment: ${errors[0].message}`);
392
+ }
393
+
394
+ // remove __typename from replacements.
395
+ // can not be deleted afterwards if deconstructed
396
+ const replacements = options.env.syncPreview.replacements.map(rep => {
397
+ const {
398
+ from,
399
+ to
400
+ } = rep;
401
+ return {
402
+ from,
403
+ to
404
+ };
405
+ });
406
+ if (backup) {
407
+ info.push({
408
+ key: 'From backup',
409
+ value: new Date(backup.createdAt).toUTCString()
410
+ });
411
+ }
398
412
  info.push({
399
- key: 'From backup',
400
- value: new Date(backup.createdAt).toUTCString()
413
+ key: 'Replacements',
414
+ value: '\n' + (0, _format.formatData)(replacements, 'table')
401
415
  });
416
+ break;
402
417
  }
403
- info.push({
404
- key: 'Replacements',
405
- value: '\n' + (0, _format.formatData)(replacements, 'table')
406
- });
407
- break;
408
418
  case 'import-media':
409
419
  info.push({
410
420
  key: 'Archive URL',
411
421
  value: _chalk.default.blue.underline(this.sub)
412
422
  });
413
- options.overwriteExistingFiles = options.hasOwnProperty('overwriteExistingFiles') && !!options.overwriteExistingFiles && !['false', 'no'].includes(options.overwriteExistingFiles);
423
+ options.overwriteExistingFiles = Object.prototype.hasOwnProperty.call(options, 'overwriteExistingFiles') && !!options.overwriteExistingFiles && !['false', 'no'].includes(options.overwriteExistingFiles);
414
424
  info.push({
415
425
  key: 'Overwrite any existing files',
416
426
  value: options.overwriteExistingFiles ? '✅ Yes' : `${_chalk.default.red('x')} No`
417
427
  });
418
- options.importIntermediateImages = options.hasOwnProperty('importIntermediateImages') && !!options.importIntermediateImages && !['false', 'no'].includes(options.importIntermediateImages);
428
+ options.importIntermediateImages = Object.prototype.hasOwnProperty.call(options, 'importIntermediateImages') && !!options.importIntermediateImages && !['false', 'no'].includes(options.importIntermediateImages);
419
429
  info.push({
420
430
  key: 'Import intermediate image files',
421
431
  value: options.importIntermediateImages ? '✅ Yes' : `${_chalk.default.red('x')} No`
422
432
  });
423
- options.exportFileErrorsToJson = options.hasOwnProperty('exportFileErrorsToJson') && !!options.exportFileErrorsToJson && !['false', 'no'].includes(options.exportFileErrorsToJson);
433
+ options.exportFileErrorsToJson = Object.prototype.hasOwnProperty.call(options, 'exportFileErrorsToJson') && !!options.exportFileErrorsToJson && !['false', 'no'].includes(options.exportFileErrorsToJson);
424
434
  info.push({
425
435
  key: 'Export any file errors encountered to a JSON file instead of a plain text file',
426
436
  value: options.exportFileErrorsToJson ? '✅ Yes' : `${_chalk.default.red('x')} No`
@@ -3,11 +3,11 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
- exports.isAlias = function (alias) {
7
- return /^@[A-Za-z0-9\.\-]+$/.test(alias);
8
- };
9
- exports.parseEnvAlias = function (alias) {
10
- if (!exports.isAlias(alias)) {
6
+ function isAlias(alias) {
7
+ return /^@[A-Za-z0-9.-]+$/.test(alias);
8
+ }
9
+ function parseEnvAlias(alias) {
10
+ if (!isAlias(alias)) {
11
11
  throw new Error('Invalid environment alias. Aliases are in the format of @app-name or @app-name.environment-name');
12
12
  }
13
13
 
@@ -17,7 +17,7 @@ exports.parseEnvAlias = function (alias) {
17
17
  // in JS, .split() with a limit discards the extra ones, so can't use it
18
18
  // Also convert to lowercase because mixed case environment names would cause problems
19
19
  const [app, ...rest] = stripped.split('.');
20
- let env = undefined;
20
+ let env;
21
21
 
22
22
  // Rejoin the env on '.' (if present), to handle instance names (env.instance-01)
23
23
  if (rest && rest.length) {
@@ -27,8 +27,8 @@ exports.parseEnvAlias = function (alias) {
27
27
  app,
28
28
  env
29
29
  };
30
- };
31
- exports.parseEnvAliasFromArgv = function (processArgv) {
30
+ }
31
+ function parseEnvAliasFromArgv(processArgv) {
32
32
  // Clone to not affect original arvg
33
33
  const argv = processArgv.slice(0);
34
34
 
@@ -39,7 +39,7 @@ exports.parseEnvAliasFromArgv = function (processArgv) {
39
39
  if (dashDashIndex > -1) {
40
40
  argsBeforeDashDash = argv.slice(0, dashDashIndex);
41
41
  }
42
- const alias = argsBeforeDashDash.find(arg => exports.isAlias(arg));
42
+ const alias = argsBeforeDashDash.find(arg => isAlias(arg));
43
43
  if (!alias) {
44
44
  return {
45
45
  argv
@@ -47,7 +47,7 @@ exports.parseEnvAliasFromArgv = function (processArgv) {
47
47
  }
48
48
 
49
49
  // If we did have an alias, split it up into app/env
50
- const parsedAlias = exports.parseEnvAlias(alias);
50
+ const parsedAlias = module.exports.parseEnvAlias(alias);
51
51
 
52
52
  // Splice out the alias
53
53
  argv.splice(argv.indexOf(alias), 1);
@@ -55,4 +55,9 @@ exports.parseEnvAliasFromArgv = function (processArgv) {
55
55
  argv,
56
56
  ...parsedAlias
57
57
  };
58
+ }
59
+ module.exports = {
60
+ isAlias,
61
+ parseEnvAlias,
62
+ parseEnvAliasFromArgv
58
63
  };
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.withError = withError;
7
7
  var _chalk = _interopRequireDefault(require("chalk"));
8
- var _env = _interopRequireDefault(require("../env"));
8
+ var _env = _interopRequireDefault(require("../../lib/env"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
  /**
11
11
  *
@@ -9,6 +9,8 @@ exports.formatData = formatData;
9
9
  exports.formatEnvironment = formatEnvironment;
10
10
  exports.formatSearchReplaceValues = void 0;
11
11
  exports.getGlyphForStatus = getGlyphForStatus;
12
+ exports.isJson = isJson;
13
+ exports.isJsonObject = isJsonObject;
12
14
  exports.keyValue = keyValue;
13
15
  exports.requoteArgs = requoteArgs;
14
16
  exports.table = table;
@@ -18,22 +20,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
20
  /**
19
21
  * External dependencies
20
22
  */
21
- function formatData(data, format, opts) {
23
+ function formatData(data, format) {
22
24
  if (!data || !data.length) {
23
25
  return '';
24
26
  }
25
27
  switch (format) {
26
28
  case 'ids':
27
- return ids(data, opts);
29
+ return ids(data);
28
30
  case 'json':
29
31
  return JSON.stringify(data, null, '\t');
30
32
  case 'csv':
31
- return csv(data, opts);
33
+ return csv(data);
32
34
  case 'keyValue':
33
- return keyValue(data, opts);
35
+ return keyValue(data);
34
36
  case 'table':
35
37
  default:
36
- return table(data, opts);
38
+ return table(data);
37
39
  }
38
40
  }
39
41
  function formatEnvironment(environment) {
@@ -85,7 +87,9 @@ function formatFields(fields) {
85
87
  function keyValue(values) {
86
88
  const lines = [];
87
89
  const pairs = values.length > 0;
88
- pairs ? lines.push('===================================') : '';
90
+ if (pairs) {
91
+ lines.push('===================================');
92
+ }
89
93
  for (const {
90
94
  key,
91
95
  value
@@ -106,12 +110,23 @@ function requoteArgs(args) {
106
110
  if (arg.includes('--') && arg.includes('=') && arg.includes(' ')) {
107
111
  return arg.replace(/^--(.*)=(.*)$/, '--$1="$2"');
108
112
  }
109
- if (arg.includes(' ')) {
113
+ if (arg.includes(' ') && !isJsonObject(arg)) {
110
114
  return `"${arg}"`;
111
115
  }
112
116
  return arg;
113
117
  });
114
118
  }
119
+ function isJsonObject(str) {
120
+ return typeof str === 'string' && str.trim().startsWith('{') && isJson(str);
121
+ }
122
+ function isJson(str) {
123
+ try {
124
+ JSON.parse(str);
125
+ } catch (error) {
126
+ return false;
127
+ }
128
+ return true;
129
+ }
115
130
  function capitalize(str) {
116
131
  if (typeof str !== 'string' || !str.length) {
117
132
  return '';
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ProgressTracker = void 0;
7
7
  var _singleLineLog = require("single-line-log");
8
- var _format = require("./format");
8
+ var _format = require("../../lib/cli/format");
9
9
  /** @format */
10
10
  /**
11
11
  * External dependencies
@@ -105,7 +105,6 @@ class ProgressTracker {
105
105
  const nextStep = this.getNextStep();
106
106
  if (nextStep) {
107
107
  this.stepRunning(nextStep.id);
108
- return;
109
108
  }
110
109
  }
111
110
  allStepsSucceeded() {
@@ -12,15 +12,13 @@ var _format = require("./format");
12
12
  /**
13
13
  * Internal dependencies
14
14
  */
15
- /* eslint-disable no-duplicate-imports */
16
- /* eslint-enable no-duplicate-imports */
17
15
  async function confirm(values, message, skipPrompt = false) {
18
16
  console.log((0, _format.keyValue)(values));
19
17
  if (!skipPrompt) {
20
18
  const answer = await (0, _enquirer.prompt)({
21
19
  type: 'confirm',
22
20
  name: 'confirm',
23
- message: message,
21
+ message,
24
22
  default: false
25
23
  });
26
24
  return answer.confirm;
@@ -35,7 +35,6 @@ async function getRepoFromGitConfig() {
35
35
  repo = repo.replace('git@github.com:', '');
36
36
  return repo;
37
37
  }
38
- return;
39
38
  }
40
39
  async function find(dir) {
41
40
  dir = dir || process.cwd();
@@ -15,6 +15,7 @@ exports.getPartBoundaries = getPartBoundaries;
15
15
  exports.getSignedUploadRequestData = getSignedUploadRequestData;
16
16
  exports.gzipFile = exports.getWorkingTempDir = void 0;
17
17
  exports.isFile = isFile;
18
+ exports.unzipFile = void 0;
18
19
  exports.uploadImportSqlFileToS3 = uploadImportSqlFileToS3;
19
20
  exports.uploadPart = uploadPart;
20
21
  exports.uploadParts = uploadParts;
@@ -27,11 +28,11 @@ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
27
28
  var _chalk = _interopRequireDefault(require("chalk"));
28
29
  var _zlib = require("zlib");
29
30
  var _crypto = require("crypto");
30
- var _stream = require("stream");
31
+ var _promises = require("node:stream/promises");
31
32
  var _xml2js = require("xml2js");
32
33
  var _debug = _interopRequireDefault(require("debug"));
33
- var _http = _interopRequireDefault(require("./api/http"));
34
- var _fileSize = require("./constants/file-size");
34
+ var _http = _interopRequireDefault(require("../lib/api/http"));
35
+ var _fileSize = require("../lib/constants/file-size");
35
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
37
  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); }
37
38
  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; }
@@ -77,24 +78,36 @@ const getFileMD5Hash = async fileName => new Promise((resolve, reject) => _fs.de
77
78
  }).on('error', error => reject(`could not generate file hash: ${error}`)));
78
79
  exports.getFileMD5Hash = getFileMD5Hash;
79
80
  const gzipFile = async (uncompressedFileName, compressedFileName) => new Promise((resolve, reject) => _fs.default.createReadStream(uncompressedFileName).pipe((0, _zlib.createGzip)()).pipe(_fs.default.createWriteStream(compressedFileName)).on('finish', resolve).on('error', error => reject(`could not compress file: ${error}`)));
81
+
82
+ /**
83
+ * Extract a .gz file and save it to a specified location
84
+ *
85
+ * @param {string} inputFilename The file to unzip
86
+ * @param {string} outputFilename The file where the unzipped data will be written
87
+ * @return {Promise} A promise that resolves when the file is unzipped
88
+ */
80
89
  exports.gzipFile = gzipFile;
90
+ const unzipFile = async (inputFilename, outputFilename) => {
91
+ const source = _fs.default.createReadStream(inputFilename);
92
+ const destination = _fs.default.createWriteStream(outputFilename);
93
+ await (0, _promises.pipeline)(source, (0, _zlib.createGunzip)(), destination);
94
+ };
95
+ exports.unzipFile = unzipFile;
81
96
  async function getFileMeta(fileName) {
82
- return new Promise(async resolve => {
83
- const fileSize = await getFileSize(fileName);
84
- const basename = _path.default.basename(fileName);
85
- // TODO Validate File basename... encodeURIComponent, maybe...?
97
+ const fileSize = await getFileSize(fileName);
98
+ const basename = _path.default.basename(fileName);
99
+ // TODO Validate File basename... encodeURIComponent, maybe...?
86
100
 
87
- const mimeType = await detectCompressedMimeType(fileName);
88
- // TODO Only allow a subset of Mime Types...?
101
+ const mimeType = await detectCompressedMimeType(fileName);
102
+ // TODO Only allow a subset of Mime Types...?
89
103
 
90
- const isCompressed = ['application/zip', 'application/gzip'].includes(mimeType);
91
- resolve({
92
- basename,
93
- fileName,
94
- fileSize,
95
- isCompressed
96
- });
97
- });
104
+ const isCompressed = ['application/zip', 'application/gzip'].includes(mimeType);
105
+ return {
106
+ basename,
107
+ fileName,
108
+ fileSize,
109
+ isCompressed
110
+ };
98
111
  }
99
112
  async function uploadImportSqlFileToS3({
100
113
  app,
@@ -173,7 +186,7 @@ async function uploadUsingPutObject({
173
186
  };
174
187
 
175
188
  let readBytes = 0;
176
- const progressPassThrough = new _stream.PassThrough();
189
+ const progressPassThrough = new _promises.PassThrough();
177
190
  progressPassThrough.on('data', data => {
178
191
  readBytes += data.length;
179
192
  const percentage = Math.floor(100 * readBytes / fileSize) + '%';
@@ -396,7 +409,7 @@ async function uploadParts({
396
409
  index,
397
410
  partSize
398
411
  } = part;
399
- const progressPassThrough = new _stream.PassThrough();
412
+ const progressPassThrough = new _promises.PassThrough();
400
413
  let partBytesRead = 0;
401
414
  progressPassThrough.on('data', data => {
402
415
  totalBytesRead += data.length;
@@ -14,11 +14,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  /**
15
15
  * External dependencies
16
16
  */
17
-
18
17
  /**
19
18
  * Internal dependencies
20
19
  */
21
-
22
20
  const UPDATE_PROGRESS_POLL_INTERVAL = 5;
23
21
  const debug = (0, _debug.default)('@automattic/vip:bin:config-software');
24
22
  const appQuery = `
@@ -11,7 +11,6 @@ exports.DEV_ENVIRONMENT_FULL_COMMAND = DEV_ENVIRONMENT_FULL_COMMAND;
11
11
  const DEV_ENVIRONMENT_DEFAULTS = {
12
12
  title: 'VIP Dev',
13
13
  multisite: false,
14
- mariadbVersion: '10.3',
15
14
  phpVersion: '8.0'
16
15
  };
17
16
  exports.DEV_ENVIRONMENT_DEFAULTS = DEV_ENVIRONMENT_DEFAULTS;