@automattic/vip 2.21.0 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/assets/dev-env.lando.template.yml.ejs +1 -1
  3. package/automattic-vip-2.23.0.tgz +0 -0
  4. package/dist/bin/vip-app-list.js +0 -12
  5. package/dist/bin/vip-app.js +6 -13
  6. package/dist/bin/vip-cache-purge-url.js +4 -19
  7. package/dist/bin/vip-cache.js +0 -2
  8. package/dist/bin/vip-config-envvar-delete.js +4 -19
  9. package/dist/bin/vip-config-envvar-get-all.js +6 -19
  10. package/dist/bin/vip-config-envvar-get.js +4 -15
  11. package/dist/bin/vip-config-envvar-list.js +8 -20
  12. package/dist/bin/vip-config-envvar-set.js +4 -23
  13. package/dist/bin/vip-config-envvar.js +0 -2
  14. package/dist/bin/vip-config-software-get.js +0 -17
  15. package/dist/bin/vip-config-software-update.js +6 -22
  16. package/dist/bin/vip-config-software.js +0 -2
  17. package/dist/bin/vip-config.js +0 -2
  18. package/dist/bin/vip-dev-env-create.js +0 -18
  19. package/dist/bin/vip-dev-env-destroy.js +0 -9
  20. package/dist/bin/vip-dev-env-exec.js +0 -12
  21. package/dist/bin/vip-dev-env-import-media.js +0 -7
  22. package/dist/bin/vip-dev-env-import-sql.js +2 -17
  23. package/dist/bin/vip-dev-env-import.js +0 -3
  24. package/dist/bin/vip-dev-env-info.js +0 -10
  25. package/dist/bin/vip-dev-env-list.js +0 -7
  26. package/dist/bin/vip-dev-env-start.js +4 -14
  27. package/dist/bin/vip-dev-env-stop.js +0 -9
  28. package/dist/bin/vip-dev-env-update.js +0 -11
  29. package/dist/bin/vip-dev-env.js +0 -2
  30. package/dist/bin/vip-import-media-abort.js +0 -18
  31. package/dist/bin/vip-import-media-status.js +0 -12
  32. package/dist/bin/vip-import-media.js +6 -23
  33. package/dist/bin/vip-import-sql-status.js +0 -12
  34. package/dist/bin/vip-import-sql.js +40 -103
  35. package/dist/bin/vip-import-validate-files.js +21 -42
  36. package/dist/bin/vip-import-validate-sql.js +0 -8
  37. package/dist/bin/vip-import.js +0 -3
  38. package/dist/bin/vip-logs.js +20 -50
  39. package/dist/bin/vip-search-replace.js +8 -14
  40. package/dist/bin/vip-sync.js +2 -25
  41. package/dist/bin/vip-validate-preflight.js +427 -0
  42. package/dist/bin/vip-validate.js +19 -0
  43. package/dist/bin/vip-whoami.js +2 -14
  44. package/dist/bin/vip-wp.js +39 -89
  45. package/dist/bin/vip.js +5 -35
  46. package/dist/lib/analytics/clients/pendo.js +9 -18
  47. package/dist/lib/analytics/clients/stub.js +1 -3
  48. package/dist/lib/analytics/clients/tracks.js +11 -20
  49. package/dist/lib/analytics/index.js +4 -11
  50. package/dist/lib/api/app.js +1 -11
  51. package/dist/lib/api/cache-purge.js +4 -7
  52. package/dist/lib/api/feature-flags.js +1 -4
  53. package/dist/lib/api/http.js +9 -15
  54. package/dist/lib/api/user.js +1 -7
  55. package/dist/lib/api.js +17 -19
  56. package/dist/lib/app-logs/app-logs.js +2 -9
  57. package/dist/lib/app.js +2 -5
  58. package/dist/lib/cli/apiConfig.js +4 -19
  59. package/dist/lib/cli/command.js +43 -133
  60. package/dist/lib/cli/config.js +1 -5
  61. package/dist/lib/cli/envAlias.js +14 -15
  62. package/dist/lib/cli/exit.js +4 -6
  63. package/dist/lib/cli/format.js +8 -50
  64. package/dist/lib/cli/progress.js +13 -42
  65. package/dist/lib/cli/prompt.js +1 -5
  66. package/dist/lib/cli/repo.js +7 -20
  67. package/dist/lib/client-file-uploader.js +44 -97
  68. package/dist/lib/config/software.js +2 -52
  69. package/dist/lib/constants/dev-environment.js +1 -2
  70. package/dist/lib/constants/file-size.js +1 -1
  71. package/dist/lib/constants/vipgo.js +1 -1
  72. package/dist/lib/dev-environment/dev-environment-cli.js +68 -155
  73. package/dist/lib/dev-environment/dev-environment-core.js +73 -194
  74. package/dist/lib/dev-environment/dev-environment-lando.js +16 -71
  75. package/dist/lib/env.js +1 -4
  76. package/dist/lib/envvar/api-delete.js +1 -4
  77. package/dist/lib/envvar/api-get-all.js +1 -4
  78. package/dist/lib/envvar/api-get.js +1 -2
  79. package/dist/lib/envvar/api-list.js +3 -4
  80. package/dist/lib/envvar/api-set.js +1 -4
  81. package/dist/lib/envvar/api.js +5 -16
  82. package/dist/lib/envvar/input.js +1 -8
  83. package/dist/lib/envvar/logging.js +2 -6
  84. package/dist/lib/envvar/read-file.js +1 -3
  85. package/dist/lib/http/proxy-agent.js +17 -22
  86. package/dist/lib/keychain/browser.js +1 -4
  87. package/dist/lib/keychain/insecure.js +1 -10
  88. package/dist/lib/keychain/secure.js +1 -8
  89. package/dist/lib/keychain.js +4 -8
  90. package/dist/lib/logout.js +0 -6
  91. package/dist/lib/media-import/media-file-import.js +3 -7
  92. package/dist/lib/media-import/progress.js +6 -17
  93. package/dist/lib/media-import/status.js +14 -65
  94. package/dist/lib/read-file.js +1 -6
  95. package/dist/lib/rollbar.js +1 -7
  96. package/dist/lib/search-and-replace.js +9 -41
  97. package/dist/lib/site-import/db-file-import.js +3 -9
  98. package/dist/lib/site-import/status.js +17 -74
  99. package/dist/lib/token.js +1 -33
  100. package/dist/lib/tracker.js +4 -20
  101. package/dist/lib/user-error.js +0 -2
  102. package/dist/lib/validations/is-multi-site-sql-dump.js +4 -12
  103. package/dist/lib/validations/is-multi-site.js +5 -21
  104. package/dist/lib/validations/is-multisite-domain-mapped.js +5 -31
  105. package/dist/lib/validations/line-by-line.js +4 -16
  106. package/dist/lib/validations/site-type.js +10 -19
  107. package/dist/lib/validations/sql.js +11 -76
  108. package/dist/lib/validations/utils.js +1 -6
  109. package/dist/lib/vip-import-validate-files.js +82 -109
  110. package/npm-shrinkwrap.json +2407 -1800
  111. package/package.json +18 -15
