@automattic/vip 2.12.0 → 2.14.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 (109) hide show
  1. package/README.md +27 -3
  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-exec.js +9 -2
  5. package/dist/bin/vip-dev-env-import-sql.js +8 -1
  6. package/dist/bin/vip-dev-env-start.js +2 -1
  7. package/dist/bin/vip-dev-env-update.js +1 -0
  8. package/dist/bin/vip.js +1 -1
  9. package/dist/lib/api/cache-purge.js +76 -0
  10. package/dist/lib/dev-environment/dev-environment-cli.js +2 -2
  11. package/dist/lib/dev-environment/dev-environment-core.js +3 -3
  12. package/dist/lib/dev-environment/dev-environment-lando.js +38 -7
  13. package/dist/lib/envvar/read-file.js +2 -18
  14. package/{package/dist/lib/envvar → dist/lib}/read-file.js +3 -6
  15. package/dist/lib/validations/sql.js +175 -53
  16. package/npm-shrinkwrap.json +82 -82
  17. package/package.json +5 -3
  18. package/.circleci/config.yml +0 -67
  19. package/package/dist/bin/vip-app-list.js +0 -73
  20. package/package/dist/bin/vip-app.js +0 -76
  21. package/package/dist/bin/vip-config-envvar-delete.js +0 -97
  22. package/package/dist/bin/vip-config-envvar-get-all.js +0 -94
  23. package/package/dist/bin/vip-config-envvar-get.js +0 -79
  24. package/package/dist/bin/vip-config-envvar-list.js +0 -91
  25. package/package/dist/bin/vip-config-envvar-set.js +0 -123
  26. package/package/dist/bin/vip-config-envvar.js +0 -23
  27. package/package/dist/bin/vip-dev-env-create.js +0 -105
  28. package/package/dist/bin/vip-dev-env-destroy.js +0 -56
  29. package/package/dist/bin/vip-dev-env-exec.js +0 -67
  30. package/package/dist/bin/vip-dev-env-import-media.js +0 -51
  31. package/package/dist/bin/vip-dev-env-import-sql.js +0 -83
  32. package/package/dist/bin/vip-dev-env-import.js +0 -32
  33. package/package/dist/bin/vip-dev-env-info.js +0 -61
  34. package/package/dist/bin/vip-dev-env-list.js +0 -46
  35. package/package/dist/bin/vip-dev-env-start.js +0 -77
  36. package/package/dist/bin/vip-dev-env-stop.js +0 -52
  37. package/package/dist/bin/vip-dev-env-update.js +0 -89
  38. package/package/dist/bin/vip-dev-env.js +0 -23
  39. package/package/dist/bin/vip-import-media-abort.js +0 -132
  40. package/package/dist/bin/vip-import-media-status.js +0 -84
  41. package/package/dist/bin/vip-import-media.js +0 -168
  42. package/package/dist/bin/vip-import-sql-status.js +0 -83
  43. package/package/dist/bin/vip-import-sql.js +0 -580
  44. package/package/dist/bin/vip-import-validate-files.js +0 -191
  45. package/package/dist/bin/vip-import-validate-sql.js +0 -34
  46. package/package/dist/bin/vip-import.js +0 -20
  47. package/package/dist/bin/vip-logs.js +0 -232
  48. package/package/dist/bin/vip-search-replace.js +0 -71
  49. package/package/dist/bin/vip-sync.js +0 -191
  50. package/package/dist/bin/vip-whoami.js +0 -67
  51. package/package/dist/bin/vip-wp.js +0 -555
  52. package/package/dist/bin/vip.js +0 -149
  53. package/package/dist/lib/analytics/clients/client.js +0 -1
  54. package/package/dist/lib/analytics/clients/pendo.js +0 -92
  55. package/package/dist/lib/analytics/clients/stub.js +0 -19
  56. package/package/dist/lib/analytics/clients/tracks.js +0 -128
  57. package/package/dist/lib/analytics/index.js +0 -45
  58. package/package/dist/lib/api/app.js +0 -70
  59. package/package/dist/lib/api/feature-flags.js +0 -39
  60. package/package/dist/lib/api/user.js +0 -58
  61. package/package/dist/lib/api.js +0 -136
  62. package/package/dist/lib/app-logs/app-logs.js +0 -70
  63. package/package/dist/lib/cli/apiConfig.js +0 -90
  64. package/package/dist/lib/cli/command.js +0 -606
  65. package/package/dist/lib/cli/envAlias.js +0 -60
  66. package/package/dist/lib/cli/exit.js +0 -33
  67. package/package/dist/lib/cli/format.js +0 -213
  68. package/package/dist/lib/cli/pager.js +0 -52
  69. package/package/dist/lib/cli/progress.js +0 -208
  70. package/package/dist/lib/cli/prompt.js +0 -37
  71. package/package/dist/lib/cli/repo.js +0 -77
  72. package/package/dist/lib/client-file-uploader.js +0 -602
  73. package/package/dist/lib/constants/dev-environment.js +0 -42
  74. package/package/dist/lib/constants/file-size.js +0 -14
  75. package/package/dist/lib/dev-environment/dev-environment-cli.js +0 -508
  76. package/package/dist/lib/dev-environment/dev-environment-core.js +0 -620
  77. package/package/dist/lib/dev-environment/dev-environment-lando.js +0 -330
  78. package/package/dist/lib/dev-environment/types.js +0 -1
  79. package/package/dist/lib/env.js +0 -36
  80. package/package/dist/lib/envvar/api-delete.js +0 -56
  81. package/package/dist/lib/envvar/api-get-all.js +0 -59
  82. package/package/dist/lib/envvar/api-get.js +0 -24
  83. package/package/dist/lib/envvar/api-list.js +0 -60
  84. package/package/dist/lib/envvar/api-set.js +0 -58
  85. package/package/dist/lib/envvar/api.js +0 -104
  86. package/package/dist/lib/envvar/input.js +0 -55
  87. package/package/dist/lib/envvar/logging.js +0 -33
  88. package/package/dist/lib/http/socks-proxy-agent.js +0 -25
  89. package/package/dist/lib/keychain/browser.js +0 -35
  90. package/package/dist/lib/keychain/insecure.js +0 -63
  91. package/package/dist/lib/keychain/keychain.js +0 -1
  92. package/package/dist/lib/keychain/secure.js +0 -36
  93. package/package/dist/lib/keychain.js +0 -36
  94. package/package/dist/lib/media-import/media-file-import.js +0 -34
  95. package/package/dist/lib/media-import/progress.js +0 -86
  96. package/package/dist/lib/media-import/status.js +0 -335
  97. package/package/dist/lib/rollbar.js +0 -35
  98. package/package/dist/lib/search-and-replace.js +0 -203
  99. package/package/dist/lib/site-import/db-file-import.js +0 -46
  100. package/package/dist/lib/site-import/status.js +0 -444
  101. package/package/dist/lib/token.js +0 -132
  102. package/package/dist/lib/tracker.js +0 -96
  103. package/package/dist/lib/validations/is-multi-site-sql-dump.js +0 -59
  104. package/package/dist/lib/validations/is-multi-site.js +0 -99
  105. package/package/dist/lib/validations/line-by-line.js +0 -92
  106. package/package/dist/lib/validations/site-type.js +0 -66
  107. package/package/dist/lib/validations/sql.js +0 -371
  108. package/package/dist/lib/vip-import-validate-files.js +0 -548
  109. package/package/vip.iml +0 -11
