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