@@ -3,46 +3,27 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.containsAppEnvArgument = containsAppEnvArgument;
6
7
  exports.default = _default;
7
8
  exports.getEnvIdentifier = getEnvIdentifier;
8
- exports.containsAppEnvArgument = containsAppEnvArgument;
9
-
10
9
  var _args = _interopRequireDefault(require("args"));
11
-
12
10
  var _enquirer = require("enquirer");
13
-
14
11
  var _chalk = _interopRequireDefault(require("chalk"));
15
-
16
12
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
17
-
18
13
  var _updateNotifier = _interopRequireDefault(require("update-notifier"));
19
-
20
14
  var _prompt = require("./prompt");
21
-
22
15
  var _api = _interopRequireDefault(require("../api"));
23
-
24
16
  var _app = _interopRequireDefault(require("../api/app"));
25
-
26
17
  var _format = require("./format");
27
-
28
18
  var _package = _interopRequireDefault(require("../../../package.json"));
29
-
30
19
  var _tracker = require("../tracker");
31
-
32
20
  var _envAlias = require("./envAlias");
33
-
34
21
  var _rollbar = require("../rollbar");
35
-
36
22
  var exit = _interopRequireWildcard(require("./exit"));
37
-
38
23
  var _debug = _interopRequireDefault(require("debug"));
