@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,59 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.startEnvironment = startEnvironment;
7
- exports.stopEnvironment = stopEnvironment;
8
6
  exports.createEnvironment = createEnvironment;
9
- exports.updateEnvironment = updateEnvironment;
10
7
  exports.destroyEnvironment = destroyEnvironment;
8
+ exports.doesEnvironmentExist = doesEnvironmentExist;
9
+ exports.exec = exec;
10
+ exports.fetchVersionList = fetchVersionList;
11
+ exports.getApplicationInformation = getApplicationInformation;
12
+ exports.getEnvironmentPath = getEnvironmentPath;
13
+ exports.getVersionList = getVersionList;
14
+ exports.importMediaPath = importMediaPath;
11
15
  exports.printAllEnvironmentsInfo = printAllEnvironmentsInfo;
12
16
  exports.printEnvironmentInfo = printEnvironmentInfo;
13
- exports.exec = exec;
14
- exports.doesEnvironmentExist = doesEnvironmentExist;
15
17
  exports.readEnvironmentData = readEnvironmentData;
16
- exports.getEnvironmentPath = getEnvironmentPath;
17
- exports.getApplicationInformation = getApplicationInformation;
18
18
  exports.resolveImportPath = resolveImportPath;
19
- exports.importMediaPath = importMediaPath;
20
- exports.fetchVersionList = fetchVersionList;
21
- exports.getVersionList = getVersionList;
22
-
19
+ exports.startEnvironment = startEnvironment;
20
+ exports.stopEnvironment = stopEnvironment;
21
+ exports.updateEnvironment = updateEnvironment;
23
22
  var _debug = _interopRequireDefault(require("debug"));
24
-
25
23
  var _xdgBasedir = _interopRequireDefault(require("xdg-basedir"));
26
-
27
24
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
28
-
29
25
  var _os = _interopRequireDefault(require("os"));
30
-
31
26
  var _fs = _interopRequireDefault(require("fs"));
32
-
33
27
  var _ejs = _interopRequireDefault(require("ejs"));
34
-
35
28
  var _path = _interopRequireDefault(require("path"));
36
-
37
29
  var _chalk = _interopRequireDefault(require("chalk"));
38
-
39
30
  var _enquirer = require("enquirer");
40
-
41
31
  var _copyDir = _interopRequireDefault(require("copy-dir"));
42
-
43
32
  var _devEnvironmentLando = require("./dev-environment-lando");
44
-
45
33
  var _searchAndReplace = require("../search-and-replace");
46
-
47
34
  var _devEnvironmentCli = require("./dev-environment-cli");
48
-
49
35
  var _app = _interopRequireDefault(require("../api/app"));
50
-
51
36
  var _devEnvironment = require("../constants/dev-environment");
52
-
53
37
  var _software = require("../config/software");
54
-
55
38
  var _userError = _interopRequireDefault(require("../user-error"));
56
-
57
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
-
59
40
  /**
60
41
  *
61
42
  * @format
@@ -68,136 +49,104 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
68
49
  /**
69
50
  * Internal dependencies
70
51
  */
71
- const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
72
52
 
53
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
73
54
  const landoFileTemplatePath = _path.default.join(__dirname, '..', '..', '..', 'assets', 'dev-env.lando.template.yml.ejs');
74
-
75
55
  const nginxFileTemplatePath = _path.default.join(__dirname, '..', '..', '..', 'assets', 'dev-env.nginx.template.conf.ejs');
76
-
77
56
  const landoFileName = '.lando.yml';
78
57
  const nginxFileName = 'extra.conf';
79
58
  const instanceDataFileName = 'instance_data.json';
80
59
  const homeDirPathInsideContainers = '/user';
81
60
  const uploadPathString = 'uploads';
82
61
  const nginxPathString = 'nginx';
