@automattic/vip 2.33.0-dev1 → 2.34.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.
- package/CHANGELOG.md +29 -0
- package/dist/bin/vip-backup.js +1 -1
- package/dist/bin/vip-dev-env-start.js +0 -19
- package/dist/bin/vip-dev-env-sync-sql.js +4 -1
- package/dist/commands/backup-db.js +1 -1
- package/dist/commands/dev-env-sync-sql.js +9 -4
- package/dist/commands/export-sql.js +23 -1
- package/dist/lib/backup-storage-availability/backup-storage-availability.js +123 -0
- package/dist/lib/backup-storage-availability/docker-machine-not-found-error.js +12 -0
- package/dist/lib/cli/format.js +19 -5
- package/dist/lib/cli/progress.js +58 -9
- package/dist/lib/dev-environment/dev-environment-core.js +63 -59
- package/dist/lib/dev-environment/dev-environment-lando.js +7 -2
- package/dist/lib/media-import/media-file-import.js +0 -5
- package/dist/lib/media-import/progress.js +11 -5
- package/dist/lib/media-import/status.js +27 -39
- package/dist/lib/site-import/db-file-import.js +4 -10
- package/dist/lib/site-import/status.js +27 -33
- package/dist/lib/utils.js +10 -5
- package/npm-shrinkwrap.json +1379 -1367
- package/package.json +13 -11
|
@@ -24,13 +24,13 @@ exports.startEnvironment = startEnvironment;
|
|
|
24
24
|
exports.stopEnvironment = stopEnvironment;
|
|
25
25
|
exports.updateEnvironment = updateEnvironment;
|
|
26
26
|
exports.writeEnvironmentData = writeEnvironmentData;
|
|
27
|
+
var _nodeOs = _interopRequireDefault(require("node:os"));
|
|
28
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
29
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
27
30
|
var _debug = _interopRequireDefault(require("debug"));
|
|
28
31
|
var _xdgBasedir = _interopRequireDefault(require("xdg-basedir"));
|
|
29
32
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
30
|
-
var _os = _interopRequireDefault(require("os"));
|
|
31
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
32
33
|
var _ejs = _interopRequireDefault(require("ejs"));
|
|
33
|
-
var _path = _interopRequireDefault(require("path"));
|
|
34
34
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
35
35
|
var _enquirer = require("enquirer");
|
|
36
36
|
var _copyDir = _interopRequireDefault(require("copy-dir"));
|
|
@@ -43,6 +43,7 @@ var _app = _interopRequireDefault(require("../api/app"));
|
|
|
43
43
|
var _devEnvironment = require("../constants/dev-environment");
|
|
44
44
|
var _software = require("../config/software");
|
|
45
45
|
var _userError = _interopRequireDefault(require("../user-error"));
|
|
46
|
+
var _proxyAgent = require("../http/proxy-agent");
|
|
46
47
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
48
|
/**
|
|
48
49
|
* External dependencies
|
|
@@ -53,8 +54,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
53
54
|
*/
|
|
54
55
|
|
|
55
56
|
const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
|
|
56
|
-
const landoFileTemplatePath =
|
|
57
|
-
const nginxFileTemplatePath =
|
|
57
|
+
const landoFileTemplatePath = _nodePath.default.join(__dirname, '..', '..', '..', 'assets', 'dev-env.lando.template.yml.ejs');
|
|
58
|
+
const nginxFileTemplatePath = _nodePath.default.join(__dirname, '..', '..', '..', 'assets', 'dev-env.nginx.template.conf.ejs');
|
|
58
59
|
const landoFileName = '.lando.yml';
|
|
59
60
|
const landoBackupFileName = '.lando.backup.yml';
|
|
60
61
|
const nginxFileName = 'extra.conf';
|
|
@@ -63,13 +64,13 @@ const uploadPathString = 'uploads';
|
|
|
63
64
|
const nginxPathString = 'nginx';
|
|
64
65
|
function xdgDataDirectory() {
|
|
65
66
|
var _xdgBasedir$data;
|
|
66
|
-
return (_xdgBasedir$data = _xdgBasedir.default.data) !== null && _xdgBasedir$data !== void 0 && _xdgBasedir$data.length ? _xdgBasedir.default.data :
|
|
67
|
+
return (_xdgBasedir$data = _xdgBasedir.default.data) !== null && _xdgBasedir$data !== void 0 && _xdgBasedir$data.length ? _xdgBasedir.default.data : _nodeOs.default.tmpdir();
|
|
67
68
|
}
|
|
68
69
|
async function startEnvironment(lando, slug, options) {
|
|
69
70
|
debug('Will start an environment', slug);
|
|
70
71
|
const instancePath = getEnvironmentPath(slug);
|
|
71
72
|
debug('Instance path for', slug, 'is:', instancePath);
|
|
72
|
-
const environmentExists =
|
|
73
|
+
const environmentExists = _nodeFs.default.existsSync(instancePath);
|
|
73
74
|
if (!environmentExists) {
|
|
74
75
|
throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
|
|
75
76
|
}
|
|
@@ -91,7 +92,7 @@ async function stopEnvironment(lando, slug) {
|
|
|
91
92
|
debug('Will stop an environment', slug);
|
|
92
93
|
const instancePath = getEnvironmentPath(slug);
|
|
93
94
|
debug('Instance path for', slug, 'is:', instancePath);
|
|
94
|
-
const environmentExists =
|
|
95
|
+
const environmentExists = _nodeFs.default.existsSync(instancePath);
|
|
95
96
|
if (!environmentExists) {
|
|
96
97
|
throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
|
|
97
98
|
}
|
|
@@ -102,7 +103,7 @@ async function createEnvironment(instanceData) {
|
|
|
102
103
|
debug('Will process an environment', slug, 'with instanceData for creation: ', instanceData);
|
|
103
104
|
const instancePath = getEnvironmentPath(slug);
|
|
104
105
|
debug('Instance path for', slug, 'is:', instancePath);
|
|
105
|
-
const alreadyExists =
|
|
106
|
+
const alreadyExists = _nodeFs.default.existsSync(instancePath);
|
|
106
107
|
if (alreadyExists) {
|
|
107
108
|
throw new Error('Environment already exists.');
|
|
108
109
|
}
|
|
@@ -115,7 +116,7 @@ async function updateEnvironment(instanceData) {
|
|
|
115
116
|
debug('Will process an environment', slug, 'with instanceData for updating: ', instanceData);
|
|
116
117
|
const instancePath = getEnvironmentPath(slug);
|
|
117
118
|
debug('Instance path for', slug, 'is:', instancePath);
|
|
118
|
-
const alreadyExists =
|
|
119
|
+
const alreadyExists = _nodeFs.default.existsSync(instancePath);
|
|
119
120
|
if (!alreadyExists) {
|
|
120
121
|
throw new Error("Environment doesn't exist.");
|
|
121
122
|
}
|
|
@@ -180,15 +181,15 @@ async function destroyEnvironment(lando, slug, removeFiles) {
|
|
|
180
181
|
if (!environmentExists) {
|
|
181
182
|
throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
|
|
182
183
|
}
|
|
183
|
-
const landoFilePath =
|
|
184
|
-
if (
|
|
184
|
+
const landoFilePath = _nodePath.default.join(instancePath, landoFileName);
|
|
185
|
+
if (_nodeFs.default.existsSync(landoFilePath)) {
|
|
185
186
|
debug('Lando file exists, will lando destroy.');
|
|
186
187
|
await (0, _devEnvironmentLando.landoDestroy)(lando, instancePath);
|
|
187
188
|
} else {
|
|
188
189
|
debug("Lando file doesn't exist, skipping lando destroy.");
|
|
189
190
|
}
|
|
190
191
|
if (removeFiles) {
|
|
191
|
-
await
|
|
192
|
+
await _nodeFs.default.promises.rm(instancePath, {
|
|
192
193
|
recursive: true
|
|
193
194
|
});
|
|
194
195
|
console.log(`${_chalk.default.green('✓')} Environment files deleted successfully.`);
|
|
@@ -265,9 +266,9 @@ function exec(lando, slug, args, options = {}) {
|
|
|
265
266
|
}
|
|
266
267
|
async function doesEnvironmentExist(instancePath) {
|
|
267
268
|
debug('Will check for environment at', instancePath);
|
|
268
|
-
const file =
|
|
269
|
+
const file = _nodePath.default.join(instancePath, instanceDataFileName);
|
|
269
270
|
try {
|
|
270
|
-
const stats = await
|
|
271
|
+
const stats = await _nodeFs.default.promises.stat(file);
|
|
271
272
|
return stats.isFile();
|
|
272
273
|
} catch (err) {
|
|
273
274
|
return false;
|
|
@@ -276,11 +277,11 @@ async function doesEnvironmentExist(instancePath) {
|
|
|
276
277
|
function readEnvironmentData(slug) {
|
|
277
278
|
debug('Will try to get instance data for environment', slug);
|
|
278
279
|
const instancePath = getEnvironmentPath(slug);
|
|
279
|
-
const instanceDataTargetPath =
|
|
280
|
+
const instanceDataTargetPath = _nodePath.default.join(instancePath, instanceDataFileName);
|
|
280
281
|
let instanceDataString;
|
|
281
282
|
let instanceData;
|
|
282
283
|
try {
|
|
283
|
-
instanceDataString =
|
|
284
|
+
instanceDataString = _nodeFs.default.readFileSync(instanceDataTargetPath, 'utf8');
|
|
284
285
|
} catch (error) {
|
|
285
286
|
const err = error;
|
|
286
287
|
throw new _userError.default(`There was an error reading file "${instanceDataTargetPath}": ${err.message}.`);
|
|
@@ -326,44 +327,44 @@ function readEnvironmentData(slug) {
|
|
|
326
327
|
function writeEnvironmentData(slug, data) {
|
|
327
328
|
debug('Will try to write instance data for environment', slug);
|
|
328
329
|
const instancePath = getEnvironmentPath(slug);
|
|
329
|
-
const instanceDataTargetPath =
|
|
330
|
-
return
|
|
330
|
+
const instanceDataTargetPath = _nodePath.default.join(instancePath, instanceDataFileName);
|
|
331
|
+
return _nodeFs.default.promises.writeFile(instanceDataTargetPath, JSON.stringify(data, null, 2));
|
|
331
332
|
}
|
|
332
333
|
async function prepareLandoEnv(instanceData, instancePath) {
|
|
333
334
|
const landoFile = await _ejs.default.renderFile(landoFileTemplatePath, instanceData);
|
|
334
335
|
const nginxFile = await _ejs.default.renderFile(nginxFileTemplatePath, instanceData);
|
|
335
336
|
const instanceDataFile = JSON.stringify(instanceData);
|
|
336
|
-
const landoFileTargetPath =
|
|
337
|
-
const landoBackupFileTargetPath =
|
|
338
|
-
const nginxFolderPath =
|
|
339
|
-
const nginxFileTargetPath =
|
|
340
|
-
const instanceDataTargetPath =
|
|
341
|
-
await
|
|
337
|
+
const landoFileTargetPath = _nodePath.default.join(instancePath, landoFileName);
|
|
338
|
+
const landoBackupFileTargetPath = _nodePath.default.join(instancePath, landoBackupFileName);
|
|
339
|
+
const nginxFolderPath = _nodePath.default.join(instancePath, nginxPathString);
|
|
340
|
+
const nginxFileTargetPath = _nodePath.default.join(nginxFolderPath, nginxFileName);
|
|
341
|
+
const instanceDataTargetPath = _nodePath.default.join(instancePath, instanceDataFileName);
|
|
342
|
+
await _nodeFs.default.promises.mkdir(instancePath, {
|
|
342
343
|
recursive: true
|
|
343
344
|
});
|
|
344
|
-
await
|
|
345
|
+
await _nodeFs.default.promises.mkdir(nginxFolderPath, {
|
|
345
346
|
recursive: true
|
|
346
347
|
});
|
|
347
|
-
const landoFileExists = await
|
|
348
|
+
const landoFileExists = await _nodeFs.default.promises.stat(landoFileTargetPath).catch(() => false);
|
|
348
349
|
if (landoFileExists) {
|
|
349
|
-
await
|
|
350
|
+
await _nodeFs.default.promises.copyFile(landoFileTargetPath, landoBackupFileTargetPath);
|
|
350
351
|
console.log(`Backup of ${landoFileName} was created in ${landoBackupFileTargetPath}`);
|
|
351
352
|
}
|
|
352
|
-
await Promise.all([
|
|
353
|
+
await Promise.all([_nodeFs.default.promises.writeFile(landoFileTargetPath, landoFile), _nodeFs.default.promises.writeFile(nginxFileTargetPath, nginxFile), _nodeFs.default.promises.writeFile(instanceDataTargetPath, instanceDataFile)]);
|
|
353
354
|
debug(`Lando file created in ${landoFileTargetPath}`);
|
|
354
355
|
debug(`Nginx file created in ${nginxFileTargetPath}`);
|
|
355
356
|
debug(`Instance data file created in ${instanceDataTargetPath}`);
|
|
356
357
|
}
|
|
357
358
|
function getAllEnvironmentNames() {
|
|
358
359
|
const mainEnvironmentPath = xdgDataDirectory();
|
|
359
|
-
const baseDir =
|
|
360
|
-
const doWeHaveAnyEnvironment =
|
|
360
|
+
const baseDir = _nodePath.default.join(mainEnvironmentPath, 'vip', 'dev-environment');
|
|
361
|
+
const doWeHaveAnyEnvironment = _nodeFs.default.existsSync(baseDir);
|
|
361
362
|
let envNames = [];
|
|
362
363
|
if (doWeHaveAnyEnvironment) {
|
|
363
|
-
const files =
|
|
364
|
+
const files = _nodeFs.default.readdirSync(baseDir);
|
|
364
365
|
envNames = files.filter(file => {
|
|
365
|
-
const fullPath =
|
|
366
|
-
return
|
|
366
|
+
const fullPath = _nodePath.default.join(baseDir, file);
|
|
367
|
+
return _nodeFs.default.lstatSync(fullPath).isDirectory();
|
|
367
368
|
});
|
|
368
369
|
}
|
|
369
370
|
return envNames;
|
|
@@ -373,7 +374,7 @@ function getEnvironmentPath(name) {
|
|
|
373
374
|
throw new Error('Name was not provided');
|
|
374
375
|
}
|
|
375
376
|
const mainEnvironmentPath = xdgDataDirectory();
|
|
376
|
-
return
|
|
377
|
+
return _nodePath.default.join(mainEnvironmentPath, 'vip', 'dev-environment', name + '');
|
|
377
378
|
}
|
|
378
379
|
async function getApplicationInformation(appId, envType) {
|
|
379
380
|
// $FlowFixMe: gql template is not supported by flow
|
|
@@ -448,10 +449,10 @@ async function resolveImportPath(slug, fileName, searchReplace, inPlace) {
|
|
|
448
449
|
debug(`Will try to resolve path - ${fileName}`);
|
|
449
450
|
let resolvedPath = (0, _devEnvironmentCli.resolvePath)(fileName);
|
|
450
451
|
debug(`Filename ${fileName} resolved to ${resolvedPath}`);
|
|
451
|
-
if (!
|
|
452
|
+
if (!_nodeFs.default.existsSync(resolvedPath)) {
|
|
452
453
|
throw new _userError.default(`The provided file ${resolvedPath} does not exist or it is not valid (see "--help" for examples)`);
|
|
453
454
|
}
|
|
454
|
-
if (
|
|
455
|
+
if (_nodeFs.default.lstatSync(resolvedPath).isDirectory()) {
|
|
455
456
|
throw new _userError.default(`The provided file ${resolvedPath} is a directory. Please point to a sql file.`);
|
|
456
457
|
}
|
|
457
458
|
|
|
@@ -473,14 +474,14 @@ async function resolveImportPath(slug, fileName, searchReplace, inPlace) {
|
|
|
473
474
|
}
|
|
474
475
|
async function importMediaPath(slug, filePath) {
|
|
475
476
|
const resolvedPath = (0, _devEnvironmentCli.resolvePath)(filePath);
|
|
476
|
-
if (!
|
|
477
|
+
if (!_nodeFs.default.existsSync(resolvedPath) || !_nodeFs.default.lstatSync(resolvedPath).isDirectory()) {
|
|
477
478
|
throw new Error('The provided path does not exist or it is not valid (see "--help" for examples)');
|
|
478
479
|
}
|
|
479
480
|
const environmentPath = getEnvironmentPath(slug);
|
|
480
481
|
if (!(await doesEnvironmentExist(environmentPath))) {
|
|
481
482
|
throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
|
|
482
483
|
}
|
|
483
|
-
const files =
|
|
484
|
+
const files = _nodeFs.default.readdirSync(resolvedPath);
|
|
484
485
|
if (files.includes(uploadPathString)) {
|
|
485
486
|
const confirm = await (0, _enquirer.prompt)({
|
|
486
487
|
type: 'confirm',
|
|
@@ -491,7 +492,7 @@ async function importMediaPath(slug, filePath) {
|
|
|
491
492
|
return;
|
|
492
493
|
}
|
|
493
494
|
}
|
|
494
|
-
const uploadsPath =
|
|
495
|
+
const uploadsPath = _nodePath.default.join(environmentPath, uploadPathString);
|
|
495
496
|
console.log(`${_chalk.default.yellow('-')} Started copying files`);
|
|
496
497
|
_copyDir.default.sync(resolvedPath, uploadsPath);
|
|
497
498
|
console.log(`${_chalk.default.green('✓')} Files successfully copied to ${uploadsPath}.`);
|
|
@@ -617,7 +618,10 @@ async function maybeUpdateVersion(slug) {
|
|
|
617
618
|
*/
|
|
618
619
|
function fetchVersionList() {
|
|
619
620
|
const url = `https://${_devEnvironment.DEV_ENVIRONMENT_RAW_GITHUB_HOST}${_devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI}`;
|
|
620
|
-
|
|
621
|
+
const proxyAgent = (0, _proxyAgent.createProxyAgent)(url);
|
|
622
|
+
return (0, _nodeFetch.default)(url, {
|
|
623
|
+
agent: proxyAgent ?? undefined
|
|
624
|
+
}).then(res => res.json());
|
|
621
625
|
}
|
|
622
626
|
|
|
623
627
|
/**
|
|
@@ -631,7 +635,7 @@ async function isVersionListExpired(cacheFile, ttl) {
|
|
|
631
635
|
try {
|
|
632
636
|
const {
|
|
633
637
|
mtime: expire
|
|
634
|
-
} = await
|
|
638
|
+
} = await _nodeFs.default.promises.stat(cacheFile);
|
|
635
639
|
expire.setSeconds(expire.getSeconds() + ttl);
|
|
636
640
|
return +new Date() > +expire;
|
|
637
641
|
} catch (err) {
|
|
@@ -645,13 +649,13 @@ async function isVersionListExpired(cacheFile, ttl) {
|
|
|
645
649
|
async function getVersionList() {
|
|
646
650
|
let res;
|
|
647
651
|
const mainEnvironmentPath = xdgDataDirectory();
|
|
648
|
-
const cacheFilePath =
|
|
649
|
-
const cacheFile =
|
|
652
|
+
const cacheFilePath = _nodePath.default.join(mainEnvironmentPath, 'vip');
|
|
653
|
+
const cacheFile = _nodePath.default.join(cacheFilePath, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY);
|
|
650
654
|
// Handle from cache
|
|
651
655
|
try {
|
|
652
656
|
// If the path for the cache file doesn't exist, create it
|
|
653
|
-
if (!
|
|
654
|
-
await
|
|
657
|
+
if (!_nodeFs.default.existsSync(cacheFilePath)) {
|
|
658
|
+
await _nodeFs.default.promises.mkdir(cacheFilePath, {
|
|
655
659
|
recursive: true
|
|
656
660
|
});
|
|
657
661
|
}
|
|
@@ -659,7 +663,7 @@ async function getVersionList() {
|
|
|
659
663
|
// If the cache does not exist or has expired, refresh it
|
|
660
664
|
if (await isVersionListExpired(cacheFile, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL)) {
|
|
661
665
|
res = await fetchVersionList();
|
|
662
|
-
await
|
|
666
|
+
await _nodeFs.default.promises.writeFile(cacheFile, JSON.stringify(res));
|
|
663
667
|
}
|
|
664
668
|
} catch (err) {
|
|
665
669
|
// Soft error handling here, since it's still possible to use a previously cached file.
|
|
@@ -669,7 +673,7 @@ async function getVersionList() {
|
|
|
669
673
|
|
|
670
674
|
// Try to parse the cached file if it exists.
|
|
671
675
|
try {
|
|
672
|
-
const data = await
|
|
676
|
+
const data = await _nodeFs.default.promises.readFile(cacheFile, 'utf8');
|
|
673
677
|
return JSON.parse(data);
|
|
674
678
|
} catch (err) {
|
|
675
679
|
debug(err);
|
|
@@ -721,7 +725,7 @@ function generateVSCodeWorkspace(slug) {
|
|
|
721
725
|
}]
|
|
722
726
|
}
|
|
723
727
|
};
|
|
724
|
-
|
|
728
|
+
_nodeFs.default.writeFileSync(workspacePath, JSON.stringify(workspace, null, 2));
|
|
725
729
|
return workspacePath;
|
|
726
730
|
}
|
|
727
731
|
const generatePathMappings = (location, instanceData) => {
|
|
@@ -730,19 +734,19 @@ const generatePathMappings = (location, instanceData) => {
|
|
|
730
734
|
pathMappings['/wp/wp-content/mu-plugins'] = instanceData.muPlugins.dir;
|
|
731
735
|
}
|
|
732
736
|
if (instanceData.appCode.dir) {
|
|
733
|
-
pathMappings['/wp/wp-content/client-mu-plugins'] =
|
|
734
|
-
pathMappings['/wp/wp-content/images'] =
|
|
735
|
-
pathMappings['/wp/wp-content/languages'] =
|
|
736
|
-
pathMappings['/wp/wp-content/plugins'] =
|
|
737
|
-
pathMappings['/wp/wp-content/private'] =
|
|
738
|
-
pathMappings['/wp/wp-content/themes'] =
|
|
739
|
-
pathMappings['/wp/wp-content/vip-config'] =
|
|
740
|
-
}
|
|
741
|
-
pathMappings['/wp'] =
|
|
737
|
+
pathMappings['/wp/wp-content/client-mu-plugins'] = _nodePath.default.resolve(instanceData.appCode.dir, 'client-mu-plugins');
|
|
738
|
+
pathMappings['/wp/wp-content/images'] = _nodePath.default.resolve(instanceData.appCode.dir, 'images');
|
|
739
|
+
pathMappings['/wp/wp-content/languages'] = _nodePath.default.resolve(instanceData.appCode.dir, 'languages');
|
|
740
|
+
pathMappings['/wp/wp-content/plugins'] = _nodePath.default.resolve(instanceData.appCode.dir, 'plugins');
|
|
741
|
+
pathMappings['/wp/wp-content/private'] = _nodePath.default.resolve(instanceData.appCode.dir, 'private');
|
|
742
|
+
pathMappings['/wp/wp-content/themes'] = _nodePath.default.resolve(instanceData.appCode.dir, 'themes');
|
|
743
|
+
pathMappings['/wp/wp-content/vip-config'] = _nodePath.default.resolve(instanceData.appCode.dir, 'vip-config');
|
|
744
|
+
}
|
|
745
|
+
pathMappings['/wp'] = _nodePath.default.resolve(location, 'wordpress');
|
|
742
746
|
return pathMappings;
|
|
743
747
|
};
|
|
744
748
|
function getVSCodeWorkspacePath(slug) {
|
|
745
749
|
const location = getEnvironmentPath(slug);
|
|
746
|
-
const workspacePath =
|
|
750
|
+
const workspacePath = _nodePath.default.join(location, `${slug}.code-workspace`);
|
|
747
751
|
return workspacePath;
|
|
748
752
|
}
|
|
@@ -366,9 +366,14 @@ async function getExtraServicesConnections(lando, app) {
|
|
|
366
366
|
const allServices = await lando.engine.list({
|
|
367
367
|
project: app.project
|
|
368
368
|
});
|
|
369
|
+
const defaultDisplayConfiguration = {
|
|
370
|
+
skip: false,
|
|
371
|
+
label: null,
|
|
372
|
+
protocol: null
|
|
373
|
+
};
|
|
369
374
|
for (const service of allServices) {
|
|
370
|
-
const displayConfiguration = extraServiceDisplayConfiguration.find(conf => conf.name === service.service);
|
|
371
|
-
if (
|
|
375
|
+
const displayConfiguration = extraServiceDisplayConfiguration.find(conf => conf.name === service.service) ?? defaultDisplayConfiguration;
|
|
376
|
+
if (displayConfiguration.skip) {
|
|
372
377
|
continue;
|
|
373
378
|
}
|
|
374
379
|
|
|
@@ -7,11 +7,6 @@ exports.SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = exports.MEDIA_IMPORT_FILE_SIZE_
|
|
|
7
7
|
exports.currentUserCanImportForApp = currentUserCanImportForApp;
|
|
8
8
|
exports.isSupportedApp = void 0;
|
|
9
9
|
var _fileSize = require("../../lib/constants/file-size");
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @format
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
10
|
/**
|
|
16
11
|
* Internal dependencies
|
|
17
12
|
*/
|
|
@@ -7,13 +7,14 @@ exports.MediaImportProgressTracker = void 0;
|
|
|
7
7
|
var _singleLineLog = require("single-line-log");
|
|
8
8
|
var _status = require("../../lib/media-import/status");
|
|
9
9
|
var _format = require("../../lib/cli/format");
|
|
10
|
-
/** @format */
|
|
11
10
|
/**
|
|
12
11
|
* External dependencies
|
|
13
12
|
*/
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
const PRINT_INTERVAL = process.env.DEBUG ? 5000 : 200; // How often the report is printed. Mainly affects the "spinner" animation.
|
|
18
19
|
|
|
19
20
|
class MediaImportProgressTracker {
|
|
@@ -26,15 +27,20 @@ class MediaImportProgressTracker {
|
|
|
26
27
|
constructor(status) {
|
|
27
28
|
this.runningSprite = new _format.RunningSprite();
|
|
28
29
|
this.hasFailure = false;
|
|
29
|
-
this.status =
|
|
30
|
+
this.status = {
|
|
31
|
+
...status
|
|
32
|
+
};
|
|
30
33
|
this.prefix = '';
|
|
31
34
|
this.suffix = '';
|
|
35
|
+
this.hasPrinted = false;
|
|
32
36
|
}
|
|
33
37
|
setStatus(status) {
|
|
34
38
|
if ('FAILED' === status.status) {
|
|
35
39
|
this.hasFailure = true;
|
|
36
40
|
}
|
|
37
|
-
this.status =
|
|
41
|
+
this.status = {
|
|
42
|
+
...status
|
|
43
|
+
};
|
|
38
44
|
}
|
|
39
45
|
startPrinting(prePrintCallback = () => {}) {
|
|
40
46
|
this.printInterval = setInterval(() => {
|
|
@@ -54,7 +60,7 @@ class MediaImportProgressTracker {
|
|
|
54
60
|
this.hasPrinted = true;
|
|
55
61
|
_singleLineLog.stdout.clear();
|
|
56
62
|
}
|
|
57
|
-
const statusIcon = (0, _status.getGlyphForStatus)(this.status.status, this.runningSprite);
|
|
63
|
+
const statusIcon = (0, _status.getGlyphForStatus)(this.status.status ?? '', this.runningSprite);
|
|
58
64
|
let logs;
|
|
59
65
|
if (this.status.filesProcessed && this.status.filesTotal) {
|
|
60
66
|
const progressPercentage = Math.floor(this.status.filesProcessed / this.status.filesTotal * 100);
|
|
@@ -62,7 +68,7 @@ class MediaImportProgressTracker {
|
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
// Output the logs
|
|
65
|
-
(0, _singleLineLog.stdout)(`${this.prefix || ''}${logs
|
|
71
|
+
(0, _singleLineLog.stdout)(`${this.prefix || ''}${logs ?? ''}${this.suffix || ''}`);
|
|
66
72
|
if (clearAfter) {
|
|
67
73
|
// Break out of the "Single log line" buffer
|
|
68
74
|
_singleLineLog.stdout.clear();
|
|
@@ -6,23 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.getGlyphForStatus = getGlyphForStatus;
|
|
8
8
|
exports.mediaImportCheckStatus = mediaImportCheckStatus;
|
|
9
|
+
var _promises = require("node:fs/promises");
|
|
10
|
+
var _nodePath = require("node:path");
|
|
9
11
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
12
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
11
|
-
var _fs = require("fs");
|
|
12
|
-
var path = _interopRequireWildcard(require("path"));
|
|
13
13
|
var _api = _interopRequireDefault(require("../../lib/api"));
|
|
14
14
|
var _mediaFileImport = require("../../lib/media-import/media-file-import");
|
|
15
|
-
var _progress = require("../../lib/media-import/progress");
|
|
16
15
|
var _format = require("../../lib/cli/format");
|
|
17
|
-
var _format2 = require("../cli/format");
|
|
18
|
-
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); }
|
|
19
|
-
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; }
|
|
20
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @format
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
17
|
/**
|
|
27
18
|
* External dependencies
|
|
28
19
|
*/
|
|
@@ -62,6 +53,7 @@ const IMPORT_MEDIA_PROGRESS_QUERY = (0, _graphqlTag.default)`
|
|
|
62
53
|
}
|
|
63
54
|
`;
|
|
64
55
|
async function getStatus(api, appId, envId) {
|
|
56
|
+
var _response$data$app;
|
|
65
57
|
const response = await api.query({
|
|
66
58
|
query: IMPORT_MEDIA_PROGRESS_QUERY,
|
|
67
59
|
variables: {
|
|
@@ -70,21 +62,15 @@ async function getStatus(api, appId, envId) {
|
|
|
70
62
|
},
|
|
71
63
|
fetchPolicy: 'network-only'
|
|
72
64
|
});
|
|
73
|
-
const
|
|
74
|
-
data: {
|
|
75
|
-
app: {
|
|
76
|
-
environments
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} = response;
|
|
65
|
+
const environments = (_response$data$app = response.data.app) === null || _response$data$app === void 0 ? void 0 : _response$data$app.environments;
|
|
80
66
|
if (!(environments !== null && environments !== void 0 && environments.length)) {
|
|
81
67
|
throw new Error('Unable to determine import status from environment');
|
|
82
68
|
}
|
|
83
69
|
const [environment] = environments;
|
|
84
70
|
const {
|
|
85
71
|
mediaImportStatus
|
|
86
|
-
} = environment;
|
|
87
|
-
return mediaImportStatus;
|
|
72
|
+
} = environment ?? {};
|
|
73
|
+
return mediaImportStatus ?? null;
|
|
88
74
|
}
|
|
89
75
|
function getGlyphForStatus(status, runningSprite) {
|
|
90
76
|
switch (status) {
|
|
@@ -113,10 +99,11 @@ function buildErrorMessage(importFailed) {
|
|
|
113
99
|
if ('FAILED' === importFailed.status) {
|
|
114
100
|
const globalFailureDetails = importFailed.failureDetails;
|
|
115
101
|
if (globalFailureDetails) {
|
|
102
|
+
var _globalFailureDetails;
|
|
116
103
|
message += `${_chalk.default.red('Import failed at status: ')}`;
|
|
117
104
|
message += `${_chalk.default.redBright.bold(globalFailureDetails.previousStatus)}\n`;
|
|
118
105
|
message += _chalk.default.red('Errors:');
|
|
119
|
-
globalFailureDetails.globalErrors.forEach(value => {
|
|
106
|
+
(_globalFailureDetails = globalFailureDetails.globalErrors) === null || _globalFailureDetails === void 0 || _globalFailureDetails.forEach(value => {
|
|
120
107
|
message += `\n\t- ${_chalk.default.redBright.bold(value)}`;
|
|
121
108
|
});
|
|
122
109
|
return message;
|
|
@@ -131,16 +118,17 @@ function buildFileErrors(fileErrors, exportFileErrorsToJson) {
|
|
|
131
118
|
if (exportFileErrorsToJson) {
|
|
132
119
|
const fileErrorsToExport = fileErrors.map(fileError => {
|
|
133
120
|
return {
|
|
134
|
-
fileName: fileError.fileName,
|
|
135
|
-
errors: fileError.errors
|
|
121
|
+
fileName: fileError === null || fileError === void 0 ? void 0 : fileError.fileName,
|
|
122
|
+
errors: fileError === null || fileError === void 0 ? void 0 : fileError.errors
|
|
136
123
|
};
|
|
137
124
|
});
|
|
138
125
|
return (0, _format.formatData)(fileErrorsToExport, 'json');
|
|
139
126
|
}
|
|
140
127
|
let errorString = '';
|
|
141
128
|
for (const fileError of fileErrors) {
|
|
142
|
-
|
|
143
|
-
errorString +=
|
|
129
|
+
var _fileError$errors;
|
|
130
|
+
errorString += `File Name: ${(fileError === null || fileError === void 0 ? void 0 : fileError.fileName) ?? 'N/A'}`;
|
|
131
|
+
errorString += `\n\nErrors:\n\t- ${(fileError === null || fileError === void 0 || (_fileError$errors = fileError.errors) === null || _fileError$errors === void 0 ? void 0 : _fileError$errors.join(', ')) ?? 'unknown error'}\n\n\n\n`;
|
|
144
132
|
}
|
|
145
133
|
return errorString;
|
|
146
134
|
}
|
|
@@ -177,7 +165,7 @@ async function mediaImportCheckStatus({
|
|
|
177
165
|
const suffix = `
|
|
178
166
|
=============================================================
|
|
179
167
|
Status: ${statusMessage}
|
|
180
|
-
App: ${app.name} (${(0, _format.formatEnvironment)(env.type)})
|
|
168
|
+
App: ${app.name ?? 'N/A'} (${(0, _format.formatEnvironment)(env.type ?? 'N/A')})
|
|
181
169
|
=============================================================
|
|
182
170
|
${maybeExitPrompt}
|
|
183
171
|
`;
|
|
@@ -188,13 +176,15 @@ ${maybeExitPrompt}
|
|
|
188
176
|
progressTracker.print();
|
|
189
177
|
};
|
|
190
178
|
progressTracker.startPrinting(setSuffixAndPrint);
|
|
191
|
-
const getResults = () =>
|
|
179
|
+
const getResults = () =>
|
|
180
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
181
|
+
new Promise((resolve, reject) => {
|
|
192
182
|
let startDate = Date.now();
|
|
193
183
|
let pollIntervalDecreasing = false;
|
|
194
184
|
const checkStatus = async pollInterval => {
|
|
195
|
-
let mediaImportStatus;
|
|
185
|
+
let mediaImportStatus = null;
|
|
196
186
|
try {
|
|
197
|
-
mediaImportStatus = await getStatus(api, app.id, env.id);
|
|
187
|
+
mediaImportStatus = await getStatus(api, app.id ?? -1, env.id ?? -1);
|
|
198
188
|
if (!mediaImportStatus) {
|
|
199
189
|
return reject({
|
|
200
190
|
error: 'Requested app/environment is not available for this operation. If you think this is not correct, please contact Support.'
|
|
@@ -202,12 +192,10 @@ ${maybeExitPrompt}
|
|
|
202
192
|
}
|
|
203
193
|
} catch (error) {
|
|
204
194
|
return reject({
|
|
205
|
-
error
|
|
195
|
+
error: error.message
|
|
206
196
|
});
|
|
207
197
|
}
|
|
208
|
-
const
|
|
209
|
-
status
|
|
210
|
-
} = mediaImportStatus;
|
|
198
|
+
const status = mediaImportStatus.status ?? 'unknown';
|
|
211
199
|
const failedMediaImport = 'FAILED' === status;
|
|
212
200
|
if (failedMediaImport) {
|
|
213
201
|
progressTracker.setStatus(mediaImportStatus);
|
|
@@ -244,23 +232,23 @@ ${maybeExitPrompt}
|
|
|
244
232
|
try {
|
|
245
233
|
var _results$failureDetai;
|
|
246
234
|
const results = await getResults();
|
|
247
|
-
overallStatus =
|
|
235
|
+
overallStatus = results.status ?? 'unknown';
|
|
248
236
|
progressTracker.stopPrinting();
|
|
249
237
|
setProgressTrackerSuffix();
|
|
250
238
|
progressTracker.print();
|
|
251
239
|
const fileErrors = (_results$failureDetai = results.failureDetails) === null || _results$failureDetai === void 0 ? void 0 : _results$failureDetai.fileErrors;
|
|
252
240
|
if (!!fileErrors && fileErrors.length > 0) {
|
|
253
241
|
progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${fileErrors.length} file error(s) have been extracted`)}`;
|
|
254
|
-
if (results.filesTotal - results.filesProcessed !== fileErrors.length) {
|
|
242
|
+
if ((results.filesTotal ?? 0) - (results.filesProcessed ?? 0) !== fileErrors.length) {
|
|
255
243
|
progressTracker.suffix += `. ${_chalk.default.italic.yellow('File-errors report size threshold reached.')}`;
|
|
256
244
|
}
|
|
257
245
|
const formattedData = buildFileErrors(fileErrors, exportFileErrorsToJson);
|
|
258
|
-
const errorsFile = `media-import-${app.name}-${Date.now()}${exportFileErrorsToJson ? '.json' : '.txt'}`;
|
|
246
|
+
const errorsFile = `media-import-${app.name ?? ''}-${Date.now()}${exportFileErrorsToJson ? '.json' : '.txt'}`;
|
|
259
247
|
try {
|
|
260
|
-
await
|
|
261
|
-
progressTracker.suffix += `\n\n${_chalk.default.yellow(`All errors have been exported to ${_chalk.default.bold(
|
|
248
|
+
await (0, _promises.writeFile)(errorsFile, formattedData);
|
|
249
|
+
progressTracker.suffix += `\n\n${_chalk.default.yellow(`All errors have been exported to ${_chalk.default.bold((0, _nodePath.resolve)(errorsFile))}`)}\n\n`;
|
|
262
250
|
} catch (writeFileErr) {
|
|
263
|
-
progressTracker.suffix += `\n\n${_chalk.default.red(`Could not export errors to file\n${writeFileErr}`)}\n\n`;
|
|
251
|
+
progressTracker.suffix += `\n\n${_chalk.default.red(`Could not export errors to file\n${writeFileErr.message}`)}\n\n`;
|
|
264
252
|
}
|
|
265
253
|
}
|
|
266
254
|
|
|
@@ -7,11 +7,6 @@ exports.SYNC_STATUS_NOT_SYNCING = exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES =
|
|
|
7
7
|
exports.currentUserCanImportForApp = currentUserCanImportForApp;
|
|
8
8
|
exports.isSupportedApp = exports.isImportingBlockedBySync = void 0;
|
|
9
9
|
var _fileSize = require("../../lib/constants/file-size");
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @format
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
10
|
/**
|
|
16
11
|
* Internal dependencies
|
|
17
12
|
*/
|
|
@@ -32,9 +27,8 @@ const isSupportedApp = ({
|
|
|
32
27
|
exports.isSupportedApp = isSupportedApp;
|
|
33
28
|
const SYNC_STATUS_NOT_SYNCING = 'not_syncing';
|
|
34
29
|
exports.SYNC_STATUS_NOT_SYNCING = SYNC_STATUS_NOT_SYNCING;
|
|
35
|
-
const isImportingBlockedBySync =
|
|
36
|
-
syncProgress
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}) => status !== SYNC_STATUS_NOT_SYNCING;
|
|
30
|
+
const isImportingBlockedBySync = env => {
|
|
31
|
+
var _env$syncProgress;
|
|
32
|
+
return ((_env$syncProgress = env.syncProgress) === null || _env$syncProgress === void 0 ? void 0 : _env$syncProgress.status) !== SYNC_STATUS_NOT_SYNCING;
|
|
33
|
+
};
|
|
40
34
|
exports.isImportingBlockedBySync = isImportingBlockedBySync;
|