@@ -1,191 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
- "use strict";
7
-
8
- var _url = _interopRequireDefault(require("url"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _chalk = _interopRequireDefault(require("chalk"));
13
-
14
- var _fs = _interopRequireDefault(require("fs"));
15
-
16
- var _util = require("util");
17
-
18
- var _command = _interopRequireDefault(require("../lib/cli/command"));
19
-
20
- var _vipImportValidateFiles = require("../lib/vip-import-validate-files");
21
-
22
- var _tracker = require("../lib/tracker");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- /**
27
- * Internal dependencies
28
- */
29
- // Promisify to use async/await
30
- const stat = (0, _util.promisify)(_fs.default.stat);
31
- (0, _command.default)({
32
- requiredArgs: 1,
33
- format: true
34
- }).example('vip import validate-files <file>', 'Run the import validation against the file').argv(process.argv, async arg => {
35
- await (0, _tracker.trackEvent)('import_validate_files_command_execute');
36
- /**
37
- * File manipulation
38
- *
39
- * Manipulating the file path/name to extract the folder name
40
- */
41
-
42
- const folder = arg.join(); // File comes in as an array as part of the args- turn it into a string
43
-
44
- arg = _url.default.parse(folder); // Then parse the file to its URL parts
45
-
46
- const filePath = arg.path; // Extract the path of the file
47
-
48
- let folderValidation;
49
- /**
50
- * Folder structure validation
51
- *
52
- * Find nested directories and files to see if media files follow the WordPress recommended folder structure
53
- *
54
- * Recommended structure: `uploads/year/month` (Single sites)
55
- */
56
-
57
- const nestedFiles = (0, _vipImportValidateFiles.findNestedDirectories)(filePath);
58
- const {
59
- files,
60
- folderStructureObj
61
- } = nestedFiles; // Destructure
62
- // Check if there are any nested directories within the given folder
63
-
64
- const nestedDirectories = Object.keys(folderStructureObj);
65
-
66
- if (nestedDirectories && nestedDirectories.length > 0) {
67
- folderValidation = (0, _vipImportValidateFiles.folderStructureValidation)(nestedDirectories);
68
- }
69
- /**
70
- * Individual file validations
71
- *
72
- * - Media file extension/type validation
73
- * - Filename validation
74
- * - Intermediate image validation
75
- */
76
-
77
-
78
- if (!files || !files.length || files.length <= 0) {
79
- console.error(_chalk.default.red('✕ Error:'), 'Media files directory cannot be empty');
80
- }
81
- /**
82
- * Media file extension validation
83
- *
84
- * Ensure that prohibited media file types are not used
85
- */
86
- // Collect invalid files for error logging
87
-
88
-
89
- let intermediateImagesTotal = 0;
90
- const errorFileTypes = [];
91
- const errorFileNames = [];
92
- const intermediateImages = {}; // Iterate through each file to isolate the extension name
93
-
94
- for (const file of files) {
95
- // Check if file is a directory
96
- const stats = await stat(file);
97
- const isFolder = stats.isDirectory();
98
-
99
- const extension = _path.default.extname(file); // Extract the extension of the file
100
-
101
-
102
- const ext = extension.substr(1); // We only want the ext name minus the period (e.g- .jpg -> jpg)
103
-
104
- const extLowerCase = ext.toLowerCase(); // Change any uppercase extensions to lowercase
105
- // Check for any invalid file extensions
106
- // Returns true if ext is valid; false if invalid
107
-
108
- const validExtensions = _vipImportValidateFiles.acceptedExtensions.includes(extLowerCase); // Collect files that have no extension, have invalid extensions,
109
- // or are directories for error logging
110
-
111
-
112
- if (!extension || !validExtensions || isFolder) {
113
- errorFileTypes.push(file);
114
- }
115
- /**
116
- * Filename validation
117
- *
118
- * Ensure that filenames don't contain prohibited characters
119
- */
120
- // Collect files that have invalid file names for error logging
121
-
122
-
123
- if ((0, _vipImportValidateFiles.isFileSanitized)(file)) {
124
- errorFileNames.push(file);
125
- }
126
- /**
127
- * Intermediate image validation
128
- *
129
- * Detect any intermediate images.
130
- *
131
- * Intermediate images are copies of images that are resized, so you may have multiples of the same image.
132
- * You can resize an image directly on VIP so intermediate images are not necessary.
133
- */
134
-
135
-
136
- const original = (0, _vipImportValidateFiles.doesImageHaveExistingSource)(file); // If an image is an intermediate image, increment the total number and
137
- // populate key/value pairs of the original image and intermediate image(s)
138
-
139
- if (original) {
140
- intermediateImagesTotal++;
141
-
142
- if (intermediateImages[original]) {
143
- // Key: original image, value: intermediate image(s)
144
- intermediateImages[original] = `${intermediateImages[original]}, ${file}`;
145
- } else {
146
- intermediateImages[original] = file;
147
- }
148
- }
149
- }
150
- /**
151
- * Error logging
152
- */
153
-
154
-
155
- if (errorFileTypes.length > 0) {
156
- (0, _vipImportValidateFiles.logErrorsForInvalidFileTypes)(errorFileTypes);
157
- }
158
-
159
- if (errorFileNames.length > 0) {
160
- (0, _vipImportValidateFiles.logErrorsForInvalidFilenames)(errorFileNames);
161
- }
162
-
163
- if (Object.keys(intermediateImages).length > 0) {
164
- (0, _vipImportValidateFiles.logErrorsForIntermediateImages)(intermediateImages);
165
- } // Log a summary of all errors
166
-
167
-
168
- (0, _vipImportValidateFiles.summaryLogs)({
169
- folderErrorsLength: folderValidation.length,
170
- intImagesErrorsLength: intermediateImagesTotal,
171
- fileTypeErrorsLength: errorFileTypes.length,
172
- filenameErrorsLength: errorFileNames.length,
173
- totalFiles: files.length,
174
- totalFolders: nestedDirectories.length
175
- }); // Tracks events to track activity
176
- // Props (object keys) need to be in Snake case vs. camelCase
177
-
178
- /* eslint-disable camelcase */
179
-
180
- const allErrors = {
181
- folder_errors_length: folderValidation.length,
182
- int_images_errors_length: intermediateImagesTotal,
183
- file_type_errors_length: errorFileTypes.length,
184
- filename_errors_length: errorFileNames.length,
185
- total_files: files.length,
186
- total_folders: nestedDirectories.length
187
- };
188
- /* eslint-enable camelcase */
189
-
190
- await (0, _tracker.trackEvent)('import_validate_files_command_success', allErrors);
191
- });
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- "use strict";
11
-
12
- var _command = _interopRequireDefault(require("../lib/cli/command"));
13
-
14
- var exit = _interopRequireWildcard(require("../lib/cli/exit"));
15
-
16
- var _sql = require("../lib/validations/sql");
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- 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; }
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- (0, _command.default)({
25
- requiredArgs: 1
26
- }).example('vip import validate-sql <file>', 'Run the import validation against file').argv(process.argv, async arg => {
27
- const filename = arg[0];
28
-
29
- if (!arg && !filename) {
30
- exit.withError('You must pass in a filename');
31
- }
32
-
33
- (0, _sql.validate)(filename);
34
- });
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- "use strict";
11
-
12
- var _command = _interopRequireDefault(require("../lib/cli/command"));
13
-
14
- var _tracker = require("../lib/tracker");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- (0, _command.default)().command('sql', 'Import SQL to your database from a file').command('validate-sql', 'Validate your SQL dump').command('validate-files', 'Validate your media file library').command('media', 'Import media files to the production environment of your application from a compressed web archive').example('vip import sql @mysite.develop <file.sql>', 'Import the given SQL file to your site').example('vip import media @mysite.production https://<path_to_publicly_accessible_archive>', 'Import contents of the given archive file into the media library of your site').argv(process.argv, async () => {
19
- await (0, _tracker.trackEvent)('vip_import_command_execute');
20
- });
@@ -1,232 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * External dependencies
5
- */
6
- "use strict";
7
-
8
- Object.defineProperty(exports, "__esModule", {
9
- value: true
10
- });
11
- exports.getLogs = getLogs;
12
- exports.followLogs = followLogs;
13
- exports.validateInputs = validateInputs;
14
- exports.appQuery = void 0;
15
-
16
- var _chalk = _interopRequireDefault(require("chalk"));
17
-
18
- var _command = _interopRequireDefault(require("../lib/cli/command"));
19
-
20
- var _rollbar = require("../lib/rollbar");
21
-
22
- var _tracker = require("../lib/tracker");
23
-
24
- var logsLib = _interopRequireWildcard(require("../lib/app-logs/app-logs"));
25
-
26
- var exit = _interopRequireWildcard(require("../lib/cli/exit"));
27
-
28
- var _format = require("../lib/cli/format");
29
-
30
- 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); }
31
-
32
- 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; }
33
-
34
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
- /**
37
- * Internal dependencies
38
- */
39
- const LIMIT_MIN = 1;
40
- const LIMIT_MAX = 5000;
41
- const ALLOWED_TYPES = ['app', 'batch'];
42
- const ALLOWED_FORMATS = ['csv', 'json', 'text'];
43
- const DEFAULT_POLLING_DELAY_IN_SECONDS = 30;
44
- const MIN_POLLING_DELAY_IN_SECONDS = 5;
45
- const MAX_POLLING_DELAY_IN_SECONDS = 300;
46
-
47
- async function getLogs(arg, opt) {
48
- validateInputs(opt.type, opt.limit, opt.format);
49
- const trackingParams = getBaseTrackingParams(opt);
50
- await (0, _tracker.trackEvent)('logs_command_execute', trackingParams);
51
- let logs;
52
-
53
- try {
54
- if (opt.follow) {
55
- return await followLogs(opt);
56
- }
57
-
58
- logs = await logsLib.getRecentLogs(opt.app.id, opt.env.id, opt.type, opt.limit);
59
- } catch (error) {
60
- _rollbar.rollbar.error(error);
61
-
62
- await (0, _tracker.trackEvent)('logs_command_error', { ...trackingParams,
63
- error: error.message
64
- });
65
- return exit.withError(error.message);
66
- }
67
-
68
- await (0, _tracker.trackEvent)('logs_command_success', { ...trackingParams,
69
- total: logs.nodes.length
70
- });
71
-
72
- if (!logs.nodes.length) {
73
- console.error('No logs found');
74
- return;
75
- }
76
-
77
- printLogs(logs.nodes, opt.format);
78
- }
79
-
80
- async function followLogs(opt) {
81
- let after = null;
82
- let isFirstRequest = true; // How many times have we polled?
83
-
84
- let requestNumber = 0;
85
- const trackingParams = getBaseTrackingParams(opt); // Set an initial default delay
86
-
87
- let delay = DEFAULT_POLLING_DELAY_IN_SECONDS;
88
-
89
- while (true) {
90
- const limit = isFirstRequest ? opt.limit : LIMIT_MAX;
91
- requestNumber++;
92
- trackingParams.request_number = requestNumber;
93
- trackingParams.request_delay = delay;
94
- trackingParams.limit = limit;
95
- let logs;
96
-
97
- try {
98
- var _logs;
99
-
100
- logs = await logsLib.getRecentLogs(opt.app.id, opt.env.id, opt.type, limit, after);
101
- await (0, _tracker.trackEvent)('logs_command_follow_success', { ...trackingParams,
102
- total: (_logs = logs) === null || _logs === void 0 ? void 0 : _logs.nodes.length
103
- });
104
- } catch (error) {
105
- await (0, _tracker.trackEvent)('logs_command_follow_error', { ...trackingParams,
106
- error: error.message
107
- }); // If the first request fails we don't want to retry (it's probably not recoverable)
108
-
109
- if (isFirstRequest) {
110
- console.error(`${_chalk.default.red('Error:')} Failed to fetch logs.`);
111
- break;
112
- } // Increase the delay on errors to avoid overloading the server, up to a max of 5 minutes
113
-
114
-
115
- delay += DEFAULT_POLLING_DELAY_IN_SECONDS;
116
- delay = Math.min(delay, MAX_POLLING_DELAY_IN_SECONDS);
117
- console.error(`${_chalk.default.red('Error:')} Failed to fetch logs. Trying again in ${delay} seconds.`);
118
-
119
- _rollbar.rollbar.error(error);
120
- }
121
-
122
- if (logs) {
123
- var _logs2, _logs3, _logs4;
124
-
125
- if ((_logs2 = logs) !== null && _logs2 !== void 0 && _logs2.nodes.length) {
126
- printLogs(logs.nodes, opt.format);
127
- }
128
-
129
- after = (_logs3 = logs) === null || _logs3 === void 0 ? void 0 : _logs3.nextCursor;
130
- isFirstRequest = false; // Keep a sane lower limit of MIN_POLLING_DELAY_IN_SECONDS just in case something goes wrong in the server-side
131
-
132
- delay = Math.max(((_logs4 = logs) === null || _logs4 === void 0 ? void 0 : _logs4.pollingDelaySeconds) || DEFAULT_POLLING_DELAY_IN_SECONDS, MIN_POLLING_DELAY_IN_SECONDS);
133
- }
134
-
135
- await new Promise(resolve => setTimeout(resolve, delay * 1000));
136
- }
137
- }
138
-
139
- function getBaseTrackingParams(opt) {
140
- return {
141
- command: 'vip logs',
142
- org_id: opt.app.organization.id,
143
- app_id: opt.app.id,
144
- env_id: opt.env.id,
145
- type: opt.type,
146
- limit: opt.limit,
147
- follow: opt.follow || false,
148
- format: opt.format
149
- };
150
- }
151
-
152
- function printLogs(logs, format) {
153
- // Strip out __typename
154
- logs = logs.map(log => {
155
- const {
156
- timestamp,
157
- message
158
- } = log;
159
- return {
160
- timestamp,
161
- message
162
- };
163
- });
164
- let output = '';
165
-
166
- if (format && 'text' === format) {
167
- const rows = [];
168
-
169
- for (const {
170
- timestamp,
171
- message
172
- } of logs) {
173
- rows.push(`${timestamp} ${message}`);
174
- output = rows.join('\n');
175
- }
176
- } else {
177
- output = (0, _format.formatData)(logs, format);
178
- }
179
-
180
- console.log(output);
181
- }
182
-
183
- function validateInputs(type, limit, format) {
184
- if (!ALLOWED_TYPES.includes(type)) {
185
- exit.withError(`Invalid type: ${type}. The supported types are: ${ALLOWED_TYPES.join(', ')}.`);
186
- }
187
-
188
- if (!ALLOWED_FORMATS.includes(format)) {
189
- exit.withError(`Invalid format: ${format}. The supported formats are: ${ALLOWED_FORMATS.join(', ')}.`);
190
- }
191
-
192
- if (!Number.isInteger(limit) || limit < LIMIT_MIN || limit > logsLib.LIMIT_MAX) {
193
- exit.withError(`Invalid limit: ${limit}. It should be a number between ${LIMIT_MIN} and ${logsLib.LIMIT_MAX}.`);
194
- }
195
- }
196
-
197
- const appQuery = `
198
- id
199
- name
200
- environments {
201
- id
202
- appId
203
- name
204
- type
205
- }
206
- organization {
207
- id
208
- name
209
- }
210
- `;
211
- exports.appQuery = appQuery;
212
- (0, _command.default)({
213
- appContext: true,
214
- appQuery,
215
- envContext: true,
216
- module: 'logs'
217
- }).option('type', 'The type of logs to be returned: "app" or "batch"', 'app').option('limit', 'The maximum number of log lines', 500).option('follow', 'Keep fetching new logs as they are generated').option('format', 'Output the log lines in CSV or JSON format', 'text').examples([{
218
- usage: 'vip @mysite.production logs',
219
- description: 'Get the most recent app logs'
220
- }, {
221
- usage: 'vip @mysite.production logs --type batch',
222
- description: 'Get the most recent batch logs'
223
- }, {
224
- usage: 'vip @mysite.production logs --limit 100',
225
- description: 'Get the most recent 100 log entries'
226
- }, {
227
- usage: 'vip @mysite.production logs --limit 100 --format csv',
228
- description: 'Get the most recent 100 log entries formatted as comma-separated values (CSV)'
229
- }, {
230
- usage: 'vip @mysite.production logs --limit 100 --format json',
231
- description: 'Get the most recent 100 log entries formatted as JSON'
232
- }]).argv(process.argv, getLogs);
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- *
5
- * @format
6
- */
7
-
8
- /**
9
- * External dependencies
10
- */
11
- "use strict";
12
-
13
- var _debug = _interopRequireDefault(require("debug"));
14
-
15
- var _command = _interopRequireDefault(require("../lib/cli/command"));
16
-
17
- var exit = _interopRequireWildcard(require("../lib/cli/exit"));
18
-
19
- var _searchAndReplace = require("../lib/search-and-replace");
20
-
21
- 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); }
22
-
23
- 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; }
24
-
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
-
27
- /**
28
- * Internal dependencies
29
- */
30
- const debug = (0, _debug.default)('@automattic/vip:bin:vip-search-replace'); // Command examples
31
-
32
- const examples = [// `search-replace` flag
33
- {
34
- usage: 'vip search-replace <file.sql> --search-replace="from,to"',
35
- description: 'Replace instances of <from> with <to> in the provided <file.sql>\n' + ' * Ensure there are no spaces between your search-replace parameters'
36
- }, // `in-place` flag
37
- {
38
- usage: 'vip search-replace <file.sql> --search-replace="from,to" --in-place',
39
- description: 'Perform Search and Replace explicitly on the provided input <file.sql> file'
40
- }, // `output` flag
41
- {
42
- usage: 'vip search-replace <file.sql> --search-replace="from,to" --output="<output.sql>"',
43
- description: 'Search and Replace to the specified output <output.sql> file\n' + ' * Has no effect when the `in-place` flag is used'
44
- }];
45
- (0, _command.default)({
46
- requiredArgs: 1
47
- }).option('search-replace', 'Specify the <from> and <to> pairs to be replaced').option('in-place', 'Perform the search and replace explicitly on the input file').option('output', 'Specify the replacement output file for Search and Replace').examples(examples).argv(process.argv, async (arg, opt) => {
48
- // TODO: tracks event for usage of this command stand alone
49
- const {
50
- searchReplace,
51
- inPlace,
52
- output
53
- } = opt;
54
- debug('Args: ', arg, 'searchReplace: ', searchReplace);
55
- const filename = arg[0];
56
-
57
- if (!arg && !filename) {
58
- exit.withError('You must pass in a filename');
59
- }
60
-
61
- if (!searchReplace || !searchReplace.length) {
62
- exit.withError('You must provide a pair of strings (separated by comma) such as original,replacement');
63
- }
64
-
65
- const isImport = false;
66
- await (0, _searchAndReplace.searchAndReplace)(filename, searchReplace, {
67
- isImport,
68
- inPlace,
69
- output
70
- });
71
- });