@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,14 +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 });
|
|
3
|
+
exports.default = startPreviewServer;
|
|
12
4
|
const handlebars_1 = require("handlebars");
|
|
13
5
|
const colorette = require("colorette");
|
|
14
6
|
const get_port_please_1 = require("get-port-please");
|
|
@@ -47,79 +39,75 @@ function getPageHTML(htmlTemplate, redocOptions = {}, useRedocPro, wsPort, host)
|
|
|
47
39
|
</script>`,
|
|
48
40
|
});
|
|
49
41
|
}
|
|
50
|
-
function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, }) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
async function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, }) {
|
|
43
|
+
const defaultTemplate = path.join(__dirname, 'default.hbs');
|
|
44
|
+
const handler = async (request, response) => {
|
|
45
|
+
console.time(colorette.dim(`GET ${request.url}`));
|
|
46
|
+
const { htmlTemplate } = getOptions() || {};
|
|
47
|
+
if (request.url?.endsWith('/') || path.extname(request.url) === '') {
|
|
48
|
+
(0, server_1.respondWithGzip)(getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort, host), request, response, {
|
|
49
|
+
'Content-Type': 'text/html',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (request.url === '/openapi.json') {
|
|
53
|
+
const bundle = await getBundle();
|
|
54
|
+
if (bundle === undefined) {
|
|
55
|
+
(0, server_1.respondWithGzip)(JSON.stringify({
|
|
56
|
+
openapi: '3.0.0',
|
|
57
|
+
info: {
|
|
58
|
+
description: '<code> Failed to generate bundle: check out console output for more details </code>',
|
|
59
|
+
},
|
|
60
|
+
paths: {},
|
|
61
|
+
}), request, response, {
|
|
62
|
+
'Content-Type': 'application/json',
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
|
-
else if (request.url === '/openapi.json') {
|
|
63
|
-
const bundle = yield getBundle();
|
|
64
|
-
if (bundle === undefined) {
|
|
65
|
-
(0, server_1.respondWithGzip)(JSON.stringify({
|
|
66
|
-
openapi: '3.0.0',
|
|
67
|
-
info: {
|
|
68
|
-
description: '<code> Failed to generate bundle: check out console output for more details </code>',
|
|
69
|
-
},
|
|
70
|
-
paths: {},
|
|
71
|
-
}), request, response, {
|
|
72
|
-
'Content-Type': 'application/json',
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
(0, server_1.respondWithGzip)(JSON.stringify(bundle), request, response, {
|
|
77
|
-
'Content-Type': 'application/json',
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
65
|
else {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
66
|
+
(0, server_1.respondWithGzip)(JSON.stringify(bundle), request, response, {
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
let filePath =
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
{
|
|
76
|
+
'/hot.js': path.join(__dirname, 'hot.js'),
|
|
77
|
+
'/oauth2-redirect.html': path.join(__dirname, 'oauth2-redirect.html'),
|
|
78
|
+
'/simplewebsocket.min.js': require.resolve('simple-websocket/simplewebsocket.min.js'),
|
|
79
|
+
}[request.url || ''];
|
|
80
|
+
if (!filePath) {
|
|
81
|
+
const basePath = htmlTemplate ? path.dirname(htmlTemplate) : process.cwd();
|
|
82
|
+
filePath = path.resolve(basePath, `.${request.url}`);
|
|
83
|
+
if (!(0, miscellaneous_1.isSubdir)(basePath, filePath)) {
|
|
84
|
+
(0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
85
|
+
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
86
|
+
return;
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
}
|
|
89
|
+
const extname = String(path.extname(filePath)).toLowerCase();
|
|
90
|
+
const contentType = server_1.mimeTypes[extname] || 'application/octet-stream';
|
|
91
|
+
try {
|
|
92
|
+
(0, server_1.respondWithGzip)(await fs_1.promises.readFile(filePath), request, response, {
|
|
93
|
+
'Content-Type': contentType,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
if (e.code === 'ENOENT') {
|
|
98
|
+
(0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
105
99
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
(0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
(0, server_1.respondWithGzip)(`Something went wrong: ${e.code || e.message}...\n`, request, response, {}, 500);
|
|
112
|
-
}
|
|
100
|
+
else {
|
|
101
|
+
(0, server_1.respondWithGzip)(`Something went wrong: ${e.code || e.message}...\n`, request, response, {}, 500);
|
|
113
102
|
}
|
|
114
103
|
}
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
return (0, server_1.startWsServer)(wsPort, host);
|
|
104
|
+
}
|
|
105
|
+
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
106
|
+
};
|
|
107
|
+
const wsPort = await (0, get_port_please_1.getPort)({ port: 32201, portRange: [32201, 32301], host });
|
|
108
|
+
const server = (0, server_1.startHttpServer)(port, host, handler);
|
|
109
|
+
server.on('listening', () => {
|
|
110
|
+
process.stdout.write(`\n 🔎 Preview server running at ${colorette.blue(`http://${host}:${port}\n`)}`);
|
|
123
111
|
});
|
|
112
|
+
return (0, server_1.startWsServer)(wsPort, host);
|
|
124
113
|
}
|
|
125
|
-
exports.default = startPreviewServer;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import * as http from 'http';
|
|
5
|
-
import { ReadStream } from 'fs';
|
|
2
|
+
import type { ReadStream } from 'fs';
|
|
6
3
|
export declare const mimeTypes: {
|
|
7
4
|
'.html': string;
|
|
8
5
|
'.js': string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mimeTypes = void 0;
|
|
4
|
+
exports.respondWithGzip = respondWithGzip;
|
|
5
|
+
exports.startHttpServer = startHttpServer;
|
|
6
|
+
exports.startWsServer = startWsServer;
|
|
4
7
|
const http = require("http");
|
|
5
8
|
const zlib = require("zlib");
|
|
6
9
|
const SocketServer = require('simple-websocket/server.js');
|
|
@@ -26,11 +29,11 @@ function respondWithGzip(contents, request, response, headers = {}, code = 200)
|
|
|
26
29
|
let compressedStream;
|
|
27
30
|
const acceptEncoding = request.headers['accept-encoding'] || '';
|
|
28
31
|
if (acceptEncoding.match(/\bdeflate\b/)) {
|
|
29
|
-
response.writeHead(code,
|
|
32
|
+
response.writeHead(code, { ...headers, 'content-encoding': 'deflate' });
|
|
30
33
|
compressedStream = zlib.createDeflate();
|
|
31
34
|
}
|
|
32
35
|
else if (acceptEncoding.match(/\bgzip\b/)) {
|
|
33
|
-
response.writeHead(code,
|
|
36
|
+
response.writeHead(code, { ...headers, 'content-encoding': 'gzip' });
|
|
34
37
|
compressedStream = zlib.createGzip();
|
|
35
38
|
}
|
|
36
39
|
else {
|
|
@@ -53,11 +56,9 @@ function respondWithGzip(contents, request, response, headers = {}, code = 200)
|
|
|
53
56
|
contents.pipe(compressedStream).pipe(response);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
exports.respondWithGzip = respondWithGzip;
|
|
57
59
|
function startHttpServer(port, host, handler) {
|
|
58
60
|
return http.createServer(handler).listen(port, host);
|
|
59
61
|
}
|
|
60
|
-
exports.startHttpServer = startHttpServer;
|
|
61
62
|
function startWsServer(port, host) {
|
|
62
63
|
const socketServer = new SocketServer({ port, host, clientTracking: true });
|
|
63
64
|
socketServer.on('connection', (socket) => {
|
|
@@ -82,4 +83,3 @@ function startWsServer(port, host) {
|
|
|
82
83
|
};
|
|
83
84
|
return socketServer;
|
|
84
85
|
}
|
|
85
|
-
exports.startWsServer = startWsServer;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { PreviewProjectOptions } from './types';
|
|
2
|
-
|
|
2
|
+
import type { CommandArgs } from '../../wrapper';
|
|
3
|
+
export declare const previewProject: ({ argv }: CommandArgs<PreviewProjectOptions>) => Promise<void>;
|
|
@@ -1,23 +1,14 @@
|
|
|
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
|
exports.previewProject = void 0;
|
|
13
4
|
const path = require("path");
|
|
14
5
|
const fs_1 = require("fs");
|
|
15
6
|
const child_process_1 = require("child_process");
|
|
16
7
|
const constants_1 = require("./constants");
|
|
17
|
-
const previewProject =
|
|
18
|
-
const { plan, port } =
|
|
19
|
-
const projectDir =
|
|
20
|
-
const product =
|
|
8
|
+
const previewProject = async ({ argv }) => {
|
|
9
|
+
const { plan, port } = argv;
|
|
10
|
+
const projectDir = argv['source-dir'];
|
|
11
|
+
const product = argv.product || tryGetProductFromPackageJson(projectDir);
|
|
21
12
|
if (!isValidProduct(product)) {
|
|
22
13
|
process.stderr.write(`Invalid product ${product}`);
|
|
23
14
|
throw new Error(`Project preview launch failed`);
|
|
@@ -30,7 +21,7 @@ const previewProject = (args) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
30
21
|
stdio: 'inherit',
|
|
31
22
|
cwd: projectDir,
|
|
32
23
|
});
|
|
33
|
-
}
|
|
24
|
+
};
|
|
34
25
|
exports.previewProject = previewProject;
|
|
35
26
|
const isValidProduct = (product) => {
|
|
36
27
|
if (!product) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PRODUCT_PACKAGES, PRODUCT_PLANS } from './constants';
|
|
1
|
+
import type { PRODUCT_PACKAGES, PRODUCT_PLANS } from './constants';
|
|
2
2
|
export type Product = keyof typeof PRODUCT_PACKAGES;
|
|
3
3
|
export type ProductPlan = typeof PRODUCT_PLANS[number];
|
|
4
4
|
export type PreviewProjectOptions = {
|
package/lib/commands/push.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Config, Region } from '@redocly/openapi-core';
|
|
2
1
|
import { handlePush as handleCMSPush } from '../cms/commands/push';
|
|
2
|
+
import type { Config, Region } from '@redocly/openapi-core';
|
|
3
|
+
import type { CommandArgs } from '../wrapper';
|
|
3
4
|
export declare const DESTINATION_REGEX: RegExp;
|
|
4
5
|
export type PushOptions = {
|
|
5
6
|
api?: string;
|
|
@@ -18,14 +19,10 @@ export type PushOptions = {
|
|
|
18
19
|
export declare function commonPushHandler({ project, 'mount-path': mountPath, }: {
|
|
19
20
|
project?: string;
|
|
20
21
|
'mount-path'?: string;
|
|
21
|
-
}): typeof handleCMSPush | (({ apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} & {
|
|
26
|
-
'batch-id'?: string | undefined;
|
|
27
|
-
}, config: Config) => Promise<void>);
|
|
28
|
-
export declare function handlePush(argv: PushOptions, config: Config): Promise<void>;
|
|
22
|
+
}): typeof handleCMSPush | (({ argv: { apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }, config, version, }: CommandArgs<BarePushArgs & {
|
|
23
|
+
"batch-id"?: string;
|
|
24
|
+
}>) => Promise<void>);
|
|
25
|
+
export declare function handlePush({ argv, config }: CommandArgs<PushOptions>): Promise<void>;
|
|
29
26
|
export declare function getDestinationProps(destination: string | undefined, organization: string | undefined): {
|
|
30
27
|
organizationId: string | undefined;
|
|
31
28
|
name: string | undefined;
|
|
@@ -36,9 +33,9 @@ type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
|
|
|
36
33
|
branch?: string;
|
|
37
34
|
destination?: string;
|
|
38
35
|
};
|
|
39
|
-
export declare const transformPush: (callback: typeof handlePush) => ({ apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }: BarePushArgs & {
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
export declare const transformPush: (callback: typeof handlePush) => ({ argv: { apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }, config, version, }: CommandArgs<BarePushArgs & {
|
|
37
|
+
"batch-id"?: string;
|
|
38
|
+
}>) => Promise<void>;
|
|
42
39
|
export declare function getApiRoot({ name, version, config: { apis }, }: {
|
|
43
40
|
name: string;
|
|
44
41
|
version: string;
|