@redocly/cli 1.18.0 → 1.19.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 (91) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
  3. package/lib/__mocks__/@redocly/openapi-core.js +1 -0
  4. package/lib/__mocks__/fs.d.ts +0 -1
  5. package/lib/__mocks__/perf_hooks.d.ts +0 -1
  6. package/lib/__mocks__/redoc.d.ts +0 -1
  7. package/lib/__tests__/commands/build-docs.test.js +21 -23
  8. package/lib/__tests__/commands/bundle.test.js +21 -30
  9. package/lib/__tests__/commands/join.test.js +101 -70
  10. package/lib/__tests__/commands/lint.test.js +54 -54
  11. package/lib/__tests__/commands/push-region.test.js +24 -25
  12. package/lib/__tests__/commands/push.test.js +269 -170
  13. package/lib/__tests__/fetch-with-timeout.test.js +3 -12
  14. package/lib/__tests__/fixtures/config.d.ts +0 -1
  15. package/lib/__tests__/utils.test.js +32 -37
  16. package/lib/__tests__/wrapper.test.js +31 -20
  17. package/lib/cms/api/__tests__/api.client.test.js +29 -38
  18. package/lib/cms/api/api-client.d.ts +0 -2
  19. package/lib/cms/api/api-client.js +106 -127
  20. package/lib/cms/api/api-keys.js +1 -2
  21. package/lib/cms/api/domains.js +1 -2
  22. package/lib/cms/commands/__tests__/push-status.test.js +251 -162
  23. package/lib/cms/commands/__tests__/push.test.js +120 -102
  24. package/lib/cms/commands/__tests__/utils.test.js +12 -21
  25. package/lib/cms/commands/push-status.d.ts +3 -2
  26. package/lib/cms/commands/push-status.js +94 -106
  27. package/lib/cms/commands/push.d.ts +3 -2
  28. package/lib/cms/commands/push.js +66 -75
  29. package/lib/cms/commands/utils.js +20 -34
  30. package/lib/commands/build-docs/index.d.ts +2 -2
  31. package/lib/commands/build-docs/index.js +8 -17
  32. package/lib/commands/build-docs/utils.js +26 -38
  33. package/lib/commands/bundle.d.ts +2 -2
  34. package/lib/commands/bundle.js +70 -94
  35. package/lib/commands/join.d.ts +2 -2
  36. package/lib/commands/join.js +377 -390
  37. package/lib/commands/lint.d.ts +2 -2
  38. package/lib/commands/lint.js +70 -78
  39. package/lib/commands/login.d.ts +3 -2
  40. package/lib/commands/login.js +9 -21
  41. package/lib/commands/preview-docs/index.d.ts +2 -2
  42. package/lib/commands/preview-docs/index.js +92 -106
  43. package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
  44. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
  45. package/lib/commands/preview-docs/preview-server/server.js +6 -6
  46. package/lib/commands/preview-project/index.d.ts +2 -1
  47. package/lib/commands/preview-project/index.js +5 -14
  48. package/lib/commands/push.d.ts +8 -11
  49. package/lib/commands/push.js +177 -195
  50. package/lib/commands/split/__tests__/index.test.js +31 -25
  51. package/lib/commands/split/index.d.ts +2 -1
  52. package/lib/commands/split/index.js +22 -35
  53. package/lib/commands/stats.d.ts +2 -2
  54. package/lib/commands/stats.js +34 -45
  55. package/lib/index.js +32 -46
  56. package/lib/types.d.ts +2 -2
  57. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
  58. package/lib/utils/fetch-with-timeout.js +7 -12
  59. package/lib/utils/getCommandNameFromArgs.js +2 -4
  60. package/lib/utils/js-utils.js +6 -7
  61. package/lib/utils/miscellaneous.d.ts +9 -5
  62. package/lib/utils/miscellaneous.js +150 -160
  63. package/lib/utils/update-version-notifier.js +4 -13
  64. package/lib/wrapper.d.ts +9 -2
  65. package/lib/wrapper.js +27 -16
  66. package/package.json +5 -3
  67. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  68. package/src/__tests__/commands/build-docs.test.ts +5 -4
  69. package/src/__tests__/commands/join.test.ts +51 -51
  70. package/src/__tests__/commands/push-region.test.ts +10 -8
  71. package/src/__tests__/commands/push.test.ts +127 -102
  72. package/src/__tests__/utils.test.ts +1 -0
  73. package/src/__tests__/wrapper.test.ts +24 -2
  74. package/src/cms/commands/__tests__/push-status.test.ts +70 -56
  75. package/src/cms/commands/__tests__/push.test.ts +30 -24
  76. package/src/cms/commands/push-status.ts +8 -7
  77. package/src/cms/commands/push.ts +19 -13
  78. package/src/commands/build-docs/index.ts +10 -5
  79. package/src/commands/bundle.ts +14 -6
  80. package/src/commands/join.ts +10 -6
  81. package/src/commands/lint.ts +20 -9
  82. package/src/commands/login.ts +4 -2
  83. package/src/commands/preview-docs/index.ts +6 -1
  84. package/src/commands/preview-project/index.ts +5 -4
  85. package/src/commands/push.ts +14 -16
  86. package/src/commands/split/__tests__/index.test.ts +17 -6
  87. package/src/commands/split/index.ts +6 -4
  88. package/src/commands/stats.ts +4 -2
  89. package/src/utils/miscellaneous.ts +55 -26
  90. package/src/wrapper.ts +37 -11
  91. package/tsconfig.tsbuildinfo +1 -1
