@automattic/vip 3.20.3 → 3.21.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/dist/bin/vip-dev-env-sync-sql.js +7 -7
- package/dist/bin/vip-export-sql.js +7 -7
- package/dist/bin/vip.js +1 -9
- package/dist/commands/export-sql.js +5 -5
- package/dist/lib/live-backup-copy.js +11 -11
- package/dist/lib/node-version-check.js +20 -0
- package/npm-shrinkwrap.json +284 -284
- package/package.json +1 -1
|
@@ -20,11 +20,11 @@ const examples = [{
|
|
|
20
20
|
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --table=wp_posts,wp_comments`,
|
|
21
21
|
description: 'Sync only the wp_posts and wp_comments tables using comma-separated syntax from the database of the develop environment in the "example-app" application to a local environment named "example-site".'
|
|
22
22
|
}, {
|
|
23
|
-
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --
|
|
24
|
-
description: 'Sync only the tables for the
|
|
23
|
+
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --site-id=2 --site-id=3`,
|
|
24
|
+
description: 'Sync only the tables for the network sites with IDs 2 and 3 from the database of the develop environment in the "example-app" application to a local environment named "example-site".'
|
|
25
25
|
}, {
|
|
26
|
-
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --
|
|
27
|
-
description: 'Sync only the tables for the
|
|
26
|
+
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --site-id=2,3`,
|
|
27
|
+
description: 'Sync only the tables for the network sites with IDs 2 and 3 using comma-separated syntax from the database of the develop environment in the "example-app" application to a local environment named "example-site".'
|
|
28
28
|
}, {
|
|
29
29
|
usage: `vip @example-app.develop dev-env sync sql --slug=example-site --config-file=~/dev-env-sync-config.json`,
|
|
30
30
|
description: 'Use the specified config file to determine what to sync from the database of the develop environment in the "example-app" application to a local environment named "example-site".'
|
|
@@ -58,17 +58,17 @@ const appQuery = `
|
|
|
58
58
|
requiredArgs: 0,
|
|
59
59
|
module: 'dev-env-sync-sql',
|
|
60
60
|
usage
|
|
61
|
-
}).option('slug', 'A unique name for a local environment. Default is "vip-local".', undefined, _devEnvironmentCli.processSlug).option('table', 'A table to sync from the remote environment to the local environment. Multiple tables can be specified with multiple --table flags or as a comma-separated list.').option('
|
|
61
|
+
}).option('slug', 'A unique name for a local environment. Default is "vip-local".', undefined, _devEnvironmentCli.processSlug).option('table', 'A table to sync from the remote environment to the local environment. Multiple tables can be specified with multiple --table flags or as a comma-separated list.').option('site-id', 'The ID of a network site to sync from the remote environment to the local environment. Multiple site IDs can be specified with multiple --site-id flags or as a comma-separated list.').option('wpcli-command', 'The WP-CLI command to run on the remote environment to retrieve the database export configuration.').option('config-file', 'The backup copy config file to use for the sync.', undefined).option('force', 'Skip validations.', undefined, _devEnvironmentCli.processBooleanOption).examples(examples).argv(process.argv, async (arg, opt) => {
|
|
62
62
|
const {
|
|
63
63
|
app,
|
|
64
64
|
env,
|
|
65
65
|
configFile,
|
|
66
66
|
table,
|
|
67
|
-
|
|
67
|
+
siteId,
|
|
68
68
|
wpcliCommand,
|
|
69
69
|
...optRest
|
|
70
70
|
} = opt;
|
|
71
|
-
const liveBackupCopyCLIOptions = (0, _liveBackupCopy.parseLiveBackupCopyCLIOptions)(configFile, table,
|
|
71
|
+
const liveBackupCopyCLIOptions = (0, _liveBackupCopy.parseLiveBackupCopyCLIOptions)(configFile, table, siteId, wpcliCommand);
|
|
72
72
|
const slug = await (0, _devEnvironmentCli.getEnvironmentName)(optRest);
|
|
73
73
|
const trackerFn = (0, _tracker.makeCommandTracker)('dev_env_sync_sql', {
|
|
74
74
|
app: app.id,
|
|
@@ -22,11 +22,11 @@ const examples = [{
|
|
|
22
22
|
usage: 'vip @example-app.develop export sql --table=wp_posts,wp_comments',
|
|
23
23
|
description: 'Generate a database backup including only the wp_posts and wp_comments tables using comma-separated syntax, and download a copy of that backup.'
|
|
24
24
|
}, {
|
|
25
|
-
usage: 'vip @example-app.develop export sql --
|
|
26
|
-
description: 'Generate a database backup including only the tables related to the
|
|
25
|
+
usage: 'vip @example-app.develop export sql --site-id=2 --site-id=3',
|
|
26
|
+
description: 'Generate a database backup including only the tables related to the network sites with IDs 2 and 3, and download a copy of that backup.'
|
|
27
27
|
}, {
|
|
28
|
-
usage: 'vip @example-app.develop export sql --
|
|
29
|
-
description: 'Generate a database backup including only the tables related to the
|
|
28
|
+
usage: 'vip @example-app.develop export sql --site-id=2,3',
|
|
29
|
+
description: 'Generate a database backup including only the tables related to the network sites with IDs 2 and 3 using comma-separated syntax, and download a copy of that backup.'
|
|
30
30
|
}, {
|
|
31
31
|
usage: 'vip @example-app.develop export sql --config-file=~/db-export-config.json',
|
|
32
32
|
description: 'Generate a database backup using the specified config file, and download a copy of that backup.'
|
|
@@ -52,17 +52,17 @@ const appQuery = `
|
|
|
52
52
|
module: 'export-sql',
|
|
53
53
|
requiredArgs: 0,
|
|
54
54
|
usage: 'vip export sql'
|
|
55
|
-
}).option('output', 'Download the file to a specific local directory path with a custom file name.').option('table', 'A table to export from the remote environment. Multiple tables can be specified with multiple --table flags or as a comma-separated list.').option('
|
|
55
|
+
}).option('output', 'Download the file to a specific local directory path with a custom file name.').option('table', 'A table to export from the remote environment. Multiple tables can be specified with multiple --table flags or as a comma-separated list.').option('site-id', 'The ID of a network site to export from the remote environment. Multiple site IDs can be specified with multiple --site-id flags or as a comma-separated list.').option('wpcli-command', 'The WP-CLI command to run on the remote environment to retrieve the database export configuration.').option('config-file', 'The backup copy config file to use for the export.', undefined).option('generate-backup', 'Generate a fresh database backup and export a copy of that backup.').examples(examples).argv(process.argv, async (arg, {
|
|
56
56
|
app,
|
|
57
57
|
env,
|
|
58
58
|
output,
|
|
59
59
|
configFile,
|
|
60
60
|
table,
|
|
61
|
-
|
|
61
|
+
siteId,
|
|
62
62
|
wpcliCommand,
|
|
63
63
|
generateBackup
|
|
64
64
|
}) => {
|
|
65
|
-
const liveBackupCopyCLIOptions = (0, _liveBackupCopy.parseLiveBackupCopyCLIOptions)(configFile, table,
|
|
65
|
+
const liveBackupCopyCLIOptions = (0, _liveBackupCopy.parseLiveBackupCopyCLIOptions)(configFile, table, siteId, wpcliCommand);
|
|
66
66
|
const trackerFn = (0, _tracker.makeCommandTracker)('export_sql', {
|
|
67
67
|
app: app.id,
|
|
68
68
|
env: env.uniqueLabel,
|
package/dist/bin/vip.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
require("../lib/node-version-check");
|
|
4
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
6
|
var _debug = _interopRequireDefault(require("debug"));
|
|
6
7
|
var _enquirer = require("enquirer");
|
|
7
|
-
var _semver = require("semver");
|
|
8
8
|
var _command = _interopRequireWildcard(require("../lib/cli/command"));
|
|
9
9
|
var _config = _interopRequireDefault(require("../lib/cli/config"));
|
|
10
10
|
var _token = _interopRequireDefault(require("../lib/token"));
|
|
11
11
|
var _tracker = require("../lib/tracker");
|
|
12
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const {
|
|
15
|
-
name,
|
|
16
|
-
engines
|
|
17
|
-
} = require('../../package.json');
|
|
18
|
-
const version = engines.node;
|
|
19
|
-
if (version && !(0, _semver.satisfies)(process.version, version)) {
|
|
20
|
-
console.warn(`${_chalk.default.bgYellow('WARNING:')} The current version of Node (${process.version}) does not meet the minimum requirements; ` + `${name} requires Node version ${version}.\n\n` + 'Please follow the installation instructions at https://nodejs.org/en/download/ to upgrade.');
|
|
21
|
-
}
|
|
22
14
|
const debug = (0, _debug.default)('@automattic/vip:bin:vip');
|
|
23
15
|
if (_config.default && _config.default.environment !== 'production') {
|
|
24
16
|
debug(`${_chalk.default.bgYellow('WARNING:')} RUNNING DEV VERSION OF @automattic/vip`);
|
|
@@ -484,13 +484,13 @@ class ExportSQLCommand {
|
|
|
484
484
|
}
|
|
485
485
|
let type = _liveBackupCopy.BackupLiveCopyType.TABLES;
|
|
486
486
|
let tables;
|
|
487
|
-
let
|
|
487
|
+
let siteIds;
|
|
488
488
|
if (this.liveBackupCopyCLIOptions?.tables) {
|
|
489
489
|
tables = Object.fromEntries(this.liveBackupCopyCLIOptions?.tables.map(key => [key, {}]));
|
|
490
490
|
}
|
|
491
|
-
if (this.liveBackupCopyCLIOptions?.
|
|
492
|
-
type = _liveBackupCopy.BackupLiveCopyType.
|
|
493
|
-
|
|
491
|
+
if (this.liveBackupCopyCLIOptions?.siteIds) {
|
|
492
|
+
type = _liveBackupCopy.BackupLiveCopyType.SITE_IDS;
|
|
493
|
+
siteIds = this.liveBackupCopyCLIOptions?.siteIds.map(id => Number(id));
|
|
494
494
|
}
|
|
495
495
|
if (this.liveBackupCopyCLIOptions?.wpcliCommand) {
|
|
496
496
|
type = _liveBackupCopy.BackupLiveCopyType.WP_CLI_COMMAND;
|
|
@@ -498,7 +498,7 @@ class ExportSQLCommand {
|
|
|
498
498
|
return {
|
|
499
499
|
type,
|
|
500
500
|
tables,
|
|
501
|
-
|
|
501
|
+
site_ids: siteIds,
|
|
502
502
|
wpcli_command: this.liveBackupCopyCLIOptions?.wpcliCommand
|
|
503
503
|
};
|
|
504
504
|
}
|
|
@@ -10,13 +10,13 @@ var _userError = _interopRequireDefault(require("./user-error"));
|
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
var _api = _interopRequireDefault(require("../lib/api"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function parseLiveBackupCopyCLIOptions(configFile, table,
|
|
13
|
+
function parseLiveBackupCopyCLIOptions(configFile, table, siteId, wpcliCommand) {
|
|
14
14
|
const options = {};
|
|
15
|
-
if (configFile && (table ||
|
|
16
|
-
throw new _userError.default('The --config-file option cannot be used with the --table, --
|
|
15
|
+
if (configFile && (table || siteId || wpcliCommand)) {
|
|
16
|
+
throw new _userError.default('The --config-file option cannot be used with the --table, --site-id, or --wpcli-command options. Please use only one of these options at a time.');
|
|
17
17
|
}
|
|
18
|
-
if (wpcliCommand && (table ||
|
|
19
|
-
throw new _userError.default('The --wpcli-command option cannot be used with the --table or --
|
|
18
|
+
if (wpcliCommand && (table || siteId)) {
|
|
19
|
+
throw new _userError.default('The --wpcli-command option cannot be used with the --table or --site-id options. Please use only one of these options at a time.');
|
|
20
20
|
}
|
|
21
21
|
let useLiveBackupCopy = false;
|
|
22
22
|
if (table) {
|
|
@@ -27,11 +27,11 @@ function parseLiveBackupCopyCLIOptions(configFile, table, subsiteId, wpcliComman
|
|
|
27
27
|
}
|
|
28
28
|
useLiveBackupCopy = true;
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
31
|
-
if (Array.isArray(
|
|
32
|
-
options.
|
|
30
|
+
if (siteId) {
|
|
31
|
+
if (Array.isArray(siteId)) {
|
|
32
|
+
options.siteIds = siteId.flatMap(id => String(id).split(',').map(idStr => Number(idStr.trim())));
|
|
33
33
|
} else {
|
|
34
|
-
options.
|
|
34
|
+
options.siteIds = String(siteId).split(',').map(idStr => Number(idStr.trim()));
|
|
35
35
|
}
|
|
36
36
|
useLiveBackupCopy = true;
|
|
37
37
|
}
|
|
@@ -73,7 +73,7 @@ const GENERATE_LIVE_BACKUP_DOWNLOAD_URL_MUTATION = exports.GENERATE_LIVE_BACKUP_
|
|
|
73
73
|
let BackupLiveCopyType = exports.BackupLiveCopyType = /*#__PURE__*/function (BackupLiveCopyType) {
|
|
74
74
|
BackupLiveCopyType["FULL"] = "full";
|
|
75
75
|
BackupLiveCopyType["TABLES"] = "tables";
|
|
76
|
-
BackupLiveCopyType["
|
|
76
|
+
BackupLiveCopyType["SITE_IDS"] = "site_ids";
|
|
77
77
|
BackupLiveCopyType["WP_CLI_COMMAND"] = "wpcli_command";
|
|
78
78
|
return BackupLiveCopyType;
|
|
79
79
|
}({});
|
|
@@ -104,7 +104,7 @@ async function startLiveBackupCopy({
|
|
|
104
104
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
105
105
|
if (!result.data?.startLiveBackupCopy.copyId) {
|
|
106
106
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
107
|
-
throw new Error(`Failed to start
|
|
107
|
+
throw new Error(`Failed to start partial database export: ${result.data?.startLiveBackupCopy?.message ? result.data?.startLiveBackupCopy?.message : 'Unknown error'}`);
|
|
108
108
|
}
|
|
109
109
|
return result.data?.startLiveBackupCopy.copyId;
|
|
110
110
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _nodeFs = require("node:fs");
|
|
4
|
+
var _nodePath = require("node:path");
|
|
5
|
+
var _semver = require("semver");
|
|
6
|
+
const boldRed = process.stdout.isTTY ? '\x1b[1;31m' : '';
|
|
7
|
+
const reset = process.stdout.isTTY ? '\x1b[0m' : '';
|
|
8
|
+
try {
|
|
9
|
+
const json = (0, _nodeFs.readFileSync)((0, _nodePath.join)(__dirname, '..', '..', 'package.json'), 'utf8');
|
|
10
|
+
const {
|
|
11
|
+
name,
|
|
12
|
+
engines
|
|
13
|
+
} = JSON.parse(json);
|
|
14
|
+
const version = engines.node;
|
|
15
|
+
if (version && !(0, _semver.satisfies)(process.version, version)) {
|
|
16
|
+
console.warn(`${boldRed}WARNING: The current version of Node (${process.version}) does not meet the minimum requirements; ` + `${name} requires Node version ${version}.\n\n` + `Please follow the installation instructions at https://nodejs.org/en/download/ to upgrade.${reset}\n`);
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
// Do nothing
|
|
20
|
+
}
|