@redocly/cli 1.18.1 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +107 -128
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -74
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.d.ts +1 -1
- package/lib/commands/build-docs/utils.js +27 -39
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +375 -388
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +64 -75
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +10 -22
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +93 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +1 -4
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/constants.d.ts +1 -1
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/preview-project/types.d.ts +1 -1
- package/lib/commands/push.d.ts +9 -12
- package/lib/commands/push.js +180 -196
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +20 -33
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +36 -47
- package/lib/index.js +34 -49
- package/lib/types.d.ts +4 -5
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.d.ts +1 -1
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +4 -1
- package/lib/utils/miscellaneous.js +130 -152
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +3 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/api/api-client.ts +2 -1
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +12 -9
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/build-docs/utils.ts +4 -4
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +6 -2
- package/src/commands/lint.ts +9 -3
- package/src/commands/login.ts +5 -2
- package/src/commands/preview-docs/index.ts +7 -1
- package/src/commands/preview-docs/preview-server/preview-server.ts +4 -3
- package/src/commands/preview-docs/preview-server/server.ts +2 -1
- package/src/commands/preview-project/constants.ts +1 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/preview-project/types.ts +1 -1
- package/src/commands/push.ts +15 -18
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +4 -2
- package/src/commands/stats.ts +13 -6
- package/src/index.ts +13 -7
- package/src/types.ts +2 -3
- package/src/utils/getCommandNameFromArgs.ts +1 -1
- package/src/utils/miscellaneous.ts +11 -1
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,15 +1,9 @@
|
|
|
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.
|
|
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");
|
|
@@ -19,20 +13,18 @@ const perf_hooks_1 = require("perf_hooks");
|
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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)) {
|
|
@@ -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 = (
|
|
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 =
|
|
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(
|
|
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(
|
|
240
|
+
for (const componentName of Object.keys(components?.[componentType] || {})) {
|
|
254
241
|
const filename = getFileNamePath(componentDirPath, componentName, ext);
|
|
255
|
-
const componentData =
|
|
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
|
-
|
|
253
|
+
delete openapi.components?.[componentType]?.[componentName];
|
|
267
254
|
}
|
|
268
255
|
}
|
|
269
256
|
removeEmptyComponents(openapi, componentType);
|
package/lib/commands/stats.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CommandArgs } from '../wrapper';
|
|
2
2
|
import type { OutputFormat } from '@redocly/openapi-core';
|
|
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
|
|
8
|
+
export declare function handleStats({ argv, config, collectSpecData }: CommandArgs<StatsOptions>): Promise<void>;
|
package/lib/commands/stats.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
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 =
|
|
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");
|
|
16
7
|
const miscellaneous_1 = require("../utils/miscellaneous");
|
|
17
|
-
const miscellaneous_2 = require("../utils/miscellaneous");
|
|
18
8
|
const statsAccumulator = {
|
|
19
9
|
refs: { metric: '🚗 References', total: 0, color: 'red', items: new Set() },
|
|
20
10
|
externalDocs: { metric: '📦 External Documents', total: 0, color: 'magenta' },
|
|
@@ -22,6 +12,7 @@ const statsAccumulator = {
|
|
|
22
12
|
parameters: { metric: '👉 Parameters', total: 0, color: 'yellow', items: new Set() },
|
|
23
13
|
links: { metric: '🔗 Links', total: 0, color: 'cyan', items: new Set() },
|
|
24
14
|
pathItems: { metric: '🔀 Path Items', total: 0, color: 'green' },
|
|
15
|
+
webhooks: { metric: '🎣 Webhooks', total: 0, color: 'green' },
|
|
25
16
|
operations: { metric: '👷 Operations', total: 0, color: 'yellow' },
|
|
26
17
|
tags: { metric: '🔖 Tags', total: 0, color: 'white', items: new Set() },
|
|
27
18
|
};
|
|
@@ -58,7 +49,7 @@ function printStats(statsAccumulator, api, startedAt, format) {
|
|
|
58
49
|
case 'stylish':
|
|
59
50
|
process.stderr.write(`Document: ${colors.magenta(api)} stats:\n\n`);
|
|
60
51
|
printStatsStylish(statsAccumulator);
|
|
61
|
-
(0,
|
|
52
|
+
(0, miscellaneous_1.printExecutionTime)('stats', startedAt, api);
|
|
62
53
|
break;
|
|
63
54
|
case 'json':
|
|
64
55
|
printStatsJson(statsAccumulator);
|
|
@@ -68,40 +59,38 @@ function printStats(statsAccumulator, api, startedAt, format) {
|
|
|
68
59
|
break;
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
|
-
function handleStats(argv, config) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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,20 +1,11 @@
|
|
|
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");
|
|
15
6
|
const colors = require("colorette");
|
|
16
|
-
const types_1 = require("./types");
|
|
17
7
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
8
|
+
const types_1 = require("./types");
|
|
18
9
|
const preview_docs_1 = require("./commands/preview-docs");
|
|
19
10
|
const stats_1 = require("./commands/stats");
|
|
20
11
|
const split_1 = require("./commands/split");
|
|
@@ -26,7 +17,6 @@ const login_1 = require("./commands/login");
|
|
|
26
17
|
const build_docs_1 = require("./commands/build-docs");
|
|
27
18
|
const update_version_notifier_1 = require("./utils/update-version-notifier");
|
|
28
19
|
const wrapper_1 = require("./wrapper");
|
|
29
|
-
const update_version_notifier_2 = require("./utils/update-version-notifier");
|
|
30
20
|
const preview_project_1 = require("./commands/preview-project");
|
|
31
21
|
const constants_1 = require("./commands/preview-project/constants");
|
|
32
22
|
const push_1 = require("./commands/push");
|
|
@@ -35,7 +25,7 @@ if (!('replaceAll' in String.prototype)) {
|
|
|
35
25
|
}
|
|
36
26
|
(0, update_version_notifier_1.cacheLatestVersion)();
|
|
37
27
|
yargs
|
|
38
|
-
.version('version', 'Show version number.',
|
|
28
|
+
.version('version', 'Show version number.', update_version_notifier_1.version)
|
|
39
29
|
.help('help', 'Show help.')
|
|
40
30
|
.parserConfiguration({ 'greedy-arrays': false, 'camel-case-expansion': false })
|
|
41
31
|
.command('stats [api]', 'Show statistics for an API description.', (yargs) => yargs.positional('api', { type: 'string' }).option({
|
|
@@ -502,51 +492,47 @@ yargs
|
|
|
502
492
|
process.env.REDOCLY_CLI_COMMAND = 'bundle';
|
|
503
493
|
(0, wrapper_1.commandWrapper)(bundle_1.handleBundle)(argv);
|
|
504
494
|
})
|
|
505
|
-
.command('check-config', 'Lint the Redocly configuration file.', (yargs) =>
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
'
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
},
|
|
516
|
-
});
|
|
495
|
+
.command('check-config', 'Lint the Redocly configuration file.', async (yargs) => yargs.option({
|
|
496
|
+
config: {
|
|
497
|
+
description: 'Path to the config file.',
|
|
498
|
+
type: 'string',
|
|
499
|
+
},
|
|
500
|
+
'lint-config': {
|
|
501
|
+
description: 'Severity level for config file linting.',
|
|
502
|
+
choices: ['warn', 'error'],
|
|
503
|
+
default: 'error',
|
|
504
|
+
},
|
|
517
505
|
}), (argv) => {
|
|
518
506
|
process.env.REDOCLY_CLI_COMMAND = 'check-config';
|
|
519
507
|
(0, wrapper_1.commandWrapper)()(argv);
|
|
520
508
|
})
|
|
521
|
-
.command('login', 'Login to the Redocly API registry with an access token.', (yargs) =>
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
},
|
|
537
|
-
});
|
|
509
|
+
.command('login', 'Login to the Redocly API registry with an access token.', async (yargs) => yargs.options({
|
|
510
|
+
verbose: {
|
|
511
|
+
description: 'Include additional output.',
|
|
512
|
+
type: 'boolean',
|
|
513
|
+
},
|
|
514
|
+
region: {
|
|
515
|
+
description: 'Specify a region.',
|
|
516
|
+
alias: 'r',
|
|
517
|
+
choices: types_1.regionChoices,
|
|
518
|
+
},
|
|
519
|
+
config: {
|
|
520
|
+
description: 'Path to the config file.',
|
|
521
|
+
requiresArg: true,
|
|
522
|
+
type: 'string',
|
|
523
|
+
},
|
|
538
524
|
}), (argv) => {
|
|
539
525
|
process.env.REDOCLY_CLI_COMMAND = 'login';
|
|
540
526
|
(0, wrapper_1.commandWrapper)(login_1.handleLogin)(argv);
|
|
541
527
|
})
|
|
542
|
-
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, (argv) =>
|
|
528
|
+
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, async (argv) => {
|
|
543
529
|
process.env.REDOCLY_CLI_COMMAND = 'logout';
|
|
544
|
-
|
|
530
|
+
await (0, wrapper_1.commandWrapper)(async () => {
|
|
545
531
|
const client = new openapi_core_1.RedoclyClient();
|
|
546
532
|
client.logout();
|
|
547
533
|
process.stdout.write('Logged out from the Redocly account. ✋\n');
|
|
548
|
-
})
|
|
549
|
-
})
|
|
534
|
+
})(argv);
|
|
535
|
+
})
|
|
550
536
|
.command('preview', 'Preview Redocly project using one of the product NPM packages.', (yargs) => yargs.options({
|
|
551
537
|
product: {
|
|
552
538
|
type: 'string',
|
|
@@ -657,14 +643,13 @@ yargs
|
|
|
657
643
|
},
|
|
658
644
|
})
|
|
659
645
|
.check((argv) => {
|
|
660
|
-
|
|
661
|
-
if (argv.theme && !((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi))
|
|
646
|
+
if (argv.theme && !argv.theme?.openapi)
|
|
662
647
|
throw Error('Invalid option: theme.openapi not set');
|
|
663
648
|
return true;
|
|
664
|
-
}), (argv) =>
|
|
649
|
+
}), async (argv) => {
|
|
665
650
|
process.env.REDOCLY_CLI_COMMAND = 'build-docs';
|
|
666
651
|
(0, wrapper_1.commandWrapper)(build_docs_1.handlerBuildCommand)(argv);
|
|
667
|
-
})
|
|
652
|
+
})
|
|
668
653
|
.completion('completion', 'Generate autocomplete script for `redocly` command.')
|
|
669
654
|
.demandCommand(1)
|
|
670
655
|
.middleware([update_version_notifier_1.notifyUpdateCliVersion])
|
package/lib/types.d.ts
CHANGED
|
@@ -9,9 +9,8 @@ import type { StatsOptions } from './commands/stats';
|
|
|
9
9
|
import type { SplitOptions } from './commands/split';
|
|
10
10
|
import type { PreviewDocsOptions } from './commands/preview-docs';
|
|
11
11
|
import type { BuildDocsArgv } from './commands/build-docs/types';
|
|
12
|
-
import type { PushOptions as PushBhOptions } from './cms/commands/push';
|
|
13
|
-
import type { PushStatusOptions } from './cms/commands/push-status';
|
|
14
12
|
import type { PushOptions as CMSPushOptions } from './cms/commands/push';
|
|
13
|
+
import type { PushStatusOptions } from './cms/commands/push-status';
|
|
15
14
|
import type { PreviewProjectOptions } from './commands/preview-project/types';
|
|
16
15
|
export type Totals = {
|
|
17
16
|
errors: number;
|
|
@@ -22,10 +21,10 @@ export type Entrypoint = {
|
|
|
22
21
|
path: string;
|
|
23
22
|
alias?: string;
|
|
24
23
|
};
|
|
25
|
-
export declare const outputExtensions:
|
|
24
|
+
export declare const outputExtensions: ReadonlyArray<BundleOutputFormat>;
|
|
26
25
|
export type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
|
|
27
|
-
export declare const regionChoices:
|
|
28
|
-
export type CommandOptions = StatsOptions | SplitOptions | JoinOptions | PushOptions |
|
|
26
|
+
export declare const regionChoices: ReadonlyArray<Region>;
|
|
27
|
+
export type CommandOptions = StatsOptions | SplitOptions | JoinOptions | PushOptions | CMSPushOptions | LintOptions | BundleOptions | LoginOptions | PreviewDocsOptions | BuildDocsArgv | PushStatusOptions | VerifyConfigOptions | PreviewProjectOptions;
|
|
29
28
|
export type VerifyConfigOptions = {
|
|
30
29
|
config?: string;
|
|
31
30
|
'lint-config'?: 'warning' | 'error' | 'off';
|
|
@@ -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 = {}) =>
|
|
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 =
|
|
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,2 +1,2 @@
|
|
|
1
|
-
import { Arguments } from 'yargs';
|
|
1
|
+
import type { Arguments } from 'yargs';
|
|
2
2
|
export declare function getCommandNameFromArgs(argv: Arguments | undefined): string | number;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCommandNameFromArgs =
|
|
3
|
+
exports.getCommandNameFromArgs = getCommandNameFromArgs;
|
|
4
4
|
function getCommandNameFromArgs(argv) {
|
|
5
|
-
|
|
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;
|
package/lib/utils/js-utils.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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 (
|
|
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;
|
|
@@ -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,6 +62,9 @@ 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;
|