@@ -1,27 +1,38 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.checkForDeprecatedOptions = exports.cleanRawInput = exports.cleanArgs = exports.sendTelemetry = exports.cleanColors = exports.checkIfRulesetExist = exports.sortTopLevelKeysForOas = exports.loadConfigAndHandleErrors = exports.isSubdir = exports.exitWithError = exports.printUnusedWarnings = exports.getOutputFileName = exports.printConfigLintTotals = exports.printLintTotals = exports.HandledError = exports.handleError = exports.pluralize = exports.getAndValidateFileExtension = exports.writeJson = exports.writeYaml = exports.writeToFileByExtension = exports.readYaml = exports.promptUser = exports.saveBundle = exports.dumpBundle = exports.CircularJSONNotSupportedError = exports.langToExt = exports.escapeLanguageName = exports.pathToFilename = exports.printExecutionTime = exports.getExecutionTime = exports.getFallbackApisOrExit = void 0;
24
- const fetch_with_timeout_1 = require("./fetch-with-timeout");
3
+ exports.HandledError = exports.CircularJSONNotSupportedError = void 0;
4
+ exports.getFallbackApisOrExit = getFallbackApisOrExit;
5
+ exports.getExecutionTime = getExecutionTime;
6
+ exports.printExecutionTime = printExecutionTime;
7
+ exports.pathToFilename = pathToFilename;
8
+ exports.escapeLanguageName = escapeLanguageName;
9
+ exports.langToExt = langToExt;
10
+ exports.dumpBundle = dumpBundle;
11
+ exports.saveBundle = saveBundle;
12
+ exports.promptUser = promptUser;
13
+ exports.readYaml = readYaml;
14
+ exports.writeToFileByExtension = writeToFileByExtension;
15
+ exports.writeYaml = writeYaml;
16
+ exports.writeJson = writeJson;
17
+ exports.getAndValidateFileExtension = getAndValidateFileExtension;
18
+ exports.pluralize = pluralize;
19
+ exports.handleError = handleError;
20
+ exports.printLintTotals = printLintTotals;
21
+ exports.printConfigLintTotals = printConfigLintTotals;
22
+ exports.getOutputFileName = getOutputFileName;
23
+ exports.printUnusedWarnings = printUnusedWarnings;
24
+ exports.exitWithError = exitWithError;
25
+ exports.isSubdir = isSubdir;
26
+ exports.loadConfigAndHandleErrors = loadConfigAndHandleErrors;
27
+ exports.sortTopLevelKeysForOas = sortTopLevelKeysForOas;
28
+ exports.checkIfRulesetExist = checkIfRulesetExist;
29
+ exports.cleanColors = cleanColors;
30
+ exports.sendTelemetry = sendTelemetry;
31
+ exports.cleanArgs = cleanArgs;
32
+ exports.cleanRawInput = cleanRawInput;
33
+ exports.checkForDeprecatedOptions = checkForDeprecatedOptions;
34
+ exports.notifyAboutIncompatibleConfigOptions = notifyAboutIncompatibleConfigOptions;
35
+ const pluralizeOne = require("pluralize");
25
36
  const path_1 = require("path");
26
37
  const colorette_1 = require("colorette");
27
38
  const perf_hooks_1 = require("perf_hooks");
@@ -32,29 +43,28 @@ const stream_1 = require("stream");
32
43
  const child_process_1 = require("child_process");
33
44
  const util_1 = require("util");
34
45
  const openapi_core_1 = require("@redocly/openapi-core");
35
- const types_1 = require("../types");
36
46
  const utils_1 = require("@redocly/openapi-core/lib/utils");
47
+ const config_1 = require("@redocly/openapi-core/lib/config");
48
+ const reference_docs_config_schema_1 = require("@redocly/config/lib/reference-docs-config-schema");
49
+ const types_1 = require("../types");
37
50
  const update_version_notifier_1 = require("./update-version-notifier");