39
-
40
24
  var _userError = _interopRequireDefault(require("../user-error"));
41
-
42
25
  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); }
43
-
44
26
  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; }
45
-
46
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
28
 
48
29
  /**
@@ -50,27 +31,26 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
50
31
  */
51
32
 
52
33
  /* eslint-enable no-duplicate-imports */
34
+
53
35
  function uncaughtError(err) {
54
36
  // Error raised when trying to write to an already closed stream
55
37
  if (err.code === 'EPIPE') {
56
38
  return;
57
39
  }
58
-
59
40
  if (err instanceof _userError.default) {
60
41
  exit.withError(err.message);
61
42
  }
62
-
63
43
  console.log(_chalk.default.red('✕'), 'Please contact VIP Support with the following information:');
64
44
  console.log(_chalk.default.dim(err.stack));
65
45
  exit.withError('Unexpected error');
66
46
  }
67
-
68
47
  process.on('uncaughtException', uncaughtError);
69
48
  process.on('unhandledRejection', uncaughtError);
70
49
  let _opts = {};
71
-
72
50
  _args.default.argv = async function (argv, cb) {
73
- const parsedAlias = (0, _envAlias.parseEnvAliasFromArgv)(argv); // A usage option allows us to override the default usage text, which isn't
51
+ const parsedAlias = (0, _envAlias.parseEnvAliasFromArgv)(argv);
52
+
53
+ // A usage option allows us to override the default usage text, which isn't
74
54
  // accurate for subcommands. By default, it will display something like (note
75
55
  // the hyphen):
76
56
  // Usage: vip command-subcommand [options]
@@ -81,7 +61,6 @@ _args.default.argv = async function (argv, cb) {
81
61
  //
82
62
  // It also allows us to represent required args in usage text:
83
63
  // Usage: vip command subcommand <arg1> <arg2> [options]
84
-
85
64
  const name = _opts.usage || null;
86
65
  const options = this.parse(parsedAlias.argv, {
87
66
  help: false,
@@ -89,99 +68,93 @@ _args.default.argv = async function (argv, cb) {
89
68
  version: false,
90
69
  debug: false
91
70
  });
92
-
93
71
  if (options.h || options.help) {
94
72
  this.showHelp();
95
73
  }
96
-
97
74
  if (options.v || options.version) {
98
75
  this.showVersion();
99
76
  }
100
-
101
77
  if (options.debug || options.d) {
102
78
  _debug.default.enable(options.debug === true ? '*' : options.debug);
103
- } // If we have both an --app/--env and an alias, we need to give a warning
104
-
79
+ }
105
80
 
81
+ // If we have both an --app/--env and an alias, we need to give a warning
106
82
  if (parsedAlias.app && (options.app || options.env)) {
107
83
  exit.withError('Please only use an environment alias, or the --app and --env parameters, but not both');
108
- } // If there is an alias, use it to populate the app/env options
109
-
84
+ }
110
85
 
86
+ // If there is an alias, use it to populate the app/env options
111
87
  if (parsedAlias.app) {
112
88
  options.app = parsedAlias.app;
113
89
  options.env = parsedAlias.env; // Can be undefined
114
90
  }
115
91
 
116
92
  const validationError = validateOpts(options);
117
-
118
93
  if (validationError) {
119
94
  const error = validationError.toString();
120
95
  await (0, _tracker.trackEvent)('command_validation_error', {
121
96
  error
122
97
  });
123
98
  exit.withError(error);
124
- } // If there's a sub-command, run that instead
125
-
99
+ }
126
100
 
101
+ // If there's a sub-command, run that instead
127
102
  if (this.isDefined(this.sub[0], 'commands')) {
128
103
  return {};
129
- } // Check for updates every day
130
-
104
+ }
131
105
 
106
+ // Check for updates every day
132
107
  (0, _updateNotifier.default)({
133
108
  pkg: _package.default,
134
109
  isGlobal: true,
135
110
  updateCheckInterval: 1000 * 60 * 60 * 24
136
- }).notify(); // `help` and `version` are always defined as subcommands
111
+ }).notify();
137
112
 
