@automattic/vip 2.12.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +12 -1
  2. package/dist/bin/vip-cache-purge-url.js +93 -0
  3. package/{package/dist/bin/vip-config.js → dist/bin/vip-cache.js} +6 -3
  4. package/dist/bin/vip-dev-env-import-sql.js +8 -1
  5. package/dist/bin/vip-dev-env-start.js +2 -1
  6. package/dist/bin/vip-dev-env-update.js +1 -0
  7. package/dist/bin/vip.js +1 -1
  8. package/dist/lib/api/cache-purge.js +76 -0
  9. package/dist/lib/dev-environment/dev-environment-lando.js +31 -3
  10. package/dist/lib/envvar/read-file.js +2 -18
  11. package/{package/dist/lib/envvar → dist/lib}/read-file.js +3 -6
  12. package/dist/lib/validations/sql.js +134 -52
  13. package/npm-shrinkwrap.json +79 -79
  14. package/package.json +4 -2
  15. package/package/dist/bin/vip-app-list.js +0 -73
  16. package/package/dist/bin/vip-app.js +0 -76
  17. package/package/dist/bin/vip-config-envvar-delete.js +0 -97
  18. package/package/dist/bin/vip-config-envvar-get-all.js +0 -94
  19. package/package/dist/bin/vip-config-envvar-get.js +0 -79
  20. package/package/dist/bin/vip-config-envvar-list.js +0 -91
  21. package/package/dist/bin/vip-config-envvar-set.js +0 -123
  22. package/package/dist/bin/vip-config-envvar.js +0 -23
  23. package/package/dist/bin/vip-dev-env-create.js +0 -105
  24. package/package/dist/bin/vip-dev-env-destroy.js +0 -56
  25. package/package/dist/bin/vip-dev-env-exec.js +0 -67
  26. package/package/dist/bin/vip-dev-env-import-media.js +0 -51
  27. package/package/dist/bin/vip-dev-env-import-sql.js +0 -83
  28. package/package/dist/bin/vip-dev-env-import.js +0 -32
  29. package/package/dist/bin/vip-dev-env-info.js +0 -61
  30. package/package/dist/bin/vip-dev-env-list.js +0 -46
  31. package/package/dist/bin/vip-dev-env-start.js +0 -77
  32. package/package/dist/bin/vip-dev-env-stop.js +0 -52
  33. package/package/dist/bin/vip-dev-env-update.js +0 -89
  34. package/package/dist/bin/vip-dev-env.js +0 -23
  35. package/package/dist/bin/vip-import-media-abort.js +0 -132
  36. package/package/dist/bin/vip-import-media-status.js +0 -84
  37. package/package/dist/bin/vip-import-media.js +0 -168
  38. package/package/dist/bin/vip-import-sql-status.js +0 -83
  39. package/package/dist/bin/vip-import-sql.js +0 -580
  40. package/package/dist/bin/vip-import-validate-files.js +0 -191
  41. package/package/dist/bin/vip-import-validate-sql.js +0 -34
  42. package/package/dist/bin/vip-import.js +0 -20
  43. package/package/dist/bin/vip-logs.js +0 -232
  44. package/package/dist/bin/vip-search-replace.js +0 -71
  45. package/package/dist/bin/vip-sync.js +0 -191
  46. package/package/dist/bin/vip-whoami.js +0 -67
  47. package/package/dist/bin/vip-wp.js +0 -555
  48. package/package/dist/bin/vip.js +0 -149
  49. package/package/dist/lib/analytics/clients/client.js +0 -1
  50. package/package/dist/lib/analytics/clients/pendo.js +0 -92
  51. package/package/dist/lib/analytics/clients/stub.js +0 -19
  52. package/package/dist/lib/analytics/clients/tracks.js +0 -128
  53. package/package/dist/lib/analytics/index.js +0 -45
  54. package/package/dist/lib/api/app.js +0 -70
  55. package/package/dist/lib/api/feature-flags.js +0 -39
  56. package/package/dist/lib/api/user.js +0 -58
  57. package/package/dist/lib/api.js +0 -136
  58. package/package/dist/lib/app-logs/app-logs.js +0 -70
  59. package/package/dist/lib/cli/apiConfig.js +0 -90
  60. package/package/dist/lib/cli/command.js +0 -606
  61. package/package/dist/lib/cli/envAlias.js +0 -60
  62. package/package/dist/lib/cli/exit.js +0 -33
  63. package/package/dist/lib/cli/format.js +0 -213
  64. package/package/dist/lib/cli/pager.js +0 -52
  65. package/package/dist/lib/cli/progress.js +0 -208
  66. package/package/dist/lib/cli/prompt.js +0 -37
  67. package/package/dist/lib/cli/repo.js +0 -77
  68. package/package/dist/lib/client-file-uploader.js +0 -602
  69. package/package/dist/lib/constants/dev-environment.js +0 -42
  70. package/package/dist/lib/constants/file-size.js +0 -14
  71. package/package/dist/lib/dev-environment/dev-environment-cli.js +0 -508
  72. package/package/dist/lib/dev-environment/dev-environment-core.js +0 -620
  73. package/package/dist/lib/dev-environment/dev-environment-lando.js +0 -330
  74. package/package/dist/lib/dev-environment/types.js +0 -1
  75. package/package/dist/lib/env.js +0 -36
  76. package/package/dist/lib/envvar/api-delete.js +0 -56
  77. package/package/dist/lib/envvar/api-get-all.js +0 -59
  78. package/package/dist/lib/envvar/api-get.js +0 -24
  79. package/package/dist/lib/envvar/api-list.js +0 -60
  80. package/package/dist/lib/envvar/api-set.js +0 -58
  81. package/package/dist/lib/envvar/api.js +0 -104
  82. package/package/dist/lib/envvar/input.js +0 -55
  83. package/package/dist/lib/envvar/logging.js +0 -33
  84. package/package/dist/lib/http/socks-proxy-agent.js +0 -25
  85. package/package/dist/lib/keychain/browser.js +0 -35
  86. package/package/dist/lib/keychain/insecure.js +0 -63
  87. package/package/dist/lib/keychain/keychain.js +0 -1
  88. package/package/dist/lib/keychain/secure.js +0 -36
  89. package/package/dist/lib/keychain.js +0 -36
  90. package/package/dist/lib/media-import/media-file-import.js +0 -34
  91. package/package/dist/lib/media-import/progress.js +0 -86
  92. package/package/dist/lib/media-import/status.js +0 -335
  93. package/package/dist/lib/rollbar.js +0 -35
  94. package/package/dist/lib/search-and-replace.js +0 -203
  95. package/package/dist/lib/site-import/db-file-import.js +0 -46
  96. package/package/dist/lib/site-import/status.js +0 -444
  97. package/package/dist/lib/token.js +0 -132
  98. package/package/dist/lib/tracker.js +0 -96
  99. package/package/dist/lib/validations/is-multi-site-sql-dump.js +0 -59
  100. package/package/dist/lib/validations/is-multi-site.js +0 -99
  101. package/package/dist/lib/validations/line-by-line.js +0 -92
  102. package/package/dist/lib/validations/site-type.js +0 -66
  103. package/package/dist/lib/validations/sql.js +0 -371
  104. package/package/dist/lib/vip-import-validate-files.js +0 -548
  105. package/package/vip.iml +0 -11
@@ -1,335 +0,0 @@
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;
@@ -1,35 +0,0 @@
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;
@@ -1,203 +0,0 @@
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;
@@ -1,46 +0,0 @@
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;