@redocly/cli 1.34.3 → 2.0.0-next.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/README.md +34 -3
- package/bin/cli.js +1 -1
- package/lib/auth/device-flow.d.ts +1 -0
- package/lib/auth/device-flow.d.ts.map +1 -0
- package/lib/auth/device-flow.js +15 -17
- package/lib/auth/device-flow.js.map +1 -0
- package/lib/auth/oauth-client.d.ts +1 -0
- package/lib/auth/oauth-client.d.ts.map +1 -0
- package/lib/auth/oauth-client.js +21 -23
- package/lib/auth/oauth-client.js.map +1 -0
- package/lib/commands/auth.d.ts +3 -5
- package/lib/commands/auth.d.ts.map +1 -0
- package/lib/commands/auth.js +19 -44
- package/lib/commands/auth.js.map +1 -0
- package/lib/commands/build-docs/index.d.ts +4 -3
- package/lib/commands/build-docs/index.d.ts.map +1 -0
- package/lib/commands/build-docs/index.js +23 -24
- package/lib/commands/build-docs/index.js.map +1 -0
- package/lib/commands/build-docs/types.d.ts +2 -1
- package/lib/commands/build-docs/types.d.ts.map +1 -0
- package/lib/commands/build-docs/types.js +2 -2
- package/lib/commands/build-docs/types.js.map +1 -0
- package/lib/commands/build-docs/utils.d.ts +3 -2
- package/lib/commands/build-docs/utils.d.ts.map +1 -0
- package/lib/commands/build-docs/utils.js +35 -37
- package/lib/commands/build-docs/utils.js.map +1 -0
- package/lib/commands/bundle.d.ts +6 -3
- package/lib/commands/bundle.d.ts.map +1 -0
- package/lib/commands/bundle.js +34 -38
- package/lib/commands/bundle.js.map +1 -0
- package/lib/commands/eject.d.ts +3 -2
- package/lib/commands/eject.d.ts.map +1 -0
- package/lib/commands/eject.js +11 -13
- package/lib/commands/eject.js.map +1 -0
- package/lib/commands/join.d.ts +4 -3
- package/lib/commands/join.d.ts.map +1 -0
- package/lib/commands/join.js +79 -81
- package/lib/commands/join.js.map +1 -0
- package/lib/commands/lint.d.ts +8 -6
- package/lib/commands/lint.d.ts.map +1 -0
- package/lib/commands/lint.js +53 -62
- package/lib/commands/lint.js.map +1 -0
- package/lib/commands/preview-project/constants.d.ts +2 -1
- package/lib/commands/preview-project/constants.d.ts.map +1 -0
- package/lib/commands/preview-project/constants.js +4 -6
- package/lib/commands/preview-project/constants.js.map +1 -0
- package/lib/commands/preview-project/index.d.ts +3 -2
- package/lib/commands/preview-project/index.d.ts.map +1 -0
- package/lib/commands/preview-project/index.js +21 -23
- package/lib/commands/preview-project/index.js.map +1 -0
- package/lib/commands/preview-project/types.d.ts +3 -2
- package/lib/commands/preview-project/types.d.ts.map +1 -0
- package/lib/commands/preview-project/types.js +2 -2
- package/lib/commands/preview-project/types.js.map +1 -0
- package/lib/commands/split/index.d.ts +4 -3
- package/lib/commands/split/index.d.ts.map +1 -0
- package/lib/commands/split/index.js +53 -57
- package/lib/commands/split/index.js.map +1 -0
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.d.ts.map +1 -0
- package/lib/commands/split/types.js +11 -13
- package/lib/commands/split/types.js.map +1 -0
- package/lib/commands/stats.d.ts +3 -2
- package/lib/commands/stats.d.ts.map +1 -0
- package/lib/commands/stats.js +21 -24
- package/lib/commands/stats.js.map +1 -0
- package/lib/commands/translations.d.ts +3 -2
- package/lib/commands/translations.d.ts.map +1 -0
- package/lib/commands/translations.js +11 -13
- package/lib/commands/translations.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +109 -239
- package/lib/index.js.map +1 -0
- package/lib/otel.d.ts +2 -1
- package/lib/otel.d.ts.map +1 -0
- package/lib/otel.js +22 -23
- package/lib/otel.js.map +1 -0
- package/lib/reunite/api/api-client.d.ts +4 -3
- package/lib/reunite/api/api-client.d.ts.map +1 -0
- package/lib/reunite/api/api-client.js +14 -20
- package/lib/reunite/api/api-client.js.map +1 -0
- package/lib/reunite/api/api-keys.d.ts +2 -1
- package/lib/reunite/api/api-keys.d.ts.map +1 -0
- package/lib/reunite/api/api-keys.js +4 -20
- package/lib/reunite/api/api-keys.js.map +1 -0
- package/lib/reunite/api/domains.d.ts +5 -2
- package/lib/reunite/api/domains.d.ts.map +1 -0
- package/lib/reunite/api/domains.js +6 -15
- package/lib/reunite/api/domains.js.map +1 -0
- package/lib/reunite/api/index.d.ts +4 -3
- package/lib/reunite/api/index.d.ts.map +1 -0
- package/lib/reunite/api/index.js +4 -19
- package/lib/reunite/api/index.js.map +1 -0
- package/lib/reunite/api/types.d.ts +1 -0
- package/lib/reunite/api/types.d.ts.map +1 -0
- package/lib/reunite/api/types.js +2 -2
- package/lib/reunite/api/types.js.map +1 -0
- package/lib/reunite/commands/push-status.d.ts +6 -5
- package/lib/reunite/commands/push-status.d.ts.map +1 -0
- package/lib/reunite/commands/push-status.js +31 -37
- package/lib/reunite/commands/push-status.js.map +1 -0
- package/lib/reunite/commands/push.d.ts +6 -6
- package/lib/reunite/commands/push.d.ts.map +1 -0
- package/lib/reunite/commands/push.js +31 -40
- package/lib/reunite/commands/push.js.map +1 -0
- package/lib/reunite/commands/utils.d.ts +4 -3
- package/lib/reunite/commands/utils.d.ts.map +1 -0
- package/lib/reunite/commands/utils.js +9 -12
- package/lib/reunite/commands/utils.js.map +1 -0
- package/lib/reunite/utils.d.ts +1 -0
- package/lib/reunite/utils.d.ts.map +1 -0
- package/lib/reunite/utils.js +2 -5
- package/lib/reunite/utils.js.map +1 -0
- package/lib/types.d.ts +15 -27
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -5
- package/lib/types.js.map +1 -0
- package/lib/utils/assert-node-version.d.ts +1 -0
- package/lib/utils/assert-node-version.d.ts.map +1 -0
- package/lib/utils/assert-node-version.js +8 -10
- package/lib/utils/assert-node-version.js.map +1 -0
- package/lib/utils/error.d.ts +4 -0
- package/lib/utils/error.d.ts.map +1 -0
- package/lib/utils/error.js +8 -0
- package/lib/utils/error.js.map +1 -0
- package/lib/utils/fetch-with-timeout.d.ts +1 -0
- package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
- package/lib/utils/fetch-with-timeout.js +6 -8
- package/lib/utils/fetch-with-timeout.js.map +1 -0
- package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
- package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
- package/lib/utils/get-command-name-from-args.js +4 -0
- package/lib/utils/get-command-name-from-args.js.map +1 -0
- package/lib/utils/js-utils.d.ts +1 -0
- package/lib/utils/js-utils.d.ts.map +1 -0
- package/lib/utils/js-utils.js +8 -12
- package/lib/utils/js-utils.js.map +1 -0
- package/lib/utils/miscellaneous.d.ts +9 -48
- package/lib/utils/miscellaneous.d.ts.map +1 -0
- package/lib/utils/miscellaneous.js +131 -269
- package/lib/utils/miscellaneous.js.map +1 -0
- package/lib/utils/package.d.ts +2 -0
- package/lib/utils/package.d.ts.map +1 -0
- package/lib/utils/package.js +4 -0
- package/lib/utils/package.js.map +1 -0
- package/lib/utils/platform.d.ts +1 -0
- package/lib/utils/platform.d.ts.map +1 -0
- package/lib/utils/platform.js +5 -9
- package/lib/utils/platform.js.map +1 -0
- package/lib/utils/proxy-agent.d.ts +3 -0
- package/lib/utils/proxy-agent.d.ts.map +1 -0
- package/lib/utils/proxy-agent.js +6 -0
- package/lib/utils/proxy-agent.js.map +1 -0
- package/lib/utils/spinner.d.ts +1 -0
- package/lib/utils/spinner.d.ts.map +1 -0
- package/lib/utils/spinner.js +8 -10
- package/lib/utils/spinner.js.map +1 -0
- package/lib/utils/telemetry.d.ts +40 -0
- package/lib/utils/telemetry.d.ts.map +1 -0
- package/lib/utils/telemetry.js +138 -0
- package/lib/utils/telemetry.js.map +1 -0
- package/lib/utils/update-version-notifier.d.ts +1 -1
- package/lib/utils/update-version-notifier.d.ts.map +1 -0
- package/lib/utils/update-version-notifier.js +35 -38
- package/lib/utils/update-version-notifier.js.map +1 -0
- package/lib/utils/validate-positive-number.d.ts +2 -0
- package/lib/utils/validate-positive-number.d.ts.map +1 -0
- package/lib/utils/validate-positive-number.js +13 -0
- package/lib/utils/validate-positive-number.js.map +1 -0
- package/lib/wrapper.d.ts +3 -3
- package/lib/wrapper.d.ts.map +1 -0
- package/lib/wrapper.js +39 -26
- package/lib/wrapper.js.map +1 -0
- package/package.json +15 -16
- package/CHANGELOG.md +0 -770
- package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
- package/lib/__mocks__/@redocly/openapi-core.js +0 -84
- package/lib/__mocks__/documents.d.ts +0 -150
- package/lib/__mocks__/documents.js +0 -123
- package/lib/__mocks__/fs.d.ts +0 -8
- package/lib/__mocks__/fs.js +0 -9
- package/lib/__mocks__/perf_hooks.d.ts +0 -3
- package/lib/__mocks__/perf_hooks.js +0 -6
- package/lib/__mocks__/redoc.d.ts +0 -6
- package/lib/__mocks__/redoc.js +0 -5
- package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +0 -54
- package/lib/__tests__/commands/bundle.test.d.ts +0 -1
- package/lib/__tests__/commands/bundle.test.js +0 -235
- package/lib/__tests__/commands/join.test.d.ts +0 -1
- package/lib/__tests__/commands/join.test.js +0 -274
- package/lib/__tests__/commands/lint.test.d.ts +0 -1
- package/lib/__tests__/commands/lint.test.js +0 -149
- package/lib/__tests__/commands/push-region.test.d.ts +0 -1
- package/lib/__tests__/commands/push-region.test.js +0 -90
- package/lib/__tests__/commands/push.test.d.ts +0 -1
- package/lib/__tests__/commands/push.test.js +0 -496
- package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
- package/lib/__tests__/fetch-with-timeout.test.js +0 -64
- package/lib/__tests__/fixtures/config.d.ts +0 -21
- package/lib/__tests__/fixtures/config.js +0 -24
- package/lib/__tests__/spinner.test.d.ts +0 -1
- package/lib/__tests__/spinner.test.js +0 -43
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -651
- package/lib/__tests__/wrapper.test.d.ts +0 -1
- package/lib/__tests__/wrapper.test.js +0 -76
- package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
- package/lib/auth/__tests__/device-flow.test.js +0 -62
- package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
- package/lib/auth/__tests__/oauth-client.test.js +0 -93
- package/lib/commands/preview-docs/index.d.ts +0 -12
- package/lib/commands/preview-docs/index.js +0 -127
- package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
- package/lib/commands/preview-docs/preview-server/hot.js +0 -59
- package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
- package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
- package/lib/commands/preview-docs/preview-server/server.js +0 -85
- package/lib/commands/push.d.ts +0 -44
- package/lib/commands/push.js +0 -301
- package/lib/commands/split/__tests__/index.test.d.ts +0 -1
- package/lib/commands/split/__tests__/index.test.js +0 -91
- package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
- package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/api.client.test.js +0 -337
- package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
- package/lib/reunite/api/__tests__/domains.test.js +0 -32
- package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
- package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/push.test.js +0 -315
- package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
- package/lib/reunite/commands/__tests__/utils.test.js +0 -51
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
- package/lib/utils/__mocks__/miscellaneous.js +0 -24
- package/lib/utils/getCommandNameFromArgs.js +0 -6
- package/src/__mocks__/@redocly/openapi-core.ts +0 -88
- package/src/__mocks__/documents.ts +0 -124
- package/src/__mocks__/fs.ts +0 -6
- package/src/__mocks__/perf_hooks.ts +0 -3
- package/src/__mocks__/redoc.ts +0 -2
- package/src/__tests__/commands/build-docs.test.ts +0 -59
- package/src/__tests__/commands/bundle.test.ts +0 -285
- package/src/__tests__/commands/join.test.ts +0 -334
- package/src/__tests__/commands/lint.test.ts +0 -190
- package/src/__tests__/commands/push-region.test.ts +0 -104
- package/src/__tests__/commands/push.test.ts +0 -553
- package/src/__tests__/fetch-with-timeout.test.ts +0 -81
- package/src/__tests__/fixtures/config.ts +0 -21
- package/src/__tests__/fixtures/openapi.json +0 -0
- package/src/__tests__/fixtures/openapi.yaml +0 -0
- package/src/__tests__/fixtures/redocly.yaml +0 -0
- package/src/__tests__/spinner.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -781
- package/src/__tests__/wrapper.test.ts +0 -91
- package/src/auth/__tests__/device-flow.test.ts +0 -73
- package/src/auth/__tests__/oauth-client.test.ts +0 -117
- package/src/auth/device-flow.ts +0 -175
- package/src/auth/oauth-client.ts +0 -111
- package/src/commands/auth.ts +0 -66
- package/src/commands/build-docs/index.ts +0 -55
- package/src/commands/build-docs/template.hbs +0 -23
- package/src/commands/build-docs/types.ts +0 -25
- package/src/commands/build-docs/utils.ts +0 -110
- package/src/commands/bundle.ts +0 -154
- package/src/commands/eject.ts +0 -42
- package/src/commands/join.ts +0 -794
- package/src/commands/lint.ts +0 -169
- package/src/commands/preview-docs/index.ts +0 -183
- package/src/commands/preview-docs/preview-server/default.hbs +0 -24
- package/src/commands/preview-docs/preview-server/hot.js +0 -59
- package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
- package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
- package/src/commands/preview-docs/preview-server/server.ts +0 -92
- package/src/commands/preview-project/constants.ts +0 -23
- package/src/commands/preview-project/index.ts +0 -71
- package/src/commands/preview-project/types.ts +0 -12
- package/src/commands/push.ts +0 -470
- package/src/commands/split/__tests__/fixtures/samples.json +0 -61
- package/src/commands/split/__tests__/fixtures/spec.json +0 -70
- package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
- package/src/commands/split/__tests__/index.test.ts +0 -156
- package/src/commands/split/index.ts +0 -397
- package/src/commands/split/types.ts +0 -60
- package/src/commands/stats.ts +0 -140
- package/src/commands/translations.ts +0 -32
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -970
- package/src/otel.ts +0 -59
- package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
- package/src/reunite/api/__tests__/api.client.test.ts +0 -452
- package/src/reunite/api/__tests__/domains.test.ts +0 -41
- package/src/reunite/api/api-client.ts +0 -381
- package/src/reunite/api/api-keys.ts +0 -26
- package/src/reunite/api/domains.ts +0 -23
- package/src/reunite/api/index.ts +0 -3
- package/src/reunite/api/types.ts +0 -108
- package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
- package/src/reunite/commands/__tests__/push.test.ts +0 -385
- package/src/reunite/commands/__tests__/utils.test.ts +0 -62
- package/src/reunite/commands/push-status.ts +0 -325
- package/src/reunite/commands/push.ts +0 -235
- package/src/reunite/commands/utils.ts +0 -66
- package/src/reunite/utils.ts +0 -1
- package/src/types.ts +0 -64
- package/src/utils/__mocks__/miscellaneous.ts +0 -24
- package/src/utils/assert-node-version.ts +0 -19
- package/src/utils/fetch-with-timeout.ts +0 -30
- package/src/utils/getCommandNameFromArgs.ts +0 -5
- package/src/utils/js-utils.ts +0 -24
- package/src/utils/miscellaneous.ts +0 -729
- package/src/utils/platform.ts +0 -31
- package/src/utils/spinner.ts +0 -50
- package/src/utils/update-version-notifier.ts +0 -115
- package/src/wrapper.ts +0 -77
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf8" />
|
|
6
|
-
<title>{{title}}</title>
|
|
7
|
-
<!-- needed for adaptive design -->
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
-
<style>
|
|
10
|
-
body {
|
|
11
|
-
padding: 0;
|
|
12
|
-
margin: 0;
|
|
13
|
-
}
|
|
14
|
-
</style>
|
|
15
|
-
{{{redocHead}}}
|
|
16
|
-
{{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
{{{redocHTML}}}
|
|
21
|
-
</body>
|
|
22
|
-
|
|
23
|
-
</html>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { VerifyConfigOptions } from '../../types';
|
|
2
|
-
|
|
3
|
-
export type BuildDocsOptions = {
|
|
4
|
-
watch?: boolean;
|
|
5
|
-
output?: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
disableGoogleFont?: boolean;
|
|
8
|
-
port?: number;
|
|
9
|
-
templateFileName?: string;
|
|
10
|
-
templateOptions?: any;
|
|
11
|
-
redocOptions?: any;
|
|
12
|
-
redocCurrentVersion: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type BuildDocsArgv = {
|
|
16
|
-
api: string;
|
|
17
|
-
o: string;
|
|
18
|
-
title?: string;
|
|
19
|
-
disableGoogleFont?: boolean;
|
|
20
|
-
template?: string;
|
|
21
|
-
templateOptions: Record<string, any>;
|
|
22
|
-
theme: {
|
|
23
|
-
openapi: string | Record<string, unknown>;
|
|
24
|
-
};
|
|
25
|
-
} & VerifyConfigOptions;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
import { createStore, Redoc } from 'redoc';
|
|
3
|
-
import { renderToString } from 'react-dom/server';
|
|
4
|
-
import { ServerStyleSheet } from 'styled-components';
|
|
5
|
-
import { compile } from 'handlebars';
|
|
6
|
-
import { dirname, join, resolve } from 'path';
|
|
7
|
-
import { existsSync, lstatSync, readFileSync } from 'fs';
|
|
8
|
-
import { red } from 'colorette';
|
|
9
|
-
import { isAbsoluteUrl } from '@redocly/openapi-core';
|
|
10
|
-
import { exitWithError } from '../../utils/miscellaneous';
|
|
11
|
-
|
|
12
|
-
import type { Config } from '@redocly/openapi-core';
|
|
13
|
-
import type { BuildDocsOptions } from './types';
|
|
14
|
-
|
|
15
|
-
export function getObjectOrJSON(
|
|
16
|
-
openapiOptions: string | Record<string, unknown>,
|
|
17
|
-
config: Config
|
|
18
|
-
): JSON | Record<string, unknown> | Config {
|
|
19
|
-
switch (typeof openapiOptions) {
|
|
20
|
-
case 'object':
|
|
21
|
-
return openapiOptions;
|
|
22
|
-
case 'string':
|
|
23
|
-
try {
|
|
24
|
-
if (existsSync(openapiOptions) && lstatSync(openapiOptions).isFile()) {
|
|
25
|
-
return JSON.parse(readFileSync(openapiOptions, 'utf-8'));
|
|
26
|
-
} else {
|
|
27
|
-
return JSON.parse(openapiOptions);
|
|
28
|
-
}
|
|
29
|
-
} catch (e) {
|
|
30
|
-
process.stderr.write(
|
|
31
|
-
red(
|
|
32
|
-
`Encountered error:\n\n${openapiOptions}\n\nis neither a file with a valid JSON object neither a stringified JSON object.`
|
|
33
|
-
)
|
|
34
|
-
);
|
|
35
|
-
exitWithError(e);
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
default: {
|
|
39
|
-
if (config) {
|
|
40
|
-
process.stdout.write(`Found ${config.configFile} and using theme.openapi options\n`);
|
|
41
|
-
|
|
42
|
-
return config.theme.openapi ? config.theme.openapi : {};
|
|
43
|
-
}
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function getPageHTML(
|
|
51
|
-
api: any,
|
|
52
|
-
pathToApi: string,
|
|
53
|
-
{
|
|
54
|
-
title,
|
|
55
|
-
disableGoogleFont,
|
|
56
|
-
templateFileName,
|
|
57
|
-
templateOptions,
|
|
58
|
-
redocOptions = {},
|
|
59
|
-
redocCurrentVersion,
|
|
60
|
-
}: BuildDocsOptions,
|
|
61
|
-
configPath?: string
|
|
62
|
-
) {
|
|
63
|
-
process.stdout.write('Prerendering docs\n');
|
|
64
|
-
|
|
65
|
-
const apiUrl = redocOptions.specUrl || (isAbsoluteUrl(pathToApi) ? pathToApi : undefined);
|
|
66
|
-
const store = await createStore(api, apiUrl, redocOptions);
|
|
67
|
-
const sheet = new ServerStyleSheet();
|
|
68
|
-
|
|
69
|
-
const html = renderToString(sheet.collectStyles(createElement(Redoc, { store })));
|
|
70
|
-
const state = await store.toJS();
|
|
71
|
-
const css = sheet.getStyleTags();
|
|
72
|
-
|
|
73
|
-
templateFileName = templateFileName
|
|
74
|
-
? templateFileName
|
|
75
|
-
: redocOptions?.htmlTemplate
|
|
76
|
-
? resolve(configPath ? dirname(configPath) : '', redocOptions.htmlTemplate)
|
|
77
|
-
: join(__dirname, './template.hbs');
|
|
78
|
-
const template = compile(readFileSync(templateFileName).toString());
|
|
79
|
-
return template({
|
|
80
|
-
redocHTML: `
|
|
81
|
-
<div id="redoc">${html || ''}</div>
|
|
82
|
-
<script>
|
|
83
|
-
${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}
|
|
84
|
-
|
|
85
|
-
var container = document.getElementById('redoc');
|
|
86
|
-
Redoc.${'hydrate(__redoc_state, container)'};
|
|
87
|
-
|
|
88
|
-
</script>`,
|
|
89
|
-
redocHead:
|
|
90
|
-
`<script src="https://cdn.redocly.com/redoc/v${redocCurrentVersion}/bundles/redoc.standalone.js"></script>` +
|
|
91
|
-
css,
|
|
92
|
-
title: title || api.info.title || 'ReDoc documentation',
|
|
93
|
-
disableGoogleFont,
|
|
94
|
-
templateOptions,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function sanitizeJSONString(str: string): string {
|
|
99
|
-
return escapeClosingScriptTag(escapeUnicode(str));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
|
|
103
|
-
export function escapeClosingScriptTag(str: string): string {
|
|
104
|
-
return str.replace(/<\/script>/g, '<\\/script>');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
|
|
108
|
-
export function escapeUnicode(str: string): string {
|
|
109
|
-
return str.replace(/\u2028|\u2029/g, (m) => '\\u202' + (m === '\u2028' ? '8' : '9'));
|
|
110
|
-
}
|
package/src/commands/bundle.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { performance } from 'perf_hooks';
|
|
2
|
-
import { blue, gray, green, yellow } from 'colorette';
|
|
3
|
-
import { writeFileSync } from 'fs';
|
|
4
|
-
import { formatProblems, getTotals, getMergedConfig, bundle } from '@redocly/openapi-core';
|
|
5
|
-
import {
|
|
6
|
-
dumpBundle,
|
|
7
|
-
getExecutionTime,
|
|
8
|
-
getFallbackApisOrExit,
|
|
9
|
-
getOutputFileName,
|
|
10
|
-
handleError,
|
|
11
|
-
printUnusedWarnings,
|
|
12
|
-
saveBundle,
|
|
13
|
-
sortTopLevelKeysForOas,
|
|
14
|
-
checkForDeprecatedOptions,
|
|
15
|
-
formatPath,
|
|
16
|
-
} from '../utils/miscellaneous';
|
|
17
|
-
|
|
18
|
-
import type { OutputExtensions, Skips, Totals, VerifyConfigOptions } from '../types';
|
|
19
|
-
import type { CommandArgs } from '../wrapper';
|
|
20
|
-
|
|
21
|
-
export type BundleOptions = {
|
|
22
|
-
apis?: string[];
|
|
23
|
-
extends?: string[];
|
|
24
|
-
output?: string;
|
|
25
|
-
ext?: OutputExtensions;
|
|
26
|
-
dereferenced?: boolean;
|
|
27
|
-
force?: boolean;
|
|
28
|
-
metafile?: string;
|
|
29
|
-
'remove-unused-components'?: boolean;
|
|
30
|
-
'keep-url-references'?: boolean;
|
|
31
|
-
} & Skips &
|
|
32
|
-
VerifyConfigOptions;
|
|
33
|
-
|
|
34
|
-
export async function handleBundle({
|
|
35
|
-
argv,
|
|
36
|
-
config,
|
|
37
|
-
version,
|
|
38
|
-
collectSpecData,
|
|
39
|
-
}: CommandArgs<BundleOptions>) {
|
|
40
|
-
const removeUnusedComponents =
|
|
41
|
-
argv['remove-unused-components'] ||
|
|
42
|
-
config.rawConfig?.styleguide?.decorators?.hasOwnProperty('remove-unused-components');
|
|
43
|
-
const apis = await getFallbackApisOrExit(argv.apis, config);
|
|
44
|
-
const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
|
|
45
|
-
const deprecatedOptions: Array<keyof BundleOptions> = [];
|
|
46
|
-
|
|
47
|
-
checkForDeprecatedOptions(argv, deprecatedOptions);
|
|
48
|
-
|
|
49
|
-
for (const { path, alias, output } of apis) {
|
|
50
|
-
try {
|
|
51
|
-
const startedAt = performance.now();
|
|
52
|
-
const resolvedConfig = getMergedConfig(config, alias);
|
|
53
|
-
const { styleguide } = resolvedConfig;
|
|
54
|
-
|
|
55
|
-
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
56
|
-
styleguide.skipDecorators(argv['skip-decorator']);
|
|
57
|
-
|
|
58
|
-
process.stderr.write(gray(`bundling ${formatPath(path)}...\n`));
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
bundle: result,
|
|
62
|
-
problems,
|
|
63
|
-
...meta
|
|
64
|
-
} = await bundle({
|
|
65
|
-
config: resolvedConfig,
|
|
66
|
-
ref: path,
|
|
67
|
-
dereference: argv.dereferenced,
|
|
68
|
-
removeUnusedComponents,
|
|
69
|
-
keepUrlRefs: argv['keep-url-references'],
|
|
70
|
-
collectSpecData,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const fileTotals = getTotals(problems);
|
|
74
|
-
const { outputFile, ext } = getOutputFileName({
|
|
75
|
-
entrypoint: path,
|
|
76
|
-
output,
|
|
77
|
-
argvOutput: argv.output,
|
|
78
|
-
ext: argv.ext,
|
|
79
|
-
entries: argv?.apis?.length || 0,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (fileTotals.errors === 0 || argv.force) {
|
|
83
|
-
if (!outputFile) {
|
|
84
|
-
const bundled = dumpBundle(
|
|
85
|
-
sortTopLevelKeysForOas(result.parsed),
|
|
86
|
-
argv.ext || 'yaml',
|
|
87
|
-
argv.dereferenced
|
|
88
|
-
);
|
|
89
|
-
process.stdout.write(bundled);
|
|
90
|
-
} else {
|
|
91
|
-
const bundled = dumpBundle(sortTopLevelKeysForOas(result.parsed), ext, argv.dereferenced);
|
|
92
|
-
saveBundle(outputFile, bundled);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
totals.errors += fileTotals.errors;
|
|
97
|
-
totals.warnings += fileTotals.warnings;
|
|
98
|
-
totals.ignored += fileTotals.ignored;
|
|
99
|
-
|
|
100
|
-
formatProblems(problems, {
|
|
101
|
-
format: 'codeframe',
|
|
102
|
-
totals: fileTotals,
|
|
103
|
-
version,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
if (argv.metafile) {
|
|
107
|
-
if (apis.length > 1) {
|
|
108
|
-
process.stderr.write(
|
|
109
|
-
yellow(`[WARNING] "--metafile" cannot be used with multiple apis. Skipping...`)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
{
|
|
113
|
-
writeFileSync(argv.metafile, JSON.stringify(meta), 'utf-8');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const elapsed = getExecutionTime(startedAt);
|
|
118
|
-
if (fileTotals.errors > 0) {
|
|
119
|
-
if (argv.force) {
|
|
120
|
-
process.stderr.write(
|
|
121
|
-
`❓ Created a bundle for ${blue(formatPath(path))} at ${blue(
|
|
122
|
-
outputFile || 'stdout'
|
|
123
|
-
)} with errors ${green(elapsed)}.\n${yellow('Errors ignored because of --force')}.\n`
|
|
124
|
-
);
|
|
125
|
-
} else {
|
|
126
|
-
process.stderr.write(
|
|
127
|
-
`❌ Errors encountered while bundling ${blue(
|
|
128
|
-
formatPath(path)
|
|
129
|
-
)}: bundle not created (use --force to ignore errors).\n`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
process.stderr.write(
|
|
134
|
-
`📦 Created a bundle for ${blue(formatPath(path))} at ${blue(
|
|
135
|
-
outputFile || 'stdout'
|
|
136
|
-
)} ${green(elapsed)}.\n`
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const removedCount = meta.visitorsData?.['remove-unused-components']?.removedCount;
|
|
141
|
-
if (removedCount) {
|
|
142
|
-
process.stderr.write(gray(`🧹 Removed ${removedCount} unused components.\n`));
|
|
143
|
-
}
|
|
144
|
-
} catch (e) {
|
|
145
|
-
handleError(e, path);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
printUnusedWarnings(config.styleguide);
|
|
150
|
-
|
|
151
|
-
if (!(totals.errors === 0 || argv.force)) {
|
|
152
|
-
throw new Error('Bundle failed.');
|
|
153
|
-
}
|
|
154
|
-
}
|
package/src/commands/eject.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import { getPlatformSpawnArgs, sanitizePath } from '../utils/platform';
|
|
3
|
-
|
|
4
|
-
import type { CommandArgs } from '../wrapper';
|
|
5
|
-
import type { VerifyConfigOptions } from '../types';
|
|
6
|
-
|
|
7
|
-
export type EjectOptions = {
|
|
8
|
-
type: 'component';
|
|
9
|
-
path?: string;
|
|
10
|
-
'project-dir'?: string;
|
|
11
|
-
force: boolean;
|
|
12
|
-
} & VerifyConfigOptions;
|
|
13
|
-
|
|
14
|
-
export const handleEject = async ({ argv }: CommandArgs<EjectOptions>) => {
|
|
15
|
-
process.stdout.write(`\nLaunching eject using NPX.\n\n`);
|
|
16
|
-
const { npxExecutableName, sanitize, shell } = getPlatformSpawnArgs();
|
|
17
|
-
|
|
18
|
-
const path = sanitize(argv.path, sanitizePath);
|
|
19
|
-
const projectDir = sanitize(argv['project-dir'], sanitizePath);
|
|
20
|
-
|
|
21
|
-
const child = spawn(
|
|
22
|
-
npxExecutableName,
|
|
23
|
-
[
|
|
24
|
-
'-y',
|
|
25
|
-
'@redocly/realm',
|
|
26
|
-
'eject',
|
|
27
|
-
`${argv.type}`,
|
|
28
|
-
path,
|
|
29
|
-
`-d=${projectDir}`,
|
|
30
|
-
argv.force ? `--force=${argv.force}` : '',
|
|
31
|
-
],
|
|
32
|
-
{
|
|
33
|
-
stdio: 'inherit',
|
|
34
|
-
shell,
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
child.on('error', (error) => {
|
|
39
|
-
process.stderr.write(`Eject launch failed: ${error.message}`);
|
|
40
|
-
throw new Error('Eject launch failed.');
|
|
41
|
-
});
|
|
42
|
-
};
|