@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,38 +1,30 @@
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.iteratePathItems = exports.crawl = exports.startsWithComponents = exports.handleSplit = void 0;
3
+ exports.handleSplit = handleSplit;
4
+ exports.startsWithComponents = startsWithComponents;
5
+ exports.crawl = crawl;
6
+ exports.iteratePathItems = iteratePathItems;
13
7
  const colorette_1 = require("colorette");
14
8
  const fs = require("fs");
15
9
  const openapi_core_1 = require("@redocly/openapi-core");
10
+ const utils_1 = require("@redocly/openapi-core/lib/utils");
16
11
  const path = require("path");
17
12
  const perf_hooks_1 = require("perf_hooks");
18
- const isEqual = require('lodash.isequal');
19
13
  const miscellaneous_1 = require("../../utils/miscellaneous");
20
14
  const js_utils_1 = require("../../utils/js-utils");
21
15
  const types_1 = require("./types");
22
- function handleSplit(argv) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const startedAt = perf_hooks_1.performance.now();
25
- const { api, outDir, separator } = argv;
26
- validateDefinitionFileName(api);
27
- const ext = (0, miscellaneous_1.getAndValidateFileExtension)(api);
28
- const openapi = (0, miscellaneous_1.readYaml)(api);
29
- splitDefinition(openapi, outDir, separator, ext);
30
- process.stderr.write(`🪓 Document: ${(0, colorette_1.blue)(api)} ${(0, colorette_1.green)('is successfully split')}
16
+ async function handleSplit({ argv, collectSpecData }) {
17
+ const startedAt = perf_hooks_1.performance.now();
18
+ const { api, outDir, separator } = argv;
19
+ validateDefinitionFileName(api);
20
+ const ext = (0, miscellaneous_1.getAndValidateFileExtension)(api);
21
+ const openapi = (0, miscellaneous_1.readYaml)(api);
22
+ collectSpecData?.(openapi);
23
+ splitDefinition(openapi, outDir, separator, ext);
24
+ process.stderr.write(`🪓 Document: ${(0, colorette_1.blue)(api)} ${(0, colorette_1.green)('is successfully split')}
31
25
  and all related files are saved to the directory: ${(0, colorette_1.blue)(outDir)} \n`);
32
- (0, miscellaneous_1.printExecutionTime)('split', startedAt, api);
33
- });
26
+ (0, miscellaneous_1.printExecutionTime)('split', startedAt, api);
34
27
  }
35
- exports.handleSplit = handleSplit;
36
28
  function splitDefinition(openapi, openapiDir, pathSeparator, ext) {
37
29
  fs.mkdirSync(openapiDir, { recursive: true });
38
30
  const componentsFiles = {};
@@ -47,7 +39,6 @@ function splitDefinition(openapi, openapiDir, pathSeparator, ext) {
47
39
  function startsWithComponents(node) {
48
40
  return node.startsWith(`#/${types_1.COMPONENTS}/`);
49
41
  }
50
- exports.startsWithComponents = startsWithComponents;
51
42
  function isSupportedExtension(filename) {
52
43
  return filename.endsWith('.yaml') || filename.endsWith('.yml') || filename.endsWith('.json');
53
44
  }
@@ -98,7 +89,6 @@ function crawl(object, visitor) {
98
89
  crawl(object[key], visitor);
99
90
  }
100
91
  }