113
+ // `help` and `version` are always defined as subcommands
138
114
  const customCommands = this.details.commands.filter(command => {
139
115
  switch (command.usage) {
140
116
  case 'help':
141
117
  case 'version':
142
118
  case 'debug':
143
119
  return false;
144
-
145
120
  default:
146
121
  return true;
147
122
  }
148
- }); // Show help if no args passed
123
+ });
149
124
 
125
+ // Show help if no args passed
150
126
  if (!!customCommands.length && !this.sub.length) {
151
127
  await (0, _tracker.trackEvent)('command_help_view');
152
128
  this.showHelp();
153
129
  return {};
154
- } // Show help if required arg is missing
155
-
130
+ }
156
131
 
132
+ // Show help if required arg is missing
157
133
  if (_opts.requiredArgs > this.sub.length) {
158
134
  await (0, _tracker.trackEvent)('command_validation_error', {
159
135
  error: 'Missing required arg'
160
136
  });
161
137
  this.showHelp();
162
138
  return {};
163
- } // Show help if subcommand is invalid
164
-
139
+ }
165
140
 
141
+ // Show help if subcommand is invalid
166
142
  const subCommands = this.details.commands.map(cmd => cmd.usage);
167
-
168
143
  if (!_opts.wildcardCommand && this.sub[_opts.requiredArgs] && 0 > subCommands.indexOf(this.sub[_opts.requiredArgs])) {
169
144
  const subcommand = this.sub.join(' ');
170
145
  await (0, _tracker.trackEvent)('command_validation_error', {
171
146
  error: `Invalid subcommand: ${subcommand}`
172
147
  });
173
148
  exit.withError(`\`${subcommand}\` is not a valid subcommand. See \`vip --help\``);
174
- } // Set the site in options.app
175
-
149
+ }
176
150
 
151
+ // Set the site in options.app
177
152
  let res;