83
-
84
62
  async function startEnvironment(slug, options) {
85
63
  debug('Will start an environment', slug);
86
64
  const instancePath = getEnvironmentPath(slug);
87
65
  debug('Instance path for', slug, 'is:', instancePath);
88
-
89
66
  const environmentExists = _fs.default.existsSync(instancePath);
90
-
91
67
  if (!environmentExists) {
92
68
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
93
69
  }
94
-
95
70
  let updated = false;
96
-
97
71
  if (!options.skipWpVersionsCheck) {
98
72
  updated = await updateWordPressImage(slug);
99
73
  }
100
-
101
74
  if (options.skipRebuild && !updated) {
102
75
  await (0, _devEnvironmentLando.landoStart)(instancePath);
103
76
  } else {
104
77
  await (0, _devEnvironmentLando.landoRebuild)(instancePath);
105
78
  }
106
-
107
79
  await printEnvironmentInfo(slug, {
108
80
  extended: false
109
81
  });
110
82
  }
111
-
112
83
  async function stopEnvironment(slug) {
113
84
  debug('Will stop an environment', slug);
114
85
  const instancePath = getEnvironmentPath(slug);
115
86
  debug('Instance path for', slug, 'is:', instancePath);
116
-
117
87
  const environmentExists = _fs.default.existsSync(instancePath);
118
-
119
88
  if (!environmentExists) {
120
89
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
121
90
  }
122
-
123
91
  await (0, _devEnvironmentLando.landoStop)(instancePath);
124
92
  }
125
-
126
93
  async function createEnvironment(instanceData) {
127
94
  const slug = instanceData.siteSlug;
128
95
  debug('Will create an environment', slug, 'with instanceData: ', instanceData);
129
96
  const instancePath = getEnvironmentPath(slug);
130
97
  debug('Instance path for', slug, 'is:', instancePath);
131
-
132
98
  const alreadyExists = _fs.default.existsSync(instancePath);
133
-
134
99
  if (alreadyExists) {
135
100
  throw new Error('Environment already exists.');
136
101
  }
137
-
138
102
  const preProcessedInstanceData = preProcessInstanceData(instanceData);
139
103
  await prepareLandoEnv(preProcessedInstanceData, instancePath);
140
104
  }
141
-
142
105
  async function updateEnvironment(instanceData) {
143
106
  const slug = instanceData.siteSlug;
144
107
  debug('Will update an environment', slug, 'with instanceData: ', instanceData);
145
108
  const instancePath = getEnvironmentPath(slug);
146
109
  debug('Instance path for', slug, 'is:', instancePath);
147
-
148
110
  const alreadyExists = _fs.default.existsSync(instancePath);
149
-
150
111
  if (!alreadyExists) {
151
112
  throw new Error('Environment doesn\'t exist.');
152
113
  }
153
-
154
114
  const preProcessedInstanceData = preProcessInstanceData(instanceData);
155
115
  await prepareLandoEnv(preProcessedInstanceData, instancePath);
156
116
  }