38
51
  const push_1 = require("../commands/push");
39
- const config_1 = require("@redocly/openapi-core/lib/config");
40
- function getFallbackApisOrExit(argsApis, config) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const { apis } = config;
43
- const shouldFallbackToAllDefinitions = !isNotEmptyArray(argsApis) && apis && Object.keys(apis).length > 0;
44
- const res = shouldFallbackToAllDefinitions
45
- ? fallbackToAllDefinitions(apis, config)
46
- : yield expandGlobsInEntrypoints(argsApis, config);
47
- const filteredInvalidEntrypoints = res.filter(({ path }) => !isApiPathValid(path));
48
- if (isNotEmptyArray(filteredInvalidEntrypoints)) {
49
- for (const { path } of filteredInvalidEntrypoints) {
50
- process.stderr.write((0, colorette_1.yellow)(`\n${(0, path_1.relative)(process.cwd(), path)} ${(0, colorette_1.red)(`does not exist or is invalid.\n\n`)}`));
51
- }
52
- exitWithError('Please provide a valid path.');
52
+ const fetch_with_timeout_1 = require("./fetch-with-timeout");
53
+ async function getFallbackApisOrExit(argsApis, config) {
54
+ const { apis } = config;
55
+ const shouldFallbackToAllDefinitions = !isNotEmptyArray(argsApis) && apis && Object.keys(apis).length > 0;
56
+ const res = shouldFallbackToAllDefinitions
57
+ ? fallbackToAllDefinitions(apis, config)
58
+ : await expandGlobsInEntrypoints(argsApis, config);
59
+ const filteredInvalidEntrypoints = res.filter(({ path }) => !isApiPathValid(path));
60
+ if (isNotEmptyArray(filteredInvalidEntrypoints)) {
61
+ for (const { path } of filteredInvalidEntrypoints) {
62
+ process.stderr.write((0, colorette_1.yellow)(`\n${(0, path_1.relative)(process.cwd(), path)} ${(0, colorette_1.red)(`does not exist or is invalid.\n\n`)}`));
53
63
  }
54
- return res;
55
- });
64
+ exitWithError('Please provide a valid path.');
65
+ }
66
+ return res;
56
67
  }
57
- exports.getFallbackApisOrExit = getFallbackApisOrExit;
58
68
  function getConfigDirectory(config) {
59
69
  return config.configFile ? (0, path_1.dirname)(config.configFile) : process.cwd();
60
70
  }
@@ -75,37 +85,32 @@ function fallbackToAllDefinitions(apis, config) {
75
85
  }));
76
86
  }
77
87
  function getAliasOrPath(config, aliasOrPath) {
78
- var _a, _b, _c;
79
88
  return config.apis[aliasOrPath]
80
- ? { path: (_a = config.apis[aliasOrPath]) === null || _a === void 0 ? void 0 : _a.root, alias: aliasOrPath }
89
+ ? { path: config.apis[aliasOrPath]?.root, alias: aliasOrPath }
81
90
  : {
82
91
  path: aliasOrPath,
83
92
  // find alias by path, take the first match
84
- alias: (_c = (_b = Object.entries(config.apis).find(([_alias, api]) => {
93
+ alias: Object.entries(config.apis).find(([_alias, api]) => {
85
94
  return (0, path_1.resolve)(api.root) === (0, path_1.resolve)(aliasOrPath);
86
- })) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : undefined,
95
+ })?.[0] ?? undefined,
87
96
  };
88
97
  }
89
- function expandGlobsInEntrypoints(args, config) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- return (yield Promise.all(args.map((aliasOrPath) => __awaiter(this, void 0, void 0, function* () {
92
- return glob.hasMagic(aliasOrPath) && !(0, openapi_core_1.isAbsoluteUrl)(aliasOrPath)
93
- ? (yield (0, util_1.promisify)(glob)(aliasOrPath)).map((g) => getAliasOrPath(config, g))
94
- : getAliasOrPath(config, aliasOrPath);
95
- })))).flat();
96
- });
98
+ async function expandGlobsInEntrypoints(args, config) {
99
+ return (await Promise.all(args.map(async (aliasOrPath) => {
100
+ return glob.hasMagic(aliasOrPath) && !(0, openapi_core_1.isAbsoluteUrl)(aliasOrPath)
101
+ ? (await (0, util_1.promisify)(glob)(aliasOrPath)).map((g) => getAliasOrPath(config, g))
102
+ : getAliasOrPath(config, aliasOrPath);
103
+ }))).flat();
97
104
  }
98
105
  function getExecutionTime(startedAt) {
99
106
  return process.env.NODE_ENV === 'test'
100
107
  ? '<test>ms'
101
108
  : `${Math.ceil(perf_hooks_1.performance.now() - startedAt)}ms`;
102
109
  }