178
-
179
153
  if (_opts.appContext) {
180
154
  // If --app is not set, try to infer the app context
181
155
  if (!options.app) {
182
156
  const api = await (0, _api.default)();
183
157
  await (0, _tracker.trackEvent)('command_appcontext_list_fetch');
184
-
185
158
  try {
186
159
  res = await api.query({
187
160
  // $FlowFixMe: gql template is not supported by flow
@@ -198,7 +171,6 @@ _args.default.argv = async function (argv, cb) {
198
171
  variables: {
199
172
  first: 100,
200
173
  after: null // TODO make dynamic?
201
-
202
174
  }
203
175
  });
204
176
  } catch (err) {
@@ -206,22 +178,17 @@ _args.default.argv = async function (argv, cb) {
206
178
  await (0, _tracker.trackEvent)('command_appcontext_list_fetch_error', {
207
179
  error: message
208
180
  });
209
-
210
181
  _rollbar.rollbar.error(err);
211
-
212
182
  exit.withError(`Failed to get app (${_opts.appQuery}) details: ${message}`);
213
183
  }
214
-
215
184
  if (!res || !res.data || !res.data.apps || !res.data.apps.edges || !res.data.apps.edges.length) {
216
185
  await (0, _tracker.trackEvent)('command_appcontext_list_fetch_error', {
217
186
  error: 'No apps found'
218
187
  });
219
188
  exit.withError("Couldn't find any apps");
220
189
  }
221
-
222
190
  const appNames = res.data.apps.edges.map(cur => cur.name);
223
191
  let appSelection;
224
-
225
192
  try {
226
193
  appSelection = await (0, _enquirer.prompt)({
227
194
  type: 'autocomplete',
@@ -234,27 +201,22 @@ _args.default.argv = async function (argv, cb) {
234
201
  if (!err) {
235
202
  process.exit();
236
203
  }
237
-
238
204
  _rollbar.rollbar.error(err);
239
-
240
205
  exit.withError(err.message || err);
241
- } // Copy all app information
242
-
206
+ }
243
207
 
208
+ // Copy all app information
244
209
  appSelection.app = res.data.apps.edges.find(cur => cur.name === appSelection.app);
245
-
246
210
  if (!appSelection || !appSelection.app || !appSelection.app.id) {
247
211
  await (0, _tracker.trackEvent)('command_appcontext_list_select_error', {
248
212
  error: 'Invalid app selected'
249
213
  });
250
214
  exit.withError(`App ${_chalk.default.blueBright(appSelection.app.name)} does not exist`);
251
215
  }
252
-
253
216
  await (0, _tracker.trackEvent)('command_appcontext_list_select_success');
254
217
  options.app = Object.assign({}, appSelection.app);
255
218
  } else {
256
219
  let appLookup;
257
-
258
220
  try {
259
221
  appLookup = await (0, _app.default)(options.app, _opts.appQuery, _opts.appQueryFragments);
260
222
  } catch (err) {
@@ -263,23 +225,19 @@ _args.default.argv = async function (argv, cb) {
263
225
  });
264
226
  exit.withError(`App ${_chalk.default.blueBright(options.app)} does not exist`);
265
227
  }
266
-
267
228
  if (!appLookup || !appLookup.id) {
268
229
  await (0, _tracker.trackEvent)('command_appcontext_param_error', {
269
230
  error: 'Invalid app specified'
270
231
  });
271
232
  exit.withError(`App ${_chalk.default.blueBright(options.app)} does not exist`);
272
233
  }
273
-
274
234
  await (0, _tracker.trackEvent)('command_appcontext_param_select');
275
235
  options.app = Object.assign({}, appLookup);
276
236
  }
277
-
278
237
  if (_opts.childEnvContext) {
279
238
  options.app.environments = options.app.environments.filter(cur => cur.id !== options.app.id);
280
239
  }
281
240
  }
282
-
283
241
  if ((_opts.envContext || _opts.childEnvContext) && options.app) {
284
242
  if (options.env) {
285
243
  if (_opts.childEnvContext && options.env.toLowerCase() === 'production') {
@@ -288,16 +246,13 @@ _args.default.argv = async function (argv, cb) {
288
246
  });
289
247
  exit.withError('Environment production is not allowed for this command');
290
248
  }
291
-
292
249
  const env = options.app.environments.find(cur => getEnvIdentifier(cur) === options.env);
293
-
294
250
  if (!env) {
295
251
  await (0, _tracker.trackEvent)('command_childcontext_param_error', {
296
252
  error: `Invalid child environment (${options.env}) specified`
297
253
  });
298
254
  exit.withError(`Environment ${_chalk.default.blueBright(options.env)} for app ${_chalk.default.blueBright(options.app.name)} does not exist`);
299
255
  }
300
-
301
256
  options.env = env;
302
257
  } else if (!options.app || !options.app.environments || !options.app.environments.length) {
303
258
  console.log('To set up a new development environment, please contact VIP Support.');
@@ -310,7 +265,6 @@ _args.default.argv = async function (argv, cb) {
310
265
  } else if (options.app.environments.length > 1) {
311
266
  const environmentNames = options.app.environments.map(envObject => getEnvIdentifier(envObject));
312
267
  let envSelection;
313
-
314
268
  try {
315
269
  envSelection = await (0, _enquirer.prompt)({
316
270
  type: 'select',
@@ -322,38 +276,32 @@ _args.default.argv = async function (argv, cb) {
322
276
  if (!err) {
323
277
  process.exit();
324
278
  }
325
-
326
279
  _rollbar.rollbar.error(err);
327
-
328
280
  exit.withError(err.message || err);
329
- } // Get full environment info after user selection
330
-
281
+ }
331
282
 
283
+ // Get full environment info after user selection
332
284
  envSelection.env = options.app.environments.find(envObject => getEnvIdentifier(envObject) === envSelection.env);
333
-
334
285
  if (!envSelection || !envSelection.env || !envSelection.env.id) {
335
286
  await (0, _tracker.trackEvent)('command_childcontext_list_select_error', {
336
287
  error: 'Invalid environment selected'
337
288
  });
338
289
  exit.withError(`Environment ${_chalk.default.blueBright(getEnvIdentifier(envSelection.env))} does not exist`);
339
290
  }
340
-
341
291
  await (0, _tracker.trackEvent)('command_childcontext_list_select_success');
342
292
  options.env = envSelection.env;
343
293
  }
344
- } // Prompt for confirmation if necessary
345
-
294
+ }
346
295
 
296
+ // Prompt for confirmation if necessary
347
297
  if (_opts.requireConfirm && !options.force) {
348
298
  const info = [];
349
-
350
299
  if (options.app) {
351
300
  info.push({
352
301
  key: 'App',
353
302
  value: `${options.app.name} (id: ${options.app.id})`
354
303
  });
355
304
  }
356
-
357
305
  if (options.env) {
358
306
  const envName = getEnvIdentifier(options.env);
359
307
  info.push({
@@ -361,28 +309,23 @@ _args.default.argv = async function (argv, cb) {
361
309
  value: `${envName} (id: ${options.env.id})`
362
310
  });
363
311
  }
364
-
365
312
  let message = 'Are you sure?';
366
-
367
313
  if ('string' === typeof _opts.requireConfirm) {
368
314
  message = _opts.requireConfirm;
369
315
  }
370
-
371
316
  switch (_opts.module) {
372
317
  case 'import-sql':
373
318
  const site = options.env;
374
-
375
319
  if (site && site.primaryDomain) {
376
320
  const primaryDomainName = site.primaryDomain.name;
377
321
  info.push({
378
322
  key: 'Primary Domain Name',
379
323
  value: primaryDomainName
380
324
  });
381
- } // Site launched details
382
-
325
+ }
383
326
 
327
+ // Site launched details
384
328
  const haveLaunchedField = site.hasOwnProperty('launched');
385
-
386
329
  if (haveLaunchedField) {
387
330
  const launched = site.launched ? '✅ Yes' : `${_chalk.default.red('x')} No`;
388
331
  info.push({
@@ -390,23 +333,20 @@ _args.default.argv = async function (argv, cb) {
390
333
  value: `${_chalk.default.cyan(launched)}`
391
334
  });
392
335
  }
393
-
394
336
  this.sub && info.push({
395
337
  key: 'SQL File',
396
338
  value: `${_chalk.default.blueBright(this.sub)}`
397
339
  });
398
340
  options.skipValidate = options.hasOwnProperty('skipValidate') && !!options.skipValidate && !['false', 'no'].includes(options.skipValidate);
399
-
400
341
  if (options.skipValidate) {
401
342
  info.push({
402
343
  key: 'Pre-Upload Validations',
403
344
  value: _chalk.default.red('SKIPPED!')
404
345
  });
405
- } // Show S-R params if the `search-replace` flag is set
406
-
346
+ }
407
347
 
348
+ // Show S-R params if the `search-replace` flag is set
408
349
  const searchReplace = options.searchReplace;
409
-
410
350
  const assignSRValues = (from, to) => {
411
351
  const pairs = {
412
352
  From: `${from}`,
@@ -414,33 +354,30 @@ _args.default.argv = async function (argv, cb) {
414
354
  };
415
355
  return pairs;
416
356
  };
417
-
418
357
  if (searchReplace) {
419
- const searchReplaceValues = (0, _format.formatSearchReplaceValues)(searchReplace, assignSRValues); // Format data into a user-friendly table
358
+ const searchReplaceValues = (0, _format.formatSearchReplaceValues)(searchReplace, assignSRValues);
420
359
 
360
+ // Format data into a user-friendly table
421
361
  info.push({
422
362
  key: 'Replacements',
423
363
  value: '\n' + (0, _format.formatData)(searchReplaceValues, 'table')
424
364
  });
425
365
  }
426
-
427
366
  break;
428
-
429
367
  case 'sync':
430
368
  const {
431
369
  backup,
432
370
  canSync,
433
371
  errors
434
372
  } = options.env.syncPreview;
435
-
436
373
  if (!canSync) {
437
374
  // User can not sync due to some error(s)
438
375
  // Shows the first error in the array
439
376
  exit.withError(`Could not sync to this environment: ${errors[0].message}`);
440
- } // remove __typename from replacements.
441
- // can not be deleted afterwards if deconstructed
442
-
377
+ }
443
378
 
379
+ // remove __typename from replacements.
380
+ // can not be deleted afterwards if deconstructed
444
381
  const replacements = options.env.syncPreview.replacements.map(rep => {
445
382
  const {
446
383
  from,
@@ -451,20 +388,17 @@ _args.default.argv = async function (argv, cb) {
451
388
  to
452
389
  };
453
390
  });
454
-
455
391
  if (backup) {
456
392
  info.push({
457
393
  key: 'From backup',
458
394
  value: new Date(backup.createdAt).toUTCString()
459
395
  });
460
396
  }
461
-
462
397
  info.push({
463
398
  key: 'Replacements',
464
399
  value: '\n' + (0, _format.formatData)(replacements, 'table')
465
400
  });
466
401
  break;
467
-
468
402
  case 'import-media':
469
403
  info.push({
470
404
  key: 'Archive URL',
@@ -486,38 +420,29 @@ _args.default.argv = async function (argv, cb) {
486
420
  value: options.exportFileErrorsToJson ? '✅ Yes' : `${_chalk.default.red('x')} No`
487
421
  });
488
422
  break;
489
-
490
423
  default:
491
424
  }
492
-
493
425
  const skipPrompt = _opts.skipConfirmPrompt || false;
494
426
  const yes = await (0, _prompt.confirm)(info, message, skipPrompt);
495
-
496
427
  if (!yes) {
497
428
  await (0, _tracker.trackEvent)('command_confirm_cancel');
498
429
  return {};
499
430
  }
500
-
501
431
  await (0, _tracker.trackEvent)('command_confirm_success');
502
432
  }
503
-
504
433
  if (cb) {
505
434
  res = await cb(this.sub, options);
506
-
507
435
  if (_opts.format && res) {
508
436
  if (res.header) {
509
437
  console.log((0, _format.formatData)(res.header, 'keyValue'));
510
438
  res = res.data;
511
439
  }
512
-
513
440
  res = res.map(row => {
514
441
  const out = Object.assign({}, row);
515
-
516
442
  if (out.__typename) {
517
443
  // Apollo injects __typename
518
444
  delete out.__typename;
519
445
  }
520
-
521
446
  return out;
522
447
  });
523
448
  await (0, _tracker.trackEvent)('command_output', {
@@ -528,32 +453,26 @@ _args.default.argv = async function (argv, cb) {
528
453
  return {};
529
454
  }
530
455
  }
531
-
532
456
  return options;
533
457
  };
534
-
535
458
  function validateOpts(opts) {
536
459
  if (opts.app) {
537
460
  if (typeof opts.app !== 'string' && typeof opts.app !== 'number') {
538
461
  return new Error('Invalid --app');
539
462
  }
540
-
541
463
  if (opts.app.length < 1) {
542
464
  return new Error('Invalid --app');
543
465
  }
544
466
  }
545
-
546
467
  if (opts.env) {
547
468
  if (typeof opts.env !== 'string' && typeof opts.env !== 'number') {
548
469
  return new Error('Invalid --env');
549
470
  }
550
-
551
471
  if (opts.env.length < 1) {
552
472
  return new Error('Invalid --env');
553
473
  }
554
474
  }
555
475
  }
556
-
557
476
  function _default(opts) {
558
477
  _opts = Object.assign({
559
478
  appContext: false,
@@ -565,44 +484,35 @@ function _default(opts) {
565
484
  requiredArgs: 0,
566
485
  wildcardCommand: false
567
486
  }, opts);
568
-
569
487
  if (_opts.appContext || _opts.requireConfirm) {
570
488
  _args.default.option('app', 'Specify the app');
571
489
  }
572
-
573
490
  if (_opts.envContext || _opts.childEnvContext) {
574
491
  _args.default.option('env', 'Specify the environment');
575
492
  }
576
-
577
493
  if (_opts.requireConfirm) {
578
494
  _args.default.option('force', 'Skip confirmation', false);
579
495
  }
580
-
581
496
  if (_opts.format) {
582
497
  _args.default.option('format', 'Format results', 'table');
583
- } // Add help and version to all subcommands
584
-
498
+ }
585
499
 
500
+ // Add help and version to all subcommands
586
501
  _args.default.option('help', 'Output the help for the (sub)command');
587
-
588
502
  _args.default.option('version', 'Output the version number');
589
-
590
503
  _args.default.option('debug', 'Activate debug output');
591
-
592
504
  return _args.default;
593
505
  }
594
-
595
506
  function getEnvIdentifier(env) {
596
- let identifier = env.type; // If the env has a unique name (happens when site has multiple envs of a type), add on name
597
- // for disambiguation. Only on non-main-env
507
+ let identifier = env.type;
598
508
 
509
+ // If the env has a unique name (happens when site has multiple envs of a type), add on name
510
+ // for disambiguation. Only on non-main-env
599
511
  if (env.name !== env.type && env.name && env.appId !== env.id) {
600
512
  identifier = `${identifier}.${env.name}`;
601
513
  }
602
-
603
514
  return identifier;
604
515
  }
605
-
606
516
  function containsAppEnvArgument(argv) {
607
517
  const parsedAlias = (0, _envAlias.parseEnvAliasFromArgv)(argv);
608
518
  return !!(parsedAlias.app || parsedAlias.env || argv.includes('--app') || argv.includes('--env'));
@@ -4,17 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _debug = _interopRequireDefault(require("debug"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  /**
13
10
  * External dependencies
14
11
  */
12
+
15
13
  const debug = (0, _debug.default)('@automattic/vip:lib:cli:config');
16
14
  let configFromFile = {};
17
-
18
15
  try {
19
16
  // Get `local` config first; this will only exist in dev as it's npmignore-d.
20
17
  configFromFile = require("../../../config/config.local.json");
@@ -24,7 +21,6 @@ try {
24
21
  configFromFile = require("../../../config/config.publish.json");
25
22
  debug('Loaded config data from config.publish.json');
26
23
  }
27
-
28
24
  const config = Object.assign({}, configFromFile);
29
25
  var _default = config;
30
26
  exports.default = _default;
@@ -3,55 +3,54 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+
6
7
  exports.isAlias = function (alias) {
7
8
  return /^@[A-Za-z0-9\.\-]+$/.test(alias);
8
9
  };
9
-
10
10
  exports.parseEnvAlias = function (alias) {
11
11
  if (!exports.isAlias(alias)) {
12
12
  throw new Error('Invalid environment alias. Aliases are in the format of @app-name or @app-name.environment-name');
13
- } // Remove the '@'
13
+ }
14
14
 
15
+ // Remove the '@'
16
+ const stripped = alias.substr(1).toLowerCase();
15
17
 
16
- const stripped = alias.substr(1).toLowerCase(); // in JS, .split() with a limit discards the extra ones, so can't use it
18
+ // in JS, .split() with a limit discards the extra ones, so can't use it
17
19
  // Also convert to lowercase because mixed case environment names would cause problems
18
-
19
20
  const [app, ...rest] = stripped.split('.');
20
- let env = undefined; // Rejoin the env on '.' (if present), to handle instance names (env.instance-01)
21
+ let env = undefined;
21
22
 
23
+ // Rejoin the env on '.' (if present), to handle instance names (env.instance-01)
22
24
  if (rest && rest.length) {
23
25
  env = rest.join('.');
24
26
  }
25
-
26
27
  return {
27
28
  app,
28
29
  env
29
30
  };
30
31
  };
31
-
32
32
  exports.parseEnvAliasFromArgv = function (processArgv) {
33
33
  // Clone to not affect original arvg
34
- const argv = processArgv.slice(0); // If command included a `--` to indicate end of named args, lets only consider aliases
35
- // _before_ it, so that it can be passed to other commands directly
34
+ const argv = processArgv.slice(0);
36
35
 
36
+ // If command included a `--` to indicate end of named args, lets only consider aliases
37
+ // _before_ it, so that it can be passed to other commands directly
37
38
  const dashDashIndex = argv.indexOf('--');
38
39
  let argsBeforeDashDash = argv;
39
-
40
40
  if (dashDashIndex > -1) {
41
41
  argsBeforeDashDash = argv.slice(0, dashDashIndex);
42
42
  }
43
-
44
43
  const alias = argsBeforeDashDash.find(arg => exports.isAlias(arg));
45
-
46
44
  if (!alias) {
47
45
  return {
48
46
  argv
49
47
  };
50
- } // If we did have an alias, split it up into app/env
51
-
48
+ }
52
49
 
53
- const parsedAlias = exports.parseEnvAlias(alias); // Splice out the alias
50
+ // If we did have an alias, split it up into app/env
51
+ const parsedAlias = exports.parseEnvAlias(alias);
54
52
 
53
+ // Splice out the alias
55
54
  argv.splice(argv.indexOf(alias), 1);
56
55
  return {
57
56
  argv,