157
-
158
117
  function preProcessInstanceData(instanceData) {
159
- const newInstanceData = { ...instanceData
118
+ const newInstanceData = {
119
+ ...instanceData
160
120
  };
161
-
162
121
  if (instanceData.mediaRedirectDomain && !instanceData.mediaRedirectDomain.match(/^http/)) {
163
122
  // We need to make sure the redirect is an absolute path
164
123
  newInstanceData.mediaRedirectDomain = `https://${instanceData.mediaRedirectDomain}`;
165
124
  }
166
-
167
125
  newInstanceData.elasticsearch = instanceData.elasticsearch || false;
168
126
  newInstanceData.php = instanceData.php || _devEnvironment.DEV_ENVIRONMENT_PHP_VERSIONS.default;
169
-
170
127
  if (newInstanceData.php.startsWith('image:')) {
171
128
  newInstanceData.php = newInstanceData.php.slice('image:'.length);
172
129
  }
173
-
174
130
  if (!newInstanceData.xdebugConfig) {
175
131
  newInstanceData.xdebugConfig = '';
176
132
  }
177
-
178
133
  return newInstanceData;
179
134
  }
180
-
181
135
  async function destroyEnvironment(slug, removeFiles) {
182
136
  debug('Will destroy an environment', slug);
183
137
  const instancePath = getEnvironmentPath(slug);
184
138
  debug('Instance path for', slug, 'is:', instancePath);
185
-
186
139
  const environmentExists = _fs.default.existsSync(instancePath);
187
-
188
140
  if (!environmentExists) {
189
141
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
190
142
  }
191
-
192
143
  const landoFilePath = _path.default.join(instancePath, landoFileName);
193
-
194
144
  if (_fs.default.existsSync(landoFilePath)) {
195
145
  debug('Lando file exists, will lando destroy.');
196
146
  await (0, _devEnvironmentLando.landoDestroy)(instancePath);
197
147
  } else {
198
148
  debug("Lando file doesn't exist, skipping lando destroy.");
199
149
  }
200
-
201
150
  if (removeFiles) {
202
151
  await _fs.default.promises.rm(instancePath, {
203
152
  recursive: true
@@ -205,39 +154,30 @@ async function destroyEnvironment(slug, removeFiles) {
205
154
  console.log(`${_chalk.default.green('✓')} Environment files deleted successfully.`);
206
155
  }
207
156
  }
208
-
209
157
  async function printAllEnvironmentsInfo(options) {
210
158
  const allEnvNames = getAllEnvironmentNames();
211
159
  debug('Will print info for all environments. Names found: ', allEnvNames);
212
160
  console.log('Found ' + _chalk.default.bold(allEnvNames.length) + ' environments' + (allEnvNames.length ? ':' : '.'));
213
-
214
161
  for (const envName of allEnvNames) {
215
162
  console.log('\n');
216
163
  await printEnvironmentInfo(envName, options);
217
164
  }
218
165
  }
219
-
220
166
  function parseComponentForInfo(component) {
221
167
  if (component.mode === 'local') {
222
168
  return component.dir || '';
223
169
  }
224
-
225
170
  return component.tag || '[demo-image]';
226
171
  }
227
-
228
172
  async function printEnvironmentInfo(slug, options) {
229
173
  debug('Will get info for an environment', slug);
230
174
  const instancePath = getEnvironmentPath(slug);
231
175
  debug('Instance path for', slug, 'is:', instancePath);
232
-
233
176
  const environmentExists = _fs.default.existsSync(instancePath);
234
-
235
177
  if (!environmentExists) {
236
178
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
237
179
  }
238
-
239
180
  const appInfo = await (0, _devEnvironmentLando.landoInfo)(instancePath);
240
-
241
181
  if (options.extended) {
242
182
  const environmentData = readEnvironmentData(slug);
243
183
  appInfo.title = environmentData.wpTitle;
@@ -246,131 +186,95 @@ async function printEnvironmentInfo(slug, options) {
246
186
  appInfo.wordpress = parseComponentForInfo(environmentData.wordpress);
247
187
  appInfo['Mu plugins'] = parseComponentForInfo(environmentData.muPlugins);
248
188
  appInfo['App Code'] = parseComponentForInfo(environmentData.appCode);
249
-
250
189
  if (environmentData.mediaRedirectDomain) {
251
190
  appInfo['Media Redirect'] = environmentData.mediaRedirectDomain;
252
191
  }
253
192
  }
254
-
255
193
  (0, _devEnvironmentCli.printTable)(appInfo);
256
194
  }
257
-
258
195
  async function exec(slug, args, options = {}) {
259
196
  debug('Will run a wp command on env', slug, 'with args', args, ' and options', options);
260
197
  const instancePath = getEnvironmentPath(slug);
261
198
  debug('Instance path for', slug, 'is:', instancePath);
262
-
263
199
  const environmentExists = _fs.default.existsSync(instancePath);
264
-
265
200
  if (!environmentExists) {
266
201
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
267
202
  }
268
-
269
203
  const command = args.shift();
270
204
  const commandArgs = [...args];
271
205
  await (0, _devEnvironmentLando.landoExec)(instancePath, command, commandArgs, options);
272
206
  }
273
-
274
207
  function doesEnvironmentExist(slug) {
275
208
  debug('Will check for environment', slug);
276
209
  const instancePath = getEnvironmentPath(slug);
277
210
  debug('Instance path for', slug, 'is:', instancePath);
278
211
  return _fs.default.existsSync(instancePath);
279
212
  }
280
-
281
213
  function readEnvironmentData(slug) {
282
214
  debug('Will try to get instance data for environment', slug);
283
215
  const instancePath = getEnvironmentPath(slug);
284
-
285
216
  const instanceDataTargetPath = _path.default.join(instancePath, instanceDataFileName);
286
-
287
217
  const instanceDataString = _fs.default.readFileSync(instanceDataTargetPath, 'utf8');
288
-
289
218
  const instanceData = JSON.parse(instanceDataString);
219
+
290
220
  /**
291
221
  ***********************************
292
222
  * BACKWARDS COMPATIBILITY SECTION
293
223
  ***********************************/
294
- // REMOVEME after the wheel of time spins around few times
295
224
 
225
+ // REMOVEME after the wheel of time spins around few times
296
226
  if (instanceData.enterpriseSearchEnabled || instanceData.elasticsearchEnabled) {
297
227
  // enterpriseSearchEnabled and elasticsearchEnabled was renamed to elasticsearch
298
228
  instanceData.elasticsearch = instanceData.enterpriseSearchEnabled || instanceData.elasticsearchEnabled;
299
- } // REMOVEME after the wheel of time spins around few times
300
-
229
+ }
301
230
 
231
+ // REMOVEME after the wheel of time spins around few times
302
232
  if (instanceData.clientCode) {
303
233
  // clientCode was renamed to appCode
304
234
  instanceData.appCode = instanceData.clientCode;
305
235
  }
306
-
307
236
  return instanceData;
308
237
  }
309
-
310
238
  async function prepareLandoEnv(instanceData, instancePath) {
311
239
  const landoFile = await _ejs.default.renderFile(landoFileTemplatePath, instanceData);
312
240
  const nginxFile = await _ejs.default.renderFile(nginxFileTemplatePath, instanceData);
313
241
  const instanceDataFile = JSON.stringify(instanceData);
314
-
315
242
  const landoFileTargetPath = _path.default.join(instancePath, landoFileName);
316
-
317
243
  const nginxFolderPath = _path.default.join(instancePath, nginxPathString);
318
-
319
244
  const nginxFileTargetPath = _path.default.join(nginxFolderPath, nginxFileName);
320
-
321
245
  const instanceDataTargetPath = _path.default.join(instancePath, instanceDataFileName);
322
-
323
- _fs.default.mkdirSync(instancePath, {
246
+ await _fs.default.promises.mkdir(instancePath, {
324
247
  recursive: true
325
248
  });
326
-
327
- _fs.default.mkdirSync(nginxFolderPath, {
249
+ await _fs.default.promises.mkdir(nginxFolderPath, {
328
250
  recursive: true
329
251
  });
330
-
331
- _fs.default.writeFileSync(landoFileTargetPath, landoFile);
332
-
333
- _fs.default.writeFileSync(nginxFileTargetPath, nginxFile);
334
-
335
- _fs.default.writeFileSync(instanceDataTargetPath, instanceDataFile);
336
-
252
+ await Promise.all([_fs.default.promises.writeFile(landoFileTargetPath, landoFile), _fs.default.promises.writeFile(nginxFileTargetPath, nginxFile), _fs.default.promises.writeFile(instanceDataTargetPath, instanceDataFile)]);
337
253
  debug(`Lando file created in ${landoFileTargetPath}`);
338
254
  debug(`Nginx file created in ${nginxFileTargetPath}`);
339
255
  debug(`Instance data file created in ${instanceDataTargetPath}`);
340
256
  }
341
-
342
257
  function getAllEnvironmentNames() {
343
258
  const mainEnvironmentPath = _xdgBasedir.default.data || _os.default.tmpdir();
344
-
345
259
  const baseDir = _path.default.join(mainEnvironmentPath, 'vip', 'dev-environment');
346
-
347
260
  const doWeHaveAnyEnvironment = _fs.default.existsSync(baseDir);
348
-
349
261
  let envNames = [];
350
-
351
262
  if (doWeHaveAnyEnvironment) {
352
263
  const files = _fs.default.readdirSync(baseDir);
353
-
354
264
  envNames = files.filter(file => {
355
265
  const fullPath = _path.default.join(baseDir, file);
356
-
357
266
  return _fs.default.lstatSync(fullPath).isDirectory();
358
267
  });
359
268
  }
360
-
361
269
  return envNames;
362
270
  }
363
-
364
271
  function getEnvironmentPath(name) {
365
272
  if (!name) {
366
273
  throw new Error('Name was not provided');
367
274
  }
368
-
369
275
  const mainEnvironmentPath = _xdgBasedir.default.data || _os.default.tmpdir();
370
-
371
276
  return _path.default.join(mainEnvironmentPath, 'vip', 'dev-environment', name + '');
372
277
  }
373
-
374
278
  async function getApplicationInformation(appId, envType) {
375
279
  // $FlowFixMe: gql template is not supported by flow
376
280
  const fieldsQuery = `
@@ -400,16 +304,13 @@ async function getApplicationInformation(appId, envType) {
400
304
  }`;
401
305
  const queryResult = await (0, _app.default)(appId, fieldsQuery, _software.appQueryFragments);
402
306
  const appData = {};
403
-
404
307
  if (queryResult) {
405
308
  var _queryResult$reposito;
406
-
407
309
  appData.id = queryResult.id;
408
310
  appData.name = queryResult.name;
409
311
  appData.repository = (_queryResult$reposito = queryResult.repository) === null || _queryResult$reposito === void 0 ? void 0 : _queryResult$reposito.htmlUrl;
410
312
  const environments = queryResult.environments || [];
411
313
  let envData;
412
-
413
314
  if (envType) {
414
315
  envData = environments.find(candidateEnv => candidateEnv.type === envType);
415
316
  } else if (1 === environments.length) {
@@ -426,10 +327,8 @@ async function getApplicationInformation(appId, envType) {
426
327
  });
427
328
  envData = environments.find(candidateEnv => candidateEnv.type === env);
428
329
  }
429
-
430
330
  if (envData) {
431
331
  var _envData$primaryDomai, _envData$softwareSett, _envData$softwareSett2, _envData$softwareSett3, _envData$softwareSett4, _envData$softwareSett5, _envData$softwareSett6;
432
-
433
332
  appData.environment = {
434
333
  name: envData.name,
435
334
  branch: envData.branch,
@@ -441,24 +340,26 @@ async function getApplicationInformation(appId, envType) {
441
340
  };
442
341
  }
443
342
  }
444
-
445
343
  return appData;
446
344
  }
447
-
448
345
  async function resolveImportPath(slug, fileName, searchReplace, inPlace) {
449
346
  debug(`Will try to resolve path - ${fileName}`);
450
347
  let resolvedPath = (0, _devEnvironmentCli.resolvePath)(fileName);
348
+ const instancePath = getEnvironmentPath(slug);
349
+ debug(`Instance path for ${slug} is ${instancePath}`);
350
+ const environmentExists = _fs.default.existsSync(instancePath);
351
+ if (!environmentExists) {
352
+ throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
353
+ }
451
354
  debug(`Filename ${fileName} resolved to ${resolvedPath}`);
452
-
453
355
  if (!_fs.default.existsSync(resolvedPath)) {
454
356
  throw new _userError.default(`The provided file ${resolvedPath} does not exist or it is not valid (see "--help" for examples)`);
455
357
  }
456
-
457
358
  if (_fs.default.lstatSync(resolvedPath).isDirectory()) {
458
359
  throw new _userError.default(`The provided file ${resolvedPath} is a directory. Please point to a sql file.`);
459
- } // Run Search and Replace if the --search-replace flag was provided
460
-
360
+ }
461
361
 
362
+ // Run Search and Replace if the --search-replace flag was provided
462
363
  if (searchReplace && searchReplace.length) {
463
364
  const {
464
365
  outputFileName
@@ -467,71 +368,53 @@ async function resolveImportPath(slug, fileName, searchReplace, inPlace) {
467
368
  output: true,
468
369
  inPlace
469
370
  });
470
-
471
371
  if (typeof outputFileName !== 'string') {
472
372
  throw new Error('Unable to determine location of the intermediate search & replace file.');
473
373
  }
474
-
475
- const environmentPath = getEnvironmentPath(slug);
476
-
477
374
  const baseName = _path.default.basename(outputFileName);
478
-
479
- resolvedPath = _path.default.join(environmentPath, baseName);
480
-
375
+ resolvedPath = _path.default.join(instancePath, baseName);
481
376
  _fs.default.renameSync(outputFileName, resolvedPath);
482
377
  }
378
+
483
379
  /**
484
380
  * Docker container does not have acces to the host filesystem.
485
381
  * However lando maps os.homedir() to /user in the container. So if we replace the path in the same way
486
382
  * in the Docker container will get the file from within the mapped volume under /user.
487
383
  */
488
-
489
-
490
384
  let inContainerPath = resolvedPath.replace(_os.default.homedir(), homeDirPathInsideContainers);
491
-
492
385
  if (_path.default.sep === '\\') {
493
386
  // Because the file path generated for windows will have \ instead of / we need to replace that as well so that the path inside the container (unix) still works.
494
387
  inContainerPath = inContainerPath.replace(/\\/g, '/');
495
388
  }
496
-
497
389
  debug(`Import file path ${resolvedPath} will be mapped to ${inContainerPath}`);
498
390
  return {
499
391
  resolvedPath,
500
392
  inContainerPath
501
393
  };
502
394
  }
503
-
504
395
  async function importMediaPath(slug, filePath) {
505
396
  const resolvedPath = (0, _devEnvironmentCli.resolvePath)(filePath);
506
-
507
397
  if (!_fs.default.existsSync(resolvedPath) || !_fs.default.lstatSync(resolvedPath).isDirectory()) {
508
398
  throw new Error('The provided path does not exist or it is not valid (see "--help" for examples)');
509
399
  }
510
-
511
400
  const files = _fs.default.readdirSync(resolvedPath);
512
-
513
401
  if (files.indexOf(uploadPathString) > -1) {
514
402
  const confirm = await (0, _enquirer.prompt)({
515
403
  type: 'confirm',
516
404
  name: 'continue',
517
405
  message: 'The provided path contains an uploads folder inside. Do you want to continue?'
518
406
  });
519
-
520
407
  if (!confirm.continue) {
521
408
  return;
522
409
  }
523
410
  }
524
-
525
411
  const environmentPath = getEnvironmentPath(slug);
526
-
527
412
  const uploadsPath = _path.default.join(environmentPath, uploadPathString);
528
-
529
413
  console.log(`${_chalk.default.yellow('-')} Started copying files`);
530
-
531
414
  _copyDir.default.sync(resolvedPath, uploadsPath);
532
-
533
415
  console.log(`${_chalk.default.green('✓')} Files successfully copied to ${uploadsPath}.`);
534
416
  }
417
+
535
418
  /**
536
419
  * Uses the WordPress versions manifest on github.com
537
420
  * Informs the user several things:
@@ -542,12 +425,11 @@ async function importMediaPath(slug, filePath) {
542
425
  * @param {Object=} slug slug
543
426
  * @return {boolean} boolean
544
427
  */
545
-
546
-
547
428
  async function updateWordPressImage(slug) {
548
429
  const versions = await getVersionList();
549
- let message, envData, currentWordPressTag; // Get the current environment configuration
430
+ let message, envData, currentWordPressTag;
550
431
 
432
+ // Get the current environment configuration
551
433
  try {
552
434
  envData = readEnvironmentData(slug);
553
435
  currentWordPressTag = envData.wordpress.tag;
@@ -559,131 +441,128 @@ async function updateWordPressImage(slug) {
559
441
  } else {
560
442
  message = `An error prevented reading the configuration of: ${slug}\n\n ${error}`;
561
443
  }
562
-
563
444
  (0, _devEnvironmentCli.handleCLIException)(new Error(message));
564
445
  return false;
565
- } // sort
566
-
446
+ }
567
447
 
568
- versions.sort((before, after) => before.tag < after.tag ? 1 : -1); // Newest WordPress Image but that is not trunk
448
+ // sort
449
+ versions.sort((before, after) => before.tag < after.tag ? 1 : -1);
569
450
 
451
+ // Newest WordPress Image but that is not trunk
570
452
  const newestWordPressImage = versions.find(({
571
453
  tag
572
454
  }) => tag !== 'trunk');
573
- console.log('The most recent WordPress version available is: ' + _chalk.default.green(newestWordPressImage.tag)); // If the currently used version is the most up to date: exit.
455
+ console.log('The most recent WordPress version available is: ' + _chalk.default.green(newestWordPressImage.tag));
574
456
 
457
+ // If the currently used version is the most up to date: exit.
575
458
  if (currentWordPressTag === newestWordPressImage.tag) {
576
459
  console.log('Environment WordPress version is: ' + _chalk.default.green(currentWordPressTag) + ' ... 😎 nice! ');
577
460
  return false;
578
- } // Determine if there is an image available for the current WordPress version
579
-
461
+ }
580
462
 
463
+ // Determine if there is an image available for the current WordPress version
581
464
  const match = versions.find(({
582
465
  tag
583
- }) => tag === currentWordPressTag); // If there is no available image for the currently installed version, give user a path to change
466
+ }) => tag === currentWordPressTag);
584
467
 
468
+ // If there is no available image for the currently installed version, give user a path to change
585
469
  if (typeof match === 'undefined') {
586
470
  console.log(`Installed WordPress: ${currentWordPressTag} has no available container image in repository. `);
587
471
  console.log('You must select a new WordPress image to continue... ');
588
472
  } else {
589
473
  console.log('Environment WordPress version is: ' + _chalk.default.yellow(`${match.tag} (${match.ref})`));
590
-
591
- if (envData.wordpress.doNotUpgrade || false) {
474
+ if (envData.wordpress.doNotUpgrade) {
592
475
  return false;
593
476
  }
594
- } // Prompt the user to select a new WordPress Version
595
-
477
+ }
596
478
 
479
+ // Prompt the user to select a new WordPress Version
597
480
  const confirm = await (0, _enquirer.prompt)({
598
481
  type: 'select',
599
482
  name: 'upgrade',
600
483
  message: 'Would You like to change the WordPress version? ',
601
484
  choices: ['yes', 'no', "no (don't ask anymore)"]
602
- }); // If the user takes the new WP version path
485
+ });
603
486
 
487
+ // If the user takes the new WP version path
604
488
  if (confirm.upgrade === 'yes') {
605
- console.log('Upgrading from: ' + _chalk.default.yellow(currentWordPressTag) + ' to:'); // Select a new image
489
+ console.log('Upgrading from: ' + _chalk.default.yellow(currentWordPressTag) + ' to:');
606
490
 
607
- const choice = await (0, _devEnvironmentCli.promptForComponent)('wordpress');
491
+ // Select a new image
492
+ const choice = await (0, _devEnvironmentCli.promptForComponent)('wordpress', false, null);
608
493
  const version = versions.find(({
609
494
  tag
610
- }) => tag.trim() === choice.tag.trim()); // Write new data and stage for rebuild
495
+ }) => tag.trim() === choice.tag.trim());
611
496
 