103
- exports.getExecutionTime = getExecutionTime;
104
110
  function printExecutionTime(commandName, startedAt, api) {
105
111
  const elapsed = getExecutionTime(startedAt);
106
112
  process.stderr.write((0, colorette_1.gray)(`\n${api}: ${commandName} processed in ${elapsed}\n\n`));
107
113
  }
108
- exports.printExecutionTime = printExecutionTime;
109
114
  function pathToFilename(path, pathSeparator) {
110
115
  return path
111
116
  .replace(/~1/g, '/')
@@ -113,11 +118,9 @@ function pathToFilename(path, pathSeparator) {
113
118
  .replace(/^\//, '')
114
119
  .replace(/\//g, pathSeparator);
115
120
  }
116
- exports.pathToFilename = pathToFilename;
117
121
  function escapeLanguageName(lang) {
118
122
  return lang.replace(/#/g, '_sharp').replace(/\//, '_').replace(/\s/g, '');
119
123
  }
120
- exports.escapeLanguageName = escapeLanguageName;
121
124
  function langToExt(lang) {
122
125
  const langObj = {
123
126
  php: '.php',
@@ -149,7 +152,6 @@ function langToExt(lang) {
149
152
  };
150
153
  return langObj[lang.toLowerCase()];
151
154
  }
152
- exports.langToExt = langToExt;
153
155
  class CircularJSONNotSupportedError extends Error {
154
156
  constructor(originalError) {
155
157
  super(originalError.message);
@@ -178,46 +180,40 @@ function dumpBundle(obj, format, dereference) {
178
180
  });
179
181
  }
180
182
  }
181
- exports.dumpBundle = dumpBundle;
182
183
  function saveBundle(filename, output) {
183
184
  fs.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
184
185
  fs.writeFileSync(filename, output);
185
186
  }
186
- exports.saveBundle = saveBundle;
187
- function promptUser(query, hideUserInput = false) {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- return new Promise((resolve) => {
190
- let output = process.stdout;
191
- let isOutputMuted = false;
192
- if (hideUserInput) {
193
- output = new stream_1.Writable({
194
- write: (chunk, encoding, callback) => {
195
- if (!isOutputMuted) {
196
- process.stdout.write(chunk, encoding);
197
- }
198
- callback();
199
- },
200
- });
201
- }
202
- const rl = readline.createInterface({
203
- input: process.stdin,
204
- output,
205
- terminal: true,
206
- historySize: hideUserInput ? 0 : 30,
207
- });
208
- rl.question(`${query}:\n\n `, (answer) => {
209
- rl.close();
210
- resolve(answer);
187
+ async function promptUser(query, hideUserInput = false) {
188
+ return new Promise((resolve) => {
189
+ let output = process.stdout;
190
+ let isOutputMuted = false;
191
+ if (hideUserInput) {
192
+ output = new stream_1.Writable({
193
+ write: (chunk, encoding, callback) => {
194
+ if (!isOutputMuted) {
195
+ process.stdout.write(chunk, encoding);
196
+ }
197
+ callback();
198
+ },
211
199
  });
212
- isOutputMuted = hideUserInput;
200
+ }
201
+ const rl = readline.createInterface({
202
+ input: process.stdin,
203
+ output,
204
+ terminal: true,
205
+ historySize: hideUserInput ? 0 : 30,
213
206
  });
207
+ rl.question(`${query}:\n\n `, (answer) => {
208
+ rl.close();
209
+ resolve(answer);
210
+ });
211
+ isOutputMuted = hideUserInput;
214
212
  });
215
213
  }
216
- exports.promptUser = promptUser;
217
214
  function readYaml(filename) {
218
215
  return (0, openapi_core_1.parseYaml)(fs.readFileSync(filename, 'utf-8'), { filename });
219
216
  }
220
- exports.readYaml = readYaml;
221
217
  function writeToFileByExtension(data, filePath, noRefs) {
222
218
  const ext = getAndValidateFileExtension(filePath);
223
219
  if (ext === 'json') {
@@ -226,7 +222,6 @@ function writeToFileByExtension(data, filePath, noRefs) {
226
222
  }
227
223
  writeYaml(data, filePath, noRefs);
228
224
  }
229
- exports.writeToFileByExtension = writeToFileByExtension;
230
225
  function writeYaml(data, filename, noRefs = false) {
231
226
  const content = (0, openapi_core_1.stringifyYaml)(data, { noRefs });
232
227
  if (process.env.NODE_ENV === 'test') {
@@ -236,7 +231,6 @@ function writeYaml(data, filename, noRefs = false) {
236
231
  fs.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
237
232
  fs.writeFileSync(filename, content);
238
233
  }
239
- exports.writeYaml = writeYaml;
240
234
  function writeJson(data, filename) {
241
235
  const content = JSON.stringify(data, null, 2);
242
236
  if (process.env.NODE_ENV === 'test') {
@@ -246,7 +240,6 @@ function writeJson(data, filename) {
246
240
  fs.mkdirSync((0, path_1.dirname)(filename), { recursive: true });
247
241
  fs.writeFileSync(filename, content);
248
242
  }
249
- exports.writeJson = writeJson;
250
243
  function getAndValidateFileExtension(fileName) {
251
244
  const ext = fileName.split('.').pop();
252
245
  if (['yaml', 'yml', 'json'].includes(ext)) {
@@ -255,17 +248,13 @@ function getAndValidateFileExtension(fileName) {
255
248
  process.stderr.write((0, colorette_1.yellow)(`Unsupported file extension: ${ext}. Using yaml.\n`));
256
249
  return 'yaml';
257
250
  }
258
- exports.getAndValidateFileExtension = getAndValidateFileExtension;
259
- function pluralize(label, num) {
260
- if (label.endsWith('is')) {
261
- [label] = label.split(' ');
262
- return num === 1 ? `${label} is` : `${label}s are`;
263
- }
264
- return num === 1 ? `${label}` : `${label}s`;
251
+ function pluralize(sentence, count, inclusive) {
252
+ return sentence
253
+ .split(' ')
254
+ .map((word) => pluralizeOne(word, count, inclusive))
255
+ .join(' ');
265
256
  }
266
- exports.pluralize = pluralize;
267
257
  function handleError(e, ref) {
268
- var _a, _b;
269
258
  switch (e.constructor) {
270
259
  case HandledError: {
271
260
  throw e;
@@ -279,7 +268,7 @@ function handleError(e, ref) {
279
268
  `Try to use ${(0, colorette_1.blue)('yaml')} output or remove ${(0, colorette_1.blue)('--dereferenced')}.`);
280
269
  }
281
270
  case SyntaxError:
282
- return exitWithError(`Syntax error: ${e.message} ${(_b = (_a = e.stack) === null || _a === void 0 ? void 0 : _a.split('\n\n')) === null || _b === void 0 ? void 0 : _b[0]}`);
271
+ return exitWithError(`Syntax error: ${e.message} ${e.stack?.split('\n\n')?.[0]}`);
283
272
  case config_1.ConfigValidationError:
284
273
  return exitWithError(e.message);
285
274
  default: {
@@ -287,7 +276,6 @@ function handleError(e, ref) {
287
276
  }
288
277
  }
289
278
  }
290
- exports.handleError = handleError;
291
279
  class HandledError extends Error {
292
280
  }
293
281
  exports.HandledError = HandledError;
@@ -312,7 +300,6 @@ function printLintTotals(totals, definitionsCount) {
312
300
  }
313
301
  process.stderr.write('\n');
314
302
  }
315
- exports.printLintTotals = printLintTotals;
316
303
  function printConfigLintTotals(totals, command) {
317
304
  if (totals.errors > 0) {
318
305
  process.stderr.write((0, colorette_1.red)(`❌ Your config has ${totals.errors} ${pluralize('error', totals.errors)}.`));
@@ -324,7 +311,6 @@ function printConfigLintTotals(totals, command) {
324
311
  process.stderr.write((0, colorette_1.green)('✅ Your config is valid.\n'));
325
312
  }
326
313
  }
327
- exports.printConfigLintTotals = printConfigLintTotals;
328
314
  function getOutputFileName(entrypoint, entries, output, ext) {
329
315
  if (!output) {
330
316
  return { outputFile: 'stdout', ext: ext || 'yaml' };
@@ -349,7 +335,6 @@ function getOutputFileName(entrypoint, entries, output, ext) {
349
335
  }
350
336
  return { outputFile, ext };
351
337
  }
352
- exports.getOutputFileName = getOutputFileName;
353
338
  function printUnusedWarnings(config) {
354
339
  const { preprocessors, rules, decorators } = config.getUnusedRules();
355
340
  if (rules.length) {
@@ -365,12 +350,10 @@ function printUnusedWarnings(config) {
365
350
  process.stderr.write(`Check the spelling and verify the added plugin prefix.\n`);
366
351
  }
367
352
  }
368
- exports.printUnusedWarnings = printUnusedWarnings;
369
353
  function exitWithError(message) {
370
354
  process.stderr.write((0, colorette_1.red)(message) + '\n\n');
371
355
  throw new HandledError(message);
372
356
  }
373
- exports.exitWithError = exitWithError;
374
357
  /**
375
358
  * Checks if dir is subdir of parent
376
359
  */
@@ -378,25 +361,20 @@ function isSubdir(parent, dir) {
378
361
  const relativePath = (0, path_1.relative)(parent, dir);
379
362
  return !!relativePath && !/^..($|\/)/.test(relativePath) && !(0, path_1.isAbsolute)(relativePath);
380
363
  }
381
- exports.isSubdir = isSubdir;
382
- function loadConfigAndHandleErrors(options = {}) {
383
- return __awaiter(this, void 0, void 0, function* () {
384
- try {
385
- return yield (0, openapi_core_1.loadConfig)(options);
386
- }
387
- catch (e) {
388
- handleError(e, '');
389
- }
390
- });
364
+ async function loadConfigAndHandleErrors(options = {}) {
365
+ try {
366
+ return await (0, openapi_core_1.loadConfig)(options);
367
+ }
368
+ catch (e) {
369
+ handleError(e, '');
370
+ }
391
371
  }
392
- exports.loadConfigAndHandleErrors = loadConfigAndHandleErrors;
393
372
  function sortTopLevelKeysForOas(document) {
394
373
  if ('swagger' in document) {
395
374
  return sortOas2Keys(document);
396
375
  }
397
376
  return sortOas3Keys(document);
398
377
  }
399
- exports.sortTopLevelKeysForOas = sortTopLevelKeysForOas;
400
378
  function sortOas2Keys(document) {
401
379
  const orderedKeys = [
402
380
  'swagger',
@@ -448,56 +426,61 @@ function sortOas3Keys(document) {
448
426
  return Object.assign(result, document);
449
427
  }
450
428
  function checkIfRulesetExist(rules) {
451
- const ruleset = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rules.oas2), rules.oas3_0), rules.oas3_1), rules.async2), rules.arazzo);
429
+ const ruleset = {
430
+ ...rules.oas2,
431
+ ...rules.oas3_0,
432
+ ...rules.oas3_1,
433
+ ...rules.async2,
434
+ ...rules.async3,
435
+ ...rules.arazzo,
436
+ };
452
437
  if ((0, utils_1.isEmptyObject)(ruleset)) {
453
438
  exitWithError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
454
439
  }
455
440
  }
456
- exports.checkIfRulesetExist = checkIfRulesetExist;
457
441
  function cleanColors(input) {
458
442
  // eslint-disable-next-line no-control-regex
459
443
  return input.replace(/\x1b\[\d+m/g, '');
460
444
  }
461
- exports.cleanColors = cleanColors;
462
- function sendTelemetry(argv, exit_code, has_config) {
463
- return __awaiter(this, void 0, void 0, function* () {
464
- try {
465
- if (!argv) {
466
- return;
467
- }
468
- const { _: [command], $0: _ } = argv, args = __rest(argv, ["_", "$0"]);
469
- const event_time = new Date().toISOString();
470
- const redoclyClient = new openapi_core_1.RedoclyClient();
471
- const logged_in = redoclyClient.hasTokens();
472
- const data = {
473
- event: 'cli_command',
474
- event_time,
475
- logged_in,
476
- command,
477
- arguments: cleanArgs(args),
478
- node_version: process.version,
479
- npm_version: (0, child_process_1.execSync)('npm -v').toString().replace('\n', ''),
480
- version: update_version_notifier_1.version,
481
- exit_code,
482
- environment: process.env.REDOCLY_ENVIRONMENT,
483
- environment_ci: process.env.CI,
484
- raw_input: cleanRawInput(process.argv.slice(2)),
485
- has_config,
486
- };
487
- yield (0, fetch_with_timeout_1.default)(`https://api.redocly.com/registry/telemetry/cli`, {
488
- method: 'POST',
489
- headers: {
490
- 'content-type': 'application/json',
491
- },
492
- body: JSON.stringify(data),
493
- });
494
- }
495
- catch (err) {
496
- // Do nothing.
445
+ async function sendTelemetry(argv, exit_code, has_config, spec_version, spec_keyword, spec_full_version) {
446
+ try {
447
+ if (!argv) {
448
+ return;
497
449
  }
498
- });
450
+ const { _: [command], $0: _, ...args } = argv;
451
+ const event_time = new Date().toISOString();
452
+ const redoclyClient = new openapi_core_1.RedoclyClient();
453
+ const logged_in = redoclyClient.hasTokens();
454
+ const data = {
455
+ event: 'cli_command',
456
+ event_time,
457
+ logged_in,
458
+ command,
459
+ arguments: cleanArgs(args),
460
+ node_version: process.version,
461
+ npm_version: (0, child_process_1.execSync)('npm -v').toString().replace('\n', ''),
462
+ version: update_version_notifier_1.version,
463
+ exit_code,
464
+ environment: process.env.REDOCLY_ENVIRONMENT,
465
+ environment_ci: process.env.CI,
466
+ raw_input: cleanRawInput(process.argv.slice(2)),
467
+ has_config,
468
+ spec_version,
469
+ spec_keyword,
470
+ spec_full_version,
471
+ };
472
+ await (0, fetch_with_timeout_1.default)(`https://api.redocly.com/registry/telemetry/cli`, {
473
+ method: 'POST',
474
+ headers: {
475
+ 'content-type': 'application/json',
476
+ },
477
+ body: JSON.stringify(data),
478
+ });
479
+ }
480
+ catch (err) {
481
+ // Do nothing.
482
+ }
499
483
  }
500
- exports.sendTelemetry = sendTelemetry;
501
484
  function isFile(value) {
502
485
  return fs.existsSync(value) && fs.statSync(value).isFile();
503
486
  }
@@ -541,11 +524,9 @@ function cleanArgs(args) {
541
524
  }
542
525
  return result;
543
526
  }
544
- exports.cleanArgs = cleanArgs;
545
527
  function cleanRawInput(argv) {
546
528
  return argv.map((entry) => entry.split('=').map(cleanString).join('=')).join(' ');
547
529
  }
548
- exports.cleanRawInput = cleanRawInput;
549
530
  function checkForDeprecatedOptions(argv, deprecatedOptions) {
550
531
  for (const option of deprecatedOptions) {
551
532
  if (argv[option]) {
@@ -553,4 +534,13 @@ function checkForDeprecatedOptions(argv, deprecatedOptions) {
553
534
  }
554
535
  }
555
536
  }
556
- exports.checkForDeprecatedOptions = checkForDeprecatedOptions;
537
+ function notifyAboutIncompatibleConfigOptions(themeOpenapiOptions) {
538
+ if ((0, utils_1.isPlainObject)(themeOpenapiOptions)) {
539
+ const propertiesSet = Object.keys(themeOpenapiOptions);
540
+ const deprecatedSet = Object.keys(reference_docs_config_schema_1.deprecatedRefDocsSchema.properties);
541
+ const intersection = propertiesSet.filter((prop) => deprecatedSet.includes(prop));
542
+ if (intersection.length > 0) {
543
+ process.stderr.write((0, colorette_1.yellow)(`\n${pluralize('Property', intersection.length)} ${(0, colorette_1.gray)(intersection.map((prop) => `'${prop}'`).join(', '))} ${pluralize('is', intersection.length)} only used in API Reference Docs and Redoc version 2.x or earlier.\n\n`));
544
+ }
545
+ }
546
+ }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var _a;
12
3
  Object.defineProperty(exports, "__esModule", { value: true });
13
4
  exports.cacheLatestVersion = exports.notifyUpdateCliVersion = exports.name = exports.version = void 0;
@@ -39,14 +30,14 @@ const notifyUpdateCliVersion = () => {
39
30
  };
40
31
  exports.notifyUpdateCliVersion = notifyUpdateCliVersion;
41
32
  const isNewVersionAvailable = (current, latest) => (0, semver_1.compare)(current, latest) < 0;
42
- const getLatestVersion = (packageName) => __awaiter(void 0, void 0, void 0, function* () {
33
+ const getLatestVersion = async (packageName) => {
43
34
  const latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
44
- const response = yield (0, fetch_with_timeout_1.default)(latestUrl);
35
+ const response = await (0, fetch_with_timeout_1.default)(latestUrl);
45
36
  if (!response)
46
37
  return;
47
- const info = yield response.json();
38
+ const info = await response.json();
48
39
  return info.version;
49
- });
40
+ };
50
41
  const cacheLatestVersion = () => {
51
42
  if (!isNeedToBeCached() || SHOULD_NOT_NOTIFY) {
52
43
  return;
package/lib/wrapper.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { Config } from '@redocly/openapi-core';
2
1
  import type { Arguments } from 'yargs';
2
+ import type { Config } from '@redocly/openapi-core';
3
+ import type { CollectFn } from '@redocly/openapi-core/lib/utils';
3
4
  import type { CommandOptions } from './types';
4
- export declare function commandWrapper<T extends CommandOptions>(commandHandler?: (argv: T, config: Config, version: string) => Promise<unknown>): (argv: Arguments<T>) => Promise<void>;
5
+ export type CommandArgs<T extends CommandOptions> = {
6
+ argv: T;
7
+ config: Config;
8
+ version: string;
9
+ collectSpecData?: CollectFn;
10
+ };
11
+ export declare function commandWrapper<T extends CommandOptions>(commandHandler?: (wrapperArgs: CommandArgs<T>) => Promise<unknown>): (argv: Arguments<T>) => Promise<void>;
package/lib/wrapper.js CHANGED
@@ -1,29 +1,41 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.commandWrapper = void 0;
3
+ exports.commandWrapper = commandWrapper;
13
4
  const openapi_core_1 = require("@redocly/openapi-core");
5
+ const utils_1 = require("@redocly/openapi-core/lib/utils");
14
6
  const update_version_notifier_1 = require("./utils/update-version-notifier");
15
7
  const miscellaneous_1 = require("./utils/miscellaneous");
16
8
  const lint_1 = require("./commands/lint");
17
9
  function commandWrapper(commandHandler) {
18
- return (argv) => __awaiter(this, void 0, void 0, function* () {
10
+ return async (argv) => {
19
11
  let code = 2;
20
12
  let hasConfig;
21
13
  let telemetry;
14
+ let specVersion;
15
+ let specKeyword;
16
+ let specFullVersion;
17
+ const collectSpecData = (document) => {
18
+ specVersion = (0, openapi_core_1.detectSpec)(document);
19
+ if (!(0, utils_1.isPlainObject)(document))
20
+ return;
21
+ specKeyword = document?.openapi
22
+ ? 'openapi'
23
+ : document?.swagger
24
+ ? 'swagger'
25
+ : document?.asyncapi
26
+ ? 'asyncapi'
27
+ : document?.arazzo
28
+ ? 'arazzo'
29
+ : undefined;
30
+ if (specKeyword) {
31
+ specFullVersion = document[specKeyword];
32
+ }
33
+ };
22
34
  try {
23
35
  if (argv.config && !(0, openapi_core_1.doesYamlFileExist)(argv.config)) {
24
36
  (0, miscellaneous_1.exitWithError)('Please provide a valid path to the configuration file.');
25
37
  }
26
- const config = (yield (0, miscellaneous_1.loadConfigAndHandleErrors)({
38
+ const config = (await (0, miscellaneous_1.loadConfigAndHandleErrors)({
27
39
  configPath: argv.config,
28
40
  customExtends: argv.extends,
29
41
  region: argv.region,
@@ -34,7 +46,7 @@ function commandWrapper(commandHandler) {
34
46
  hasConfig = !config.styleguide.recommendedFallback;
35
47
  code = 1;
36
48
  if (typeof commandHandler === 'function') {
37
- yield commandHandler(argv, config, update_version_notifier_1.version);
49
+ await commandHandler({ argv, config, version: update_version_notifier_1.version, collectSpecData });
38
50
  }
39
51
  code = 0;
40
52
  }
@@ -43,12 +55,11 @@ function commandWrapper(commandHandler) {
43
55
  }
44
56
  finally {
45
57
  if (process.env.REDOCLY_TELEMETRY !== 'off' && telemetry !== 'off') {
46
- yield (0, miscellaneous_1.sendTelemetry)(argv, code, hasConfig);
58
+ await (0, miscellaneous_1.sendTelemetry)(argv, code, hasConfig, specVersion, specKeyword, specFullVersion);
47
59
  }
48
60
  process.once('beforeExit', () => {
49
61
  process.exit(code);
50
62
  });
51
63
  }
52
- });
64
+ };
53
65
  }
54
- exports.commandWrapper = commandWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/cli",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -36,7 +36,7 @@
36
36
  "Roman Hotsiy <roman@redoc.ly> (https://redoc.ly/)"
37
37
  ],
38
38
  "dependencies": {
39
- "@redocly/openapi-core": "1.18.0",
39
+ "@redocly/openapi-core": "1.19.0",
40
40
  "abort-controller": "^3.0.0",
41
41
  "chokidar": "^3.5.1",
42
42
  "colorette": "^1.2.0",
@@ -47,6 +47,7 @@
47
47
  "handlebars": "^4.7.6",
48
48
  "mobx": "^6.0.4",
49
49
  "node-fetch": "^2.6.1",
50
+ "pluralize": "^8.0.0",
50
51
  "react": "^17.0.0 || ^18.2.0",
51
52
  "react-dom": "^17.0.0 || ^18.2.0",
52
53
  "redoc": "~2.1.5",
@@ -58,10 +59,11 @@
58
59
  "devDependencies": {
59
60
  "@types/configstore": "^5.0.1",
60
61
  "@types/glob": "^8.1.0",
62
+ "@types/pluralize": "^0.0.29",
61
63
  "@types/react": "^17.0.0 || ^18.2.21",
62
64
  "@types/react-dom": "^17.0.0 || ^18.2.7",
63
65
  "@types/semver": "^7.5.0",
64
66
  "@types/yargs": "17.0.32",
65
- "typescript": "^5.2.2"
67
+ "typescript": "5.5.3"
66
68
  }
67
69
  }