101
- exports.crawl = crawl;
102
92
  function replace$Refs(obj, relativeFrom, componentFiles = {}) {
103
93
  crawl(obj, (node) => {
104
94
  if (node.$ref && typeof node.$ref === 'string' && startsWithComponents(node.$ref)) {
@@ -161,7 +151,7 @@ function findComponentTypes(components) {
161
151
  return types_1.OPENAPI3_COMPONENT_NAMES.filter((item) => isNotSecurityComponentType(item) && Object.keys(components).includes(item));
162
152
  }
163
153
  function doesFileDiffer(filename, componentData) {
164
- return fs.existsSync(filename) && !isEqual((0, miscellaneous_1.readYaml)(filename), componentData);
154
+ return fs.existsSync(filename) && !(0, utils_1.dequal)((0, miscellaneous_1.readYaml)(filename), componentData);
165
155
  }
166
156
  function removeEmptyComponents(openapi, componentType) {
167
157
  if (openapi.components && (0, js_utils_1.isEmptyObject)(openapi.components[componentType])) {
@@ -183,10 +173,9 @@ function getFileNamePath(componentDirPath, componentName, ext) {
183
173
  return path.join(componentDirPath, componentName) + `.${ext}`;
184
174
  }
185
175
  function gatherComponentsFiles(components, componentsFiles, componentType, componentName, filename) {
186
- var _a, _b;
187
176
  let inherits = [];
188
177
  if (componentType === types_1.OPENAPI3_COMPONENT.Schemas) {
189
- inherits = (((_b = (_a = components === null || components === void 0 ? void 0 : components[componentType]) === null || _a === void 0 ? void 0 : _a[componentName]) === null || _b === void 0 ? void 0 : _b.allOf) || [])
178
+ inherits = (components?.[componentType]?.[componentName]?.allOf || [])
190
179
  .map(({ $ref }) => $ref)
191
180
  .filter(openapi_core_1.isTruthy);
192
181
  }
@@ -204,7 +193,7 @@ function iteratePathItems(pathItems, openapiDir, outDir, componentsFiles, pathSe
204
193
  continue;
205
194
  for (const method of types_1.OPENAPI3_METHOD_NAMES) {
206
195
  const methodData = pathData[method];
207
- const methodDataXCode = (methodData === null || methodData === void 0 ? void 0 : methodData['x-code-samples']) || (methodData === null || methodData === void 0 ? void 0 : methodData['x-codeSamples']);
196
+ const methodDataXCode = methodData?.['x-code-samples'] || methodData?.['x-codeSamples'];
208
197
  if (!methodDataXCode || !Array.isArray(methodDataXCode)) {
209
198
  continue;
210
199
  }
@@ -228,7 +217,6 @@ function iteratePathItems(pathItems, openapiDir, outDir, componentsFiles, pathSe
228
217
  traverseDirectoryDeep(outDir, traverseDirectoryDeepCallback, componentsFiles);
229
218
  }
230
219
  }
231
- exports.iteratePathItems = iteratePathItems;
232
220
  function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
233
221
  const { components } = openapi;
234
222
  if (components) {
@@ -240,19 +228,18 @@ function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
240
228
  // eslint-disable-next-line no-inner-declarations
241
229
  function iterateAndGatherComponentsFiles(componentType) {
242
230
  const componentDirPath = path.join(componentsDir, componentType);
243
- for (const componentName of Object.keys((components === null || components === void 0 ? void 0 : components[componentType]) || {})) {
231
+ for (const componentName of Object.keys(components?.[componentType] || {})) {
244
232
  const filename = getFileNamePath(componentDirPath, componentName, ext);
245
233
  gatherComponentsFiles(components, componentsFiles, componentType, componentName, filename);
246
234
  }
247
235
  }
248
236
  // eslint-disable-next-line no-inner-declarations
249
237
  function iterateComponentTypes(componentType) {
250
- var _a, _b, _c;
251
238
  const componentDirPath = path.join(componentsDir, componentType);
252
239
  createComponentDir(componentDirPath, componentType);
253
- for (const componentName of Object.keys((components === null || components === void 0 ? void 0 : components[componentType]) || {})) {
240
+ for (const componentName of Object.keys(components?.[componentType] || {})) {
254
241
  const filename = getFileNamePath(componentDirPath, componentName, ext);
255
- const componentData = (_a = components === null || components === void 0 ? void 0 : components[componentType]) === null || _a === void 0 ? void 0 : _a[componentName];
242
+ const componentData = components?.[componentType]?.[componentName];
256
243
  replace$Refs(componentData, path.dirname(filename), componentsFiles);
257
244
  implicitlyReferenceDiscriminator(componentData, extractFileNameFromPath(filename), filename, componentsFiles.schemas || {});
258
245
  if (doesFileDiffer(filename, componentData)) {
@@ -263,7 +250,7 @@ function iterateComponents(openapi, openapiDir, componentsFiles, ext) {
263
250
  }
264
251
  if (isNotSecurityComponentType(componentType)) {
265
252
  // security schemas must referenced from components
266
- (_c = (_b = openapi.components) === null || _b === void 0 ? void 0 : _b[componentType]) === null || _c === void 0 ? true : delete _c[componentName];
253
+ delete openapi.components?.[componentType]?.[componentName];
267
254
  }
268
255
  }
269
256
  removeEmptyComponents(openapi, componentType);
@@ -1,8 +1,8 @@
1
- import { Config } from '@redocly/openapi-core';
2
1
  import type { OutputFormat } from '@redocly/openapi-core';
2
+ import type { CommandArgs } from '../wrapper';
3
3
  export type StatsOptions = {
4
4
  api?: string;
5
5
  format: OutputFormat;
6
6
  config?: string;
7
7
  };
8
- export declare function handleStats(argv: StatsOptions, config: Config): Promise<void>;
8
+ export declare function handleStats({ argv, config, collectSpecData }: CommandArgs<StatsOptions>): Promise<void>;
@@ -1,15 +1,6 @@
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.handleStats = void 0;
3
+ exports.handleStats = handleStats;
13
4
  const perf_hooks_1 = require("perf_hooks");
14
5
  const colors = require("colorette");
15
6
  const openapi_core_1 = require("@redocly/openapi-core");
@@ -68,40 +59,38 @@ function printStats(statsAccumulator, api, startedAt, format) {
68
59
  break;
69
60
  }
70
61
  }
71
- function handleStats(argv, config) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const [{ path }] = yield (0, miscellaneous_1.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
74
- const externalRefResolver = new openapi_core_1.BaseResolver(config.resolve);
75
- const { bundle: document } = yield (0, openapi_core_1.bundle)({ config, ref: path });
76
- const lintConfig = config.styleguide;
77
- const specVersion = (0, openapi_core_1.detectSpec)(document.parsed);
78
- const types = (0, openapi_core_1.normalizeTypes)(lintConfig.extendTypes((0, openapi_core_1.getTypes)(specVersion), specVersion), lintConfig);
79
- const startedAt = perf_hooks_1.performance.now();
80
- const ctx = {
81
- problems: [],
82
- oasVersion: specVersion,
83
- visitorsData: {},
84
- };
85
- const resolvedRefMap = yield (0, openapi_core_1.resolveDocument)({
86
- rootDocument: document,
87
- rootType: types.Root,
88
- externalRefResolver,
89
- });
90
- const statsVisitor = (0, openapi_core_1.normalizeVisitors)([
91
- {
92
- severity: 'warn',
93
- ruleId: 'stats',
94
- visitor: (0, openapi_core_1.Stats)(statsAccumulator),
95
- },
96
- ], types);
97
- (0, openapi_core_1.walkDocument)({
98
- document,
99
- rootType: types.Root,
100
- normalizedVisitors: statsVisitor,
101
- resolvedRefMap,
102
- ctx,
103
- });
104
- printStats(statsAccumulator, path, startedAt, argv.format);
62
+ async function handleStats({ argv, config, collectSpecData }) {
63
+ const [{ path }] = await (0, miscellaneous_1.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
64
+ const externalRefResolver = new openapi_core_1.BaseResolver(config.resolve);
65
+ const { bundle: document } = await (0, openapi_core_1.bundle)({ config, ref: path });
66
+ collectSpecData?.(document.parsed);
67
+ const lintConfig = config.styleguide;
68
+ const specVersion = (0, openapi_core_1.detectSpec)(document.parsed);
69
+ const types = (0, openapi_core_1.normalizeTypes)(lintConfig.extendTypes((0, openapi_core_1.getTypes)(specVersion), specVersion), lintConfig);
70
+ const startedAt = perf_hooks_1.performance.now();
71
+ const ctx = {
72
+ problems: [],
73
+ oasVersion: specVersion,
74
+ visitorsData: {},
75
+ };
76
+ const resolvedRefMap = await (0, openapi_core_1.resolveDocument)({
77
+ rootDocument: document,
78
+ rootType: types.Root,
79
+ externalRefResolver,
80
+ });
81
+ const statsVisitor = (0, openapi_core_1.normalizeVisitors)([
82
+ {
83
+ severity: 'warn',
84
+ ruleId: 'stats',
85
+ visitor: (0, openapi_core_1.Stats)(statsAccumulator),
86
+ },
87
+ ], types);
88
+ (0, openapi_core_1.walkDocument)({
89
+ document,
90
+ rootType: types.Root,
91
+ normalizedVisitors: statsVisitor,
92
+ resolvedRefMap,
93
+ ctx,
105
94
  });
95
+ printStats(statsAccumulator, path, startedAt, argv.format);
106
96
  }
107
- exports.handleStats = handleStats;
package/lib/index.js CHANGED
@@ -1,14 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
3
  Object.defineProperty(exports, "__esModule", { value: true });
13
4
  require("./utils/assert-node-version");
14
5
  const yargs = require("yargs");
@@ -502,51 +493,47 @@ yargs
502
493
  process.env.REDOCLY_CLI_COMMAND = 'bundle';
503
494
  (0, wrapper_1.commandWrapper)(bundle_1.handleBundle)(argv);
504
495
  })
505
- .command('check-config', 'Lint the Redocly configuration file.', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
506
- return yargs.option({
507
- config: {
508
- description: 'Path to the config file.',
509
- type: 'string',
510
- },
511
- 'lint-config': {
512
- description: 'Severity level for config file linting.',
513
- choices: ['warn', 'error'],
514
- default: 'error',
515
- },
516
- });
496
+ .command('check-config', 'Lint the Redocly configuration file.', async (yargs) => yargs.option({
497
+ config: {
498
+ description: 'Path to the config file.',
499
+ type: 'string',
500
+ },
501
+ 'lint-config': {
502
+ description: 'Severity level for config file linting.',
503
+ choices: ['warn', 'error'],
504
+ default: 'error',
505
+ },
517
506
  }), (argv) => {
518
507
  process.env.REDOCLY_CLI_COMMAND = 'check-config';
519
508
  (0, wrapper_1.commandWrapper)()(argv);
520
509
  })
521
- .command('login', 'Login to the Redocly API registry with an access token.', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
522
- return yargs.options({
523
- verbose: {
524
- description: 'Include additional output.',
525
- type: 'boolean',
526
- },
527
- region: {
528
- description: 'Specify a region.',
529
- alias: 'r',
530
- choices: types_1.regionChoices,
531
- },
532
- config: {
533
- description: 'Path to the config file.',
534
- requiresArg: true,
535
- type: 'string',
536
- },
537
- });
510
+ .command('login', 'Login to the Redocly API registry with an access token.', async (yargs) => yargs.options({
511
+ verbose: {
512
+ description: 'Include additional output.',
513
+ type: 'boolean',
514
+ },
515
+ region: {
516
+ description: 'Specify a region.',
517
+ alias: 'r',
518
+ choices: types_1.regionChoices,
519
+ },
520
+ config: {
521
+ description: 'Path to the config file.',
522
+ requiresArg: true,
523
+ type: 'string',
524
+ },
538
525
  }), (argv) => {
539
526
  process.env.REDOCLY_CLI_COMMAND = 'login';
540
527
  (0, wrapper_1.commandWrapper)(login_1.handleLogin)(argv);
541
528
  })
542
- .command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, (argv) => __awaiter(void 0, void 0, void 0, function* () {
529
+ .command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, async (argv) => {
543
530
  process.env.REDOCLY_CLI_COMMAND = 'logout';
544
- yield (0, wrapper_1.commandWrapper)(() => __awaiter(void 0, void 0, void 0, function* () {
531
+ await (0, wrapper_1.commandWrapper)(async () => {
545
532
  const client = new openapi_core_1.RedoclyClient();
546
533
  client.logout();
547
534
  process.stdout.write('Logged out from the Redocly account. ✋\n');
548
- }))(argv);
549
- }))
535
+ })(argv);
536
+ })
550
537
  .command('preview', 'Preview Redocly project using one of the product NPM packages.', (yargs) => yargs.options({
551
538
  product: {
552
539
  type: 'string',
@@ -657,14 +644,13 @@ yargs
657
644
  },
658
645
  })
659
646
  .check((argv) => {
660
- var _a;
661
- if (argv.theme && !((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi))
647
+ if (argv.theme && !argv.theme?.openapi)
662
648
  throw Error('Invalid option: theme.openapi not set');
663
649
  return true;
664
- }), (argv) => __awaiter(void 0, void 0, void 0, function* () {
650
+ }), async (argv) => {
665
651
  process.env.REDOCLY_CLI_COMMAND = 'build-docs';
666
652
  (0, wrapper_1.commandWrapper)(build_docs_1.handlerBuildCommand)(argv);
667
- }))
653
+ })
668
654
  .completion('completion', 'Generate autocomplete script for `redocly` command.')
669
655
  .demandCommand(1)
670
656
  .middleware([update_version_notifier_1.notifyUpdateCliVersion])
package/lib/types.d.ts CHANGED
@@ -22,9 +22,9 @@ export type Entrypoint = {
22
22
  path: string;
23
23
  alias?: string;
24
24
  };
25
- export declare const outputExtensions: readonly BundleOutputFormat[];
25
+ export declare const outputExtensions: ReadonlyArray<BundleOutputFormat>;
26
26
  export type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
27
- export declare const regionChoices: readonly Region[];
27
+ export declare const regionChoices: ReadonlyArray<Region>;
28
28
  export type CommandOptions = StatsOptions | SplitOptions | JoinOptions | PushOptions | PushBhOptions | LintOptions | BundleOptions | LoginOptions | PreviewDocsOptions | BuildDocsArgv | PushStatusOptions | VerifyConfigOptions | PreviewProjectOptions;
29
29
  export type VerifyConfigOptions = {
30
30
  config?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  export declare const getFallbackApisOrExit: jest.Mock<any, [entrypoints: any]>;
3
2
  export declare const dumpBundle: jest.Mock<string, []>;
4
3
  export declare const slash: jest.Mock<any, any>;
@@ -1,29 +1,24 @@
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
3
  const node_fetch_1 = require("node-fetch");
13
4
  const abort_controller_1 = require("abort-controller");
14
5
  const openapi_core_1 = require("@redocly/openapi-core");
15
6
  const TIMEOUT = 3000;
16
- exports.default = (url, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
7
+ exports.default = async (url, options = {}) => {
17
8
  try {
18
9
  const controller = new abort_controller_1.default();
19
10
  const timeout = setTimeout(() => {
20
11
  controller.abort();
21
12
  }, TIMEOUT);
22
- const res = yield (0, node_fetch_1.default)(url, Object.assign(Object.assign({ signal: controller.signal }, options), { agent: (0, openapi_core_1.getProxyAgent)() }));
13
+ const res = await (0, node_fetch_1.default)(url, {
14
+ signal: controller.signal,
15
+ ...options,
16
+ agent: (0, openapi_core_1.getProxyAgent)(),
17
+ });
23
18
  clearTimeout(timeout);
24
19
  return res;
25
20
  }
26
21
  catch (e) {
27
22
  return;
28
23
  }
29
- });
24
+ };
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommandNameFromArgs = void 0;
3
+ exports.getCommandNameFromArgs = getCommandNameFromArgs;
4
4
  function getCommandNameFromArgs(argv) {
5
- var _a, _b;
6
- return (_b = (_a = argv === null || argv === void 0 ? void 0 : argv._) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '';
5
+ return argv?._?.[0] ?? '';
7
6
  }
8
- exports.getCommandNameFromArgs = getCommandNameFromArgs;
@@ -1,29 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalize = exports.keysOf = exports.isString = exports.isEmptyObject = exports.isObject = void 0;
3
+ exports.isObject = isObject;
4
+ exports.isEmptyObject = isEmptyObject;
5
+ exports.isString = isString;
6
+ exports.keysOf = keysOf;
7
+ exports.capitalize = capitalize;
4
8
  function isObject(obj) {
5
9
  const type = typeof obj;
6
10
  return type === 'function' || (type === 'object' && !!obj);
7
11
  }
8
- exports.isObject = isObject;
9
12
  function isEmptyObject(obj) {
10
13
  return !!obj && Object.keys(obj).length === 0;
11
14
  }
12
- exports.isEmptyObject = isEmptyObject;
13
15
  function isString(str) {
14
16
  return Object.prototype.toString.call(str) === '[object String]';
15
17
  }
16
- exports.isString = isString;
17
18
  function keysOf(obj) {
18
19
  if (!obj)
19
20
  return [];
20
21
  return Object.keys(obj);
21
22
  }
22
- exports.keysOf = keysOf;
23
23
  function capitalize(s) {
24
- if ((s === null || s === void 0 ? void 0 : s.length) > 0) {
24
+ if (s?.length > 0) {
25
25
  return s[0].toUpperCase() + s.slice(1);
26
26
  }
27
27
  return s;
28
28
  }
29
- exports.capitalize = capitalize;
@@ -1,7 +1,7 @@
1
- import { BundleOutputFormat, StyleguideConfig, Region, Config, Oas3Definition, Oas2Definition } from '@redocly/openapi-core';
2
- import { Totals, Entrypoint, ConfigApis, CommandOptions, OutputExtensions } from '../types';
3
- import { Arguments } from 'yargs';
1
+ import type { Arguments } from 'yargs';
2
+ import type { BundleOutputFormat, StyleguideConfig, Region, Config, Oas3Definition, Oas2Definition } from '@redocly/openapi-core';
4
3
  import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
4
+ import type { Totals, Entrypoint, ConfigApis, CommandOptions, OutputExtensions } from '../types';
5
5
  export declare function getFallbackApisOrExit(argsApis: string[] | undefined, config: ConfigApis): Promise<Entrypoint[]>;
6
6
  export declare function getExecutionTime(startedAt: number): string;
7
7
  export declare function printExecutionTime(commandName: string, startedAt: number, api: string): void;
@@ -20,7 +20,7 @@ export declare function writeToFileByExtension(data: unknown, filePath: string,
20
20
  export declare function writeYaml(data: any, filename: string, noRefs?: boolean): void;
21
21
  export declare function writeJson(data: unknown, filename: string): void;
22
22
  export declare function getAndValidateFileExtension(fileName: string): NonNullable<OutputExtensions>;
23
- export declare function pluralize(label: string, num: number): string;
23
+ export declare function pluralize(sentence: string, count?: number, inclusive?: boolean): string;
24
24
  export declare function handleError(e: Error, ref: string): void;
25
25
  export declare class HandledError extends Error {
26
26
  }
@@ -46,7 +46,7 @@ export declare function loadConfigAndHandleErrors(options?: {
46
46
  export declare function sortTopLevelKeysForOas(document: Oas3Definition | Oas2Definition): Oas3Definition | Oas2Definition;
47
47
  export declare function checkIfRulesetExist(rules: typeof StyleguideConfig.prototype.rules): void;
48
48
  export declare function cleanColors(input: string): string;
49
- export declare function sendTelemetry(argv: Arguments | undefined, exit_code: ExitCode, has_config: boolean | undefined): Promise<void>;
49
+ export declare function sendTelemetry(argv: Arguments | undefined, exit_code: ExitCode, has_config: boolean | undefined, spec_version: string | undefined, spec_keyword: string | undefined, spec_full_version: string | undefined): Promise<void>;
50
50
  export type ExitCode = 0 | 1 | 2;
51
51
  export type Analytics = {
52
52
  event: string;
@@ -62,7 +62,11 @@ export type Analytics = {
62
62
  environment_ci?: string;
63
63
  raw_input: string;
64
64
  has_config?: boolean;
65
+ spec_version?: string;
66
+ spec_keyword?: string;
67
+ spec_full_version?: string;
65
68
  };
66
69
  export declare function cleanArgs(args: CommandOptions): Record<string, unknown>;
67
70
  export declare function cleanRawInput(argv: string[]): string;
68
71
  export declare function checkForDeprecatedOptions<T>(argv: T, deprecatedOptions: Array<keyof T>): void;
72
+ export declare function notifyAboutIncompatibleConfigOptions(themeOpenapiOptions: Record<string, unknown> | undefined): void;