497
+ // Write new data and stage for rebuild
612
498
  envData.wordpress.tag = version.tag;
613
499
  envData.wordpress.ref = version.ref;
614
500
  await updateEnvironment(envData);
615
501
  return true;
616
502
  }
617
-
618
503
  if (confirm.upgrade === "no (don't ask anymore)") {
619
504
  envData.wordpress.doNotUpgrade = true;
620
505
  console.log("We won't ask about upgrading this environment anymore.");
621
506
  console.log('To manually upgrade please run:' + `${_chalk.default.yellow(`vip dev-env update --slug=${slug}`)}`);
622
507
  await updateEnvironment(envData);
623
508
  }
624
-
625
509
  return false;
626
510
  }
511
+
627
512
  /**
628
513
  * Makes a web call to raw.githubusercontent.com
629
514
  */
630
-
631
-
632
515
  async function fetchVersionList() {
633
516
  const url = `https://${_devEnvironment.DEV_ENVIRONMENT_RAW_GITHUB_HOST}${_devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI}`;
634
517
  return (0, _nodeFetch.default)(url).then(res => res.text());
635
518
  }
519
+
636
520
  /**
637
521
  * Encapsulates the logic for determining if a file is expired by an arbitrary TTL
638
522
  * @param {string} cacheFile uri of cache file
639
523
  * @param {number} ttl time to live in seconds
640
524
  * @returns {boolean} version list expired true/false
641
525
  */
