@automattic/vip 2.10.0 → 2.12.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/CONTRIBUTING.md +7 -2
- package/README.md +27 -0
- package/config/{config.json → config.publish.json} +0 -0
- package/dist/bin/vip-dev-env-create.js +1 -0
- package/dist/bin/vip-dev-env-destroy.js +1 -0
- package/dist/bin/vip-dev-env-exec.js +1 -0
- package/dist/bin/vip-dev-env-import-media.js +1 -0
- package/dist/bin/vip-dev-env-import-sql.js +1 -0
- package/dist/bin/vip-dev-env-info.js +1 -0
- package/dist/bin/vip-dev-env-list.js +1 -0
- package/dist/bin/vip-dev-env-start.js +4 -3
- package/dist/bin/vip-dev-env-stop.js +7 -1
- package/dist/bin/vip-dev-env-update.js +1 -0
- package/dist/bin/vip-import-sql.js +7 -1
- package/dist/bin/vip-wp.js +2 -2
- package/dist/bin/vip.js +1 -1
- package/dist/lib/analytics/clients/pendo.js +92 -0
- package/dist/lib/analytics/clients/stub.js +1 -1
- package/dist/lib/analytics/clients/tracks.js +0 -5
- package/dist/lib/analytics/index.js +21 -4
- package/dist/lib/api.js +2 -2
- package/dist/lib/cli/config.js +30 -0
- package/dist/lib/dev-environment/dev-environment-cli.js +25 -2
- package/dist/lib/dev-environment/dev-environment-lando.js +17 -0
- package/dist/lib/http/proxy-agent.js +94 -0
- package/dist/lib/rollbar.js +1 -1
- package/dist/lib/tracker.js +13 -4
- package/npm-shrinkwrap.json +319 -133
- 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/{dist → package/dist}/lib/http/socks-proxy-agent.js +0 -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 +12 -9
- package/helpers/prepare-config.js +0 -19
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGlyphForStatus = getGlyphForStatus;
|
|
7
|
+
exports.mediaImportCheckStatus = mediaImportCheckStatus;
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
+
|
|
12
|
+
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
|
+
|
|
14
|
+
var _fs = require("fs");
|
|
15
|
+
|
|
16
|
+
var path = _interopRequireWildcard(require("path"));
|
|
17
|
+
|
|
18
|
+
var _api = _interopRequireDefault(require("../api"));
|
|
19
|
+
|
|
20
|
+
var _mediaFileImport = require("./media-file-import");
|
|
21
|
+
|
|
22
|
+
var _progress = require("./progress");
|
|
23
|
+
|
|
24
|
+
var _format = require("../cli/format");
|
|
25
|
+
|
|
26
|
+
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); }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @format
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* External dependencies
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Internal dependencies
|
|
43
|
+
*/
|
|
44
|
+
const IMPORT_MEDIA_PROGRESS_POLL_INTERVAL = 1000;
|
|
45
|
+
const ONE_MINUTE_IN_MILLISECONDS = 1000 * 60;
|
|
46
|
+
const TWO_MINUTES_IN_MILLISECONDS = 2 * ONE_MINUTE_IN_MILLISECONDS;
|
|
47
|
+
const IMPORT_MEDIA_PROGRESS_QUERY = (0, _graphqlTag.default)`
|
|
48
|
+
query App( $appId: Int, $envId: Int ) {
|
|
49
|
+
app( id: $appId ) {
|
|
50
|
+
environments( id: $envId ) {
|
|
51
|
+
id
|
|
52
|
+
name
|
|
53
|
+
type
|
|
54
|
+
repo
|
|
55
|
+
mediaImportStatus {
|
|
56
|
+
importId
|
|
57
|
+
siteId
|
|
58
|
+
status
|
|
59
|
+
filesTotal
|
|
60
|
+
filesProcessed
|
|
61
|
+
failureDetails {
|
|
62
|
+
previousStatus
|
|
63
|
+
globalErrors
|
|
64
|
+
fileErrors {
|
|
65
|
+
fileName
|
|
66
|
+
errors
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
async function getStatus(api, appId, envId) {
|
|
76
|
+
const response = await api.query({
|
|
77
|
+
query: IMPORT_MEDIA_PROGRESS_QUERY,
|
|
78
|
+
variables: {
|
|
79
|
+
appId,
|
|
80
|
+
envId
|
|
81
|
+
},
|
|
82
|
+
fetchPolicy: 'network-only'
|
|
83
|
+
});
|
|
84
|
+
const {
|
|
85
|
+
data: {
|
|
86
|
+
app: {
|
|
87
|
+
environments
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} = response;
|
|
91
|
+
|
|
92
|
+
if (!(environments !== null && environments !== void 0 && environments.length)) {
|
|
93
|
+
throw new Error('Unable to determine import status from environment');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [environment] = environments;
|
|
97
|
+
const {
|
|
98
|
+
mediaImportStatus
|
|
99
|
+
} = environment;
|
|
100
|
+
return mediaImportStatus;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getGlyphForStatus(status, runningSprite) {
|
|
104
|
+
switch (status) {
|
|
105
|
+
case 'INITIALIZING':
|
|
106
|
+
return '○';
|
|
107
|
+
|
|
108
|
+
case 'INITIALIZED':
|
|
109
|
+
case 'RUNNING':
|
|
110
|
+
case 'COMPLETING':
|
|
111
|
+
case 'RAN':
|
|
112
|
+
case 'VALIDATING':
|
|
113
|
+
case 'VALIDATED':
|
|
114
|
+
return _chalk.default.blueBright(runningSprite);
|
|
115
|
+
|
|
116
|
+
case 'COMPLETED':
|
|
117
|
+
return _chalk.default.green('✓');
|
|
118
|
+
|
|
119
|
+
case 'FAILED':
|
|
120
|
+
return _chalk.default.red('✕');
|
|
121
|
+
|
|
122
|
+
case 'ABORTED':
|
|
123
|
+
case 'ABORTING':
|
|
124
|
+
return _chalk.default.yellow('⚠️');
|
|
125
|
+
|
|
126
|
+
default:
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function buildErrorMessage(importFailed) {
|
|
132
|
+
let message = '';
|
|
133
|
+
|
|
134
|
+
if ('FAILED' === importFailed.status) {
|
|
135
|
+
const globalFailureDetails = importFailed.failureDetails;
|
|
136
|
+
|
|
137
|
+
if (globalFailureDetails) {
|
|
138
|
+
message += `${_chalk.default.red('Import failed at status: ')}`;
|
|
139
|
+
message += `${_chalk.default.redBright.bold(globalFailureDetails.previousStatus)}\n`;
|
|
140
|
+
message += _chalk.default.red('Errors:');
|
|
141
|
+
globalFailureDetails.globalErrors.forEach(value => {
|
|
142
|
+
message += `\n\t- ${_chalk.default.redBright.bold(value)}`;
|
|
143
|
+
});
|
|
144
|
+
return message;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
message += _chalk.default.red(importFailed.error ? importFailed.error : importFailed);
|
|
149
|
+
message += '\n\nPlease check the status of your Import using `vip import media status @mysite.production`';
|
|
150
|
+
message += '\n\nIf this error persists and you are not sure on how to fix, please contact support\n';
|
|
151
|
+
return message;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function buildFileErrors(fileErrors, exportFileErrorsToJson) {
|
|
155
|
+
if (exportFileErrorsToJson) {
|
|
156
|
+
const fileErrorsToExport = fileErrors.map(fileError => {
|
|
157
|
+
return {
|
|
158
|
+
fileName: fileError.fileName,
|
|
159
|
+
errors: fileError.errors
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
return (0, _format.formatData)(fileErrorsToExport, 'json');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
let errorString = '';
|
|
166
|
+
|
|
167
|
+
for (const fileError of fileErrors) {
|
|
168
|
+
errorString += `File Name: ${fileError.fileName}`;
|
|
169
|
+
errorString += `\n\nErrors:\n\t- ${fileError.errors}\n\n\n\n`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return errorString;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function mediaImportCheckStatus({
|
|
176
|
+
app,
|
|
177
|
+
env,
|
|
178
|
+
progressTracker,
|
|
179
|
+
exportFileErrorsToJson
|
|
180
|
+
}) {
|
|
181
|
+
// Stop printing so we can pass our callback
|
|
182
|
+
progressTracker.stopPrinting(); // NO `console.log` in this function (until results are final)! It will break the progress printing.
|
|
183
|
+
|
|
184
|
+
const api = await (0, _api.default)();
|
|
185
|
+
|
|
186
|
+
if (!(0, _mediaFileImport.currentUserCanImportForApp)(app)) {
|
|
187
|
+
throw new Error('The currently authenticated account does not have permission to view Media Import status.');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let overallStatus = 'Checking...';
|
|
191
|
+
|
|
192
|
+
const setProgressTrackerSuffix = () => {
|
|
193
|
+
const sprite = getGlyphForStatus(overallStatus, progressTracker.runningSprite);
|
|
194
|
+
const exitPrompt = '(Press ^C to hide progress. The import will continue in the background.)';
|
|
195
|
+
let statusMessage;
|
|
196
|
+
|
|
197
|
+
switch (overallStatus) {
|
|
198
|
+
case 'INITIALIZING':
|
|
199
|
+
statusMessage = `INITIALIZING ${sprite} : We're downloading the files to be imported...`;
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
case 'COMPLETED':
|
|
203
|
+
statusMessage = `COMPLETED ${sprite} : The imported files should be visible on your App`;
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
default:
|
|
207
|
+
statusMessage = `${(0, _format.capitalize)(overallStatus)} ${sprite}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const maybeExitPrompt = ['COMPLETED', 'ABORTED', 'FAILED'].includes(overallStatus) ? '' : exitPrompt;
|
|
211
|
+
const suffix = `
|
|
212
|
+
=============================================================
|
|
213
|
+
Status: ${statusMessage}
|
|
214
|
+
App: ${app.name} (${(0, _format.formatEnvironment)(env.type)})
|
|
215
|
+
=============================================================
|
|
216
|
+
${maybeExitPrompt}
|
|
217
|
+
`;
|
|
218
|
+
progressTracker.suffix = suffix;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const setSuffixAndPrint = () => {
|
|
222
|
+
setProgressTrackerSuffix();
|
|
223
|
+
progressTracker.print();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
progressTracker.startPrinting(setSuffixAndPrint);
|
|
227
|
+
|
|
228
|
+
const getResults = () => new Promise((resolve, reject) => {
|
|
229
|
+
let startDate = Date.now();
|
|
230
|
+
let pollIntervalDecreasing = false;
|
|
231
|
+
|
|
232
|
+
const checkStatus = async pollInterval => {
|
|
233
|
+
let mediaImportStatus;
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
mediaImportStatus = await getStatus(api, app.id, env.id);
|
|
237
|
+
|
|
238
|
+
if (!mediaImportStatus) {
|
|
239
|
+
return reject({
|
|
240
|
+
error: 'Requested app/environment is not available for this operation. If you think this is not correct, please contact Support.'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
return reject({
|
|
245
|
+
error
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const {
|
|
250
|
+
status
|
|
251
|
+
} = mediaImportStatus;
|
|
252
|
+
const failedMediaImport = 'FAILED' === status;
|
|
253
|
+
|
|
254
|
+
if (failedMediaImport) {
|
|
255
|
+
progressTracker.setStatus(mediaImportStatus);
|
|
256
|
+
overallStatus = 'FAILED';
|
|
257
|
+
setSuffixAndPrint();
|
|
258
|
+
return reject({ ...mediaImportStatus,
|
|
259
|
+
error: 'Import FAILED'
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
progressTracker.setStatus(mediaImportStatus);
|
|
264
|
+
setSuffixAndPrint();
|
|
265
|
+
|
|
266
|
+
if (['COMPLETED', 'ABORTED'].includes(status)) {
|
|
267
|
+
return resolve(mediaImportStatus);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
overallStatus = status; // after two minutes, we'll start decreasing the pollInterval
|
|
271
|
+
|
|
272
|
+
pollIntervalDecreasing = pollIntervalDecreasing || startDate < Date.now() - TWO_MINUTES_IN_MILLISECONDS; // decrease poll interval by a second, every minute
|
|
273
|
+
|
|
274
|
+
if (pollIntervalDecreasing && startDate < Date.now() - ONE_MINUTE_IN_MILLISECONDS) {
|
|
275
|
+
pollInterval = pollInterval + IMPORT_MEDIA_PROGRESS_POLL_INTERVAL;
|
|
276
|
+
startDate = Date.now();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
setTimeout(() => {
|
|
280
|
+
checkStatus(pollInterval);
|
|
281
|
+
}, pollInterval);
|
|
282
|
+
}; // Kick off the check
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
checkStatus(IMPORT_MEDIA_PROGRESS_POLL_INTERVAL);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
var _results$failureDetai;
|
|
290
|
+
|
|
291
|
+
const results = await getResults();
|
|
292
|
+
overallStatus = (results === null || results === void 0 ? void 0 : results.status) || 'unknown';
|
|
293
|
+
progressTracker.stopPrinting();
|
|
294
|
+
setProgressTrackerSuffix();
|
|
295
|
+
progressTracker.print();
|
|
296
|
+
const fileErrors = (_results$failureDetai = results.failureDetails) === null || _results$failureDetai === void 0 ? void 0 : _results$failureDetai.fileErrors;
|
|
297
|
+
|
|
298
|
+
if (!!fileErrors && fileErrors.length > 0) {
|
|
299
|
+
progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${fileErrors.length} file error(s) have been extracted`)}`;
|
|
300
|
+
|
|
301
|
+
if (results.filesTotal - results.filesProcessed !== fileErrors.length) {
|
|
302
|
+
progressTracker.suffix += `. ${_chalk.default.italic.yellow('File-errors report size threshold reached.')}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const formattedData = buildFileErrors(fileErrors, exportFileErrorsToJson);
|
|
306
|
+
const errorsFile = `media-import-${app.name}-${Date.now()}${!!exportFileErrorsToJson ? '.json' : '.txt'}`;
|
|
307
|
+
|
|
308
|
+
try {
|
|
309
|
+
await _fs.promises.writeFile(errorsFile, formattedData);
|
|
310
|
+
progressTracker.suffix += `\n\n${_chalk.default.yellow(`All errors have been exported to ${_chalk.default.bold(path.resolve(errorsFile))}`)}\n\n`;
|
|
311
|
+
} catch (writeFileErr) {
|
|
312
|
+
progressTracker.suffix += `\n\n${_chalk.default.red(`Could not export errors to file\n${writeFileErr}`)}\n\n`;
|
|
313
|
+
}
|
|
314
|
+
} // Print one final time
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
progressTracker.print({
|
|
318
|
+
clearAfter: true
|
|
319
|
+
});
|
|
320
|
+
process.exit(0);
|
|
321
|
+
} catch (importFailed) {
|
|
322
|
+
progressTracker.stopPrinting();
|
|
323
|
+
progressTracker.print();
|
|
324
|
+
progressTracker.suffix += `\n${buildErrorMessage(importFailed)}`;
|
|
325
|
+
progressTracker.print({
|
|
326
|
+
clearAfter: true
|
|
327
|
+
});
|
|
328
|
+
process.exit(1);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
var _default = {
|
|
333
|
+
mediaImportCheckStatus
|
|
334
|
+
};
|
|
335
|
+
exports.default = _default;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rollbar = void 0;
|
|
7
|
+
|
|
8
|
+
var _env = _interopRequireDefault(require("./env"));
|
|
9
|
+
|
|
10
|
+
var _config = _interopRequireDefault(require("../../config/config.json"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
const Rollbar = require('rollbar');
|
|
18
|
+
|
|
19
|
+
const rollbar = new Rollbar({
|
|
20
|
+
accessToken: '99c8f982d64f47049fde6f6f9d567070',
|
|
21
|
+
captureUncaught: true,
|
|
22
|
+
captureUnhandledRejections: true,
|
|
23
|
+
|
|
24
|
+
/* eslint-disable camelcase */
|
|
25
|
+
payload: {
|
|
26
|
+
platform: 'client',
|
|
27
|
+
cli_version: _env.default.app.version,
|
|
28
|
+
os_name: _env.default.os.name,
|
|
29
|
+
node_version: _env.default.node.version,
|
|
30
|
+
environment: _config.default.environment
|
|
31
|
+
}
|
|
32
|
+
/* eslint-enable camelcase */
|
|
33
|
+
|
|
34
|
+
});
|
|
35
|
+
exports.rollbar = rollbar;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getReadAndWriteStreams = getReadAndWriteStreams;
|
|
7
|
+
exports.searchAndReplace = void 0;
|
|
8
|
+
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
|
|
11
|
+
var _os = _interopRequireDefault(require("os"));
|
|
12
|
+
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
|
|
15
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
16
|
+
|
|
17
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
18
|
+
|
|
19
|
+
var _vipSearchReplace = require("@automattic/vip-search-replace");
|
|
20
|
+
|
|
21
|
+
var _tracker = require("./tracker");
|
|
22
|
+
|
|
23
|
+
var _prompt = require("./cli/prompt");
|
|
24
|
+
|
|
25
|
+
var _clientFileUploader = require("./client-file-uploader");
|
|
26
|
+
|
|
27
|
+
var exit = _interopRequireWildcard(require("./cli/exit"));
|
|
28
|
+
|
|
29
|
+
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); }
|
|
30
|
+
|
|
31
|
+
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; }
|
|
32
|
+
|
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @format
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* External dependencies
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Internal dependencies
|
|
46
|
+
*/
|
|
47
|
+
const debug = (0, _debug.default)('@automattic/vip:lib:search-and-replace');
|
|
48
|
+
|
|
49
|
+
const flatten = arr => {
|
|
50
|
+
return arr.reduce((flat, toFlatten) => {
|
|
51
|
+
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
|
|
52
|
+
}, []);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function makeTempDir() {
|
|
56
|
+
const tmpDir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'vip-search-replace-'));
|
|
57
|
+
|
|
58
|
+
debug(`Created a directory to hold temporary files: ${tmpDir}`);
|
|
59
|
+
return tmpDir;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getReadAndWriteStreams({
|
|
63
|
+
fileName,
|
|
64
|
+
inPlace,
|
|
65
|
+
output
|
|
66
|
+
}) {
|
|
67
|
+
let writeStream;
|
|
68
|
+
let usingStdOut = false;
|
|
69
|
+
let outputFileName;
|
|
70
|
+
|
|
71
|
+
if (inPlace) {
|
|
72
|
+
const midputFileName = _path.default.join(makeTempDir(), _path.default.basename(fileName));
|
|
73
|
+
|
|
74
|
+
_fs.default.copyFileSync(fileName, midputFileName);
|
|
75
|
+
|
|
76
|
+
debug(`Copied input file to ${midputFileName}`);
|
|
77
|
+
debug(`Set output to the original file path ${fileName}`);
|
|
78
|
+
outputFileName = fileName;
|
|
79
|
+
return {
|
|
80
|
+
outputFileName,
|
|
81
|
+
readStream: _fs.default.createReadStream(midputFileName),
|
|
82
|
+
usingStdOut,
|
|
83
|
+
writeStream: _fs.default.createWriteStream(fileName)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
debug(`Reading input from file: ${fileName}`);
|
|
88
|
+
|
|
89
|
+
switch (typeof output) {
|
|
90
|
+
case 'string':
|
|
91
|
+
writeStream = _fs.default.createWriteStream(output);
|
|
92
|
+
outputFileName = output;
|
|
93
|
+
debug(`Outputting to file: ${outputFileName}`);
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case 'object':
|
|
97
|
+
writeStream = output;
|
|
98
|
+
|
|
99
|
+
if (writeStream === process.stdout) {
|
|
100
|
+
usingStdOut = true;
|
|
101
|
+
debug('Outputting to the standard output stream');
|
|
102
|
+
} else {
|
|
103
|
+
debug('Outputting to the provided output stream');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
default:
|
|
109
|
+
const tmpOutFile = _path.default.join(makeTempDir(), _path.default.basename(fileName));
|
|
110
|
+
|
|
111
|
+
writeStream = _fs.default.createWriteStream(tmpOutFile);
|
|
112
|
+
outputFileName = tmpOutFile;
|
|
113
|
+
debug(`Outputting to file: ${outputFileName}`);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
outputFileName,
|
|
119
|
+
readStream: _fs.default.createReadStream(fileName),
|
|
120
|
+
usingStdOut,
|
|
121
|
+
writeStream
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const searchAndReplace = async (fileName, pairs, {
|
|
126
|
+
isImport = true,
|
|
127
|
+
inPlace = false,
|
|
128
|
+
output = process.stdout
|
|
129
|
+
}, binary = null) => {
|
|
130
|
+
await (0, _tracker.trackEvent)('searchreplace_started', {
|
|
131
|
+
is_import: isImport,
|
|
132
|
+
in_place: inPlace
|
|
133
|
+
});
|
|
134
|
+
const startTime = process.hrtime();
|
|
135
|
+
const fileSize = (0, _clientFileUploader.getFileSize)(fileName); // if we don't have any pairs to replace with, return the input file
|
|
136
|
+
|
|
137
|
+
if (!pairs || !pairs.length) {
|
|
138
|
+
throw new Error('No search and replace parameters provided.');
|
|
139
|
+
} // If only one pair is provided, ensure we have an array
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if (!Array.isArray(pairs)) {
|
|
143
|
+
pairs = [pairs];
|
|
144
|
+
} // determine all the replacements required
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
const replacementsArr = pairs.map(pair => pair.split(',').map(str => str.trim()));
|
|
148
|
+
const replacements = flatten(replacementsArr);
|
|
149
|
+
debug('Pairs: ', pairs, 'Replacements: ', replacements);
|
|
150
|
+
|
|
151
|
+
if (inPlace) {
|
|
152
|
+
const approved = await (0, _prompt.confirm)([], 'Are you sure you want to run search and replace on your input file? This operation is not reversible.'); // Bail if user does not wish to proceed
|
|
153
|
+
|
|
154
|
+
if (!approved) {
|
|
155
|
+
await (0, _tracker.trackEvent)('search_replace_in_place_cancelled', {
|
|
156
|
+
is_import: isImport,
|
|
157
|
+
in_place: inPlace
|
|
158
|
+
});
|
|
159
|
+
process.exit();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
usingStdOut,
|
|
165
|
+
outputFileName,
|
|
166
|
+
readStream,
|
|
167
|
+
writeStream
|
|
168
|
+
} = getReadAndWriteStreams({
|
|
169
|
+
fileName,
|
|
170
|
+
inPlace,
|
|
171
|
+
output
|
|
172
|
+
});
|
|
173
|
+
let replacedStream;
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements, binary);
|
|
177
|
+
} catch (replaceError) {
|
|
178
|
+
exit.withError(replaceError);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const result = await new Promise((resolve, reject) => {
|
|
182
|
+
replacedStream.pipe(writeStream).on('finish', () => {
|
|
183
|
+
resolve({
|
|
184
|
+
inputFileName: fileName,
|
|
185
|
+
outputFileName,
|
|
186
|
+
usingStdOut
|
|
187
|
+
});
|
|
188
|
+
}).on('error', () => {
|
|
189
|
+
console.log(_chalk.default.red("Oh no! We couldn't write to the output file. Please check your available disk space and file/folder permissions."));
|
|
190
|
+
reject();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
const endTime = process.hrtime(startTime);
|
|
194
|
+
const end = endTime[1] / 1000000; // time in ms
|
|
195
|
+
|
|
196
|
+
await (0, _tracker.trackEvent)('searchreplace_completed', {
|
|
197
|
+
time_to_run: end,
|
|
198
|
+
file_size: fileSize
|
|
199
|
+
});
|
|
200
|
+
return result;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
exports.searchAndReplace = searchAndReplace;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.currentUserCanImportForApp = currentUserCanImportForApp;
|
|
7
|
+
exports.isImportingBlockedBySync = exports.SYNC_STATUS_NOT_SYNCING = exports.isSupportedApp = exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = exports.SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = exports.SQL_IMPORT_FILE_SIZE_LIMIT = void 0;
|
|
8
|
+
|
|
9
|
+
var _fileSize = require("../constants/file-size");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @format
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
const SQL_IMPORT_FILE_SIZE_LIMIT = 100 * _fileSize.GB_IN_BYTES;
|
|
20
|
+
exports.SQL_IMPORT_FILE_SIZE_LIMIT = SQL_IMPORT_FILE_SIZE_LIMIT;
|
|
21
|
+
const SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = 350 * _fileSize.MB_IN_BYTES;
|
|
22
|
+
exports.SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED;
|
|
23
|
+
|
|
24
|
+
function currentUserCanImportForApp(app) {
|
|
25
|
+
// TODO: implement
|
|
26
|
+
return !!app;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = ['WordPress'];
|
|
30
|
+
exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = SUPPORTED_DB_FILE_IMPORT_SITE_TYPES;
|
|
31
|
+
|
|
32
|
+
const isSupportedApp = ({
|
|
33
|
+
type
|
|
34
|
+
}) => SUPPORTED_DB_FILE_IMPORT_SITE_TYPES.includes(type);
|
|
35
|
+
|
|
36
|
+
exports.isSupportedApp = isSupportedApp;
|
|
37
|
+
const SYNC_STATUS_NOT_SYNCING = 'not_syncing';
|
|
38
|
+
exports.SYNC_STATUS_NOT_SYNCING = SYNC_STATUS_NOT_SYNCING;
|
|
39
|
+
|
|
40
|
+
const isImportingBlockedBySync = ({
|
|
41
|
+
syncProgress: {
|
|
42
|
+
status
|
|
43
|
+
}
|
|
44
|
+
}) => status !== SYNC_STATUS_NOT_SYNCING;
|
|
45
|
+
|
|
46
|
+
exports.isImportingBlockedBySync = isImportingBlockedBySync;
|