642
-
643
-
644
526
  function isVersionListExpired(cacheFile, ttl) {
645
527
  const stats = _fs.default.statSync(cacheFile);
646
-
647
528
  const expire = new Date(stats.mtime);
648
529
  expire.setSeconds(expire.getSeconds() + ttl);
649
530
  return +new Date() > expire;
650
531
  }
532
+
651
533
  /**
652
534
  * Uses a cache file to keep the version list in tow until it is ultimately outdated
653
535
  */
654
-
655
-
656
536
  async function getVersionList() {
657
537
  let res;
658
-
659
538
  const mainEnvironmentPath = _xdgBasedir.default.data || _os.default.tmpdir();
660
-
661
- const cacheFile = _path.default.join(mainEnvironmentPath, 'vip', _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY); // Handle from cache
662
-
663
-
539
+ const cacheFilePath = _path.default.join(mainEnvironmentPath, 'vip');
540
+ const cacheFile = _path.default.join(cacheFilePath, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY);
541
+ // Handle from cache
664
542
  try {
665
- // If the cache doesn't exist, create it
666
- if (!_fs.default.existsSync(cacheFile)) {
667
- res = await fetchVersionList();
668
-
669
- _fs.default.writeFileSync(cacheFile, res);
670
- } // If the cache is expired, refresh it
671
-
543
+ // If the path for the cache file doesn't exist, create it
544
+ if (!_fs.default.existsSync(cacheFilePath)) {
545
+ await _fs.default.promises.mkdir(cacheFilePath, {
546
+ recursive: true
547
+ });
548
+ }
672
549
 
673
- if (isVersionListExpired(cacheFile, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL)) {
550
+ // If the cache doesn't exist, create it
551
+ // If the cache is expired, refresh it
552
+ if (!_fs.default.existsSync(cacheFile) || isVersionListExpired(cacheFile, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL)) {
674
553
  res = await fetchVersionList();
675
-
676
- _fs.default.writeFileSync(cacheFile, res);
554
+ await _fs.default.promises.writeFile(cacheFile, res);
677
555
  }
678
556
  } catch (err) {
679
557
  // Soft error handling here, since it's still possible to use a previously cached file.
680
558
  console.log(_chalk.default.yellow('fetchWordPressVersionList failed to retrieve an updated version list'));
681
559
  debug(err);
682
- } // Try to parse the cached file if it exists.
683
-
560
+ }
684
561
 
562
+ // Try to parse the cached file if it exists.
685
563
  try {
686
- return JSON.parse(_fs.default.readFileSync(cacheFile));
564
+ const data = await _fs.default.promises.readFile(cacheFile, 'utf8');
565
+ return JSON.parse(data);
687
566
  } catch (err) {
688
567
  debug(err);
689
568
  return [];