@redocly/cli 1.34.4 → 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 +16 -17
- package/CHANGELOG.md +0 -777
- 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
package/src/commands/lint.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { blue, gray } from 'colorette';
|
|
2
|
-
import { performance } from 'perf_hooks';
|
|
3
|
-
import {
|
|
4
|
-
formatProblems,
|
|
5
|
-
getMergedConfig,
|
|
6
|
-
getTotals,
|
|
7
|
-
lint,
|
|
8
|
-
lintConfig,
|
|
9
|
-
} from '@redocly/openapi-core';
|
|
10
|
-
import { ConfigValidationError } from '@redocly/openapi-core/lib/config';
|
|
11
|
-
import { pluralize } from '@redocly/openapi-core/lib/utils';
|
|
12
|
-
import {
|
|
13
|
-
checkIfRulesetExist,
|
|
14
|
-
exitWithError,
|
|
15
|
-
formatPath,
|
|
16
|
-
getExecutionTime,
|
|
17
|
-
getFallbackApisOrExit,
|
|
18
|
-
handleError,
|
|
19
|
-
notifyAboutIncompatibleConfigOptions,
|
|
20
|
-
printConfigLintTotals,
|
|
21
|
-
printLintTotals,
|
|
22
|
-
printUnusedWarnings,
|
|
23
|
-
} from '../utils/miscellaneous';
|
|
24
|
-
import { getCommandNameFromArgs } from '../utils/getCommandNameFromArgs';
|
|
25
|
-
|
|
26
|
-
import type { Arguments } from 'yargs';
|
|
27
|
-
import type { OutputFormat, ProblemSeverity } from '@redocly/openapi-core';
|
|
28
|
-
import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
|
|
29
|
-
import type { CommandOptions, Skips, Totals, VerifyConfigOptions } from '../types';
|
|
30
|
-
import type { CommandArgs } from '../wrapper';
|
|
31
|
-
|
|
32
|
-
export type LintOptions = {
|
|
33
|
-
apis?: string[];
|
|
34
|
-
'max-problems': number;
|
|
35
|
-
extends?: string[];
|
|
36
|
-
format: OutputFormat;
|
|
37
|
-
'generate-ignore-file'?: boolean;
|
|
38
|
-
} & Omit<Skips, 'skip-decorator'> &
|
|
39
|
-
VerifyConfigOptions;
|
|
40
|
-
|
|
41
|
-
export async function handleLint({
|
|
42
|
-
argv,
|
|
43
|
-
config,
|
|
44
|
-
version,
|
|
45
|
-
collectSpecData,
|
|
46
|
-
}: CommandArgs<LintOptions>) {
|
|
47
|
-
const apis = await getFallbackApisOrExit(argv.apis, config);
|
|
48
|
-
|
|
49
|
-
if (!apis.length) {
|
|
50
|
-
exitWithError('No APIs were provided.');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (argv['generate-ignore-file']) {
|
|
54
|
-
config.styleguide.ignore = {}; // clear ignore
|
|
55
|
-
}
|
|
56
|
-
const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
|
|
57
|
-
let totalIgnored = 0;
|
|
58
|
-
|
|
59
|
-
// TODO: use shared externalRef resolver, blocked by preprocessors now as they can mutate documents
|
|
60
|
-
for (const { path, alias } of apis) {
|
|
61
|
-
try {
|
|
62
|
-
const startedAt = performance.now();
|
|
63
|
-
const resolvedConfig = getMergedConfig(config, alias);
|
|
64
|
-
const { styleguide } = resolvedConfig;
|
|
65
|
-
|
|
66
|
-
checkIfRulesetExist(styleguide.rules);
|
|
67
|
-
|
|
68
|
-
styleguide.skipRules(argv['skip-rule']);
|
|
69
|
-
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
70
|
-
|
|
71
|
-
if (styleguide.recommendedFallback) {
|
|
72
|
-
process.stderr.write(
|
|
73
|
-
`No configurations were provided -- using built in ${blue(
|
|
74
|
-
'recommended'
|
|
75
|
-
)} configuration by default.\n\n`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
process.stderr.write(gray(`validating ${formatPath(path)}...\n`));
|
|
79
|
-
const results = await lint({
|
|
80
|
-
ref: path,
|
|
81
|
-
config: resolvedConfig,
|
|
82
|
-
collectSpecData,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const fileTotals = getTotals(results);
|
|
86
|
-
totals.errors += fileTotals.errors;
|
|
87
|
-
totals.warnings += fileTotals.warnings;
|
|
88
|
-
totals.ignored += fileTotals.ignored;
|
|
89
|
-
|
|
90
|
-
if (argv['generate-ignore-file']) {
|
|
91
|
-
for (const m of results) {
|
|
92
|
-
config.styleguide.addIgnore(m);
|
|
93
|
-
totalIgnored++;
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
formatProblems(results, {
|
|
97
|
-
format: argv.format,
|
|
98
|
-
maxProblems: argv['max-problems'],
|
|
99
|
-
totals: fileTotals,
|
|
100
|
-
version,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const elapsed = getExecutionTime(startedAt);
|
|
105
|
-
process.stderr.write(gray(`${formatPath(path)}: validated in ${elapsed}\n\n`));
|
|
106
|
-
} catch (e) {
|
|
107
|
-
handleError(e, path);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (argv['generate-ignore-file']) {
|
|
112
|
-
config.styleguide.saveIgnore();
|
|
113
|
-
process.stderr.write(
|
|
114
|
-
`Generated ignore file with ${totalIgnored} ${pluralize('problem', totalIgnored)}.\n\n`
|
|
115
|
-
);
|
|
116
|
-
} else {
|
|
117
|
-
printLintTotals(totals, apis.length);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
printUnusedWarnings(config.styleguide);
|
|
121
|
-
|
|
122
|
-
if (!(totals.errors === 0 || argv['generate-ignore-file'])) {
|
|
123
|
-
throw new Error('Lint failed.');
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function lintConfigCallback(
|
|
128
|
-
argv: CommandOptions & Record<string, undefined>,
|
|
129
|
-
version: string
|
|
130
|
-
): RawConfigProcessor | undefined {
|
|
131
|
-
if (argv['lint-config'] === 'off') {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (argv.format === 'json') {
|
|
136
|
-
// we can't print config lint results as it will break json output
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return async ({ document, resolvedRefMap, config, parsed: { theme = {} } }) => {
|
|
141
|
-
const command = argv ? getCommandNameFromArgs(argv as Arguments) : undefined;
|
|
142
|
-
|
|
143
|
-
if (command === 'check-config') {
|
|
144
|
-
notifyAboutIncompatibleConfigOptions(theme.openapi);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const problems = await lintConfig({
|
|
148
|
-
document,
|
|
149
|
-
resolvedRefMap,
|
|
150
|
-
config,
|
|
151
|
-
severity: (argv['lint-config'] || 'warn') as ProblemSeverity,
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const fileTotals = getTotals(problems);
|
|
155
|
-
|
|
156
|
-
formatProblems(problems, {
|
|
157
|
-
format: argv.format,
|
|
158
|
-
maxProblems: argv['max-problems'],
|
|
159
|
-
totals: fileTotals,
|
|
160
|
-
version,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
printConfigLintTotals(fileTotals, command);
|
|
164
|
-
|
|
165
|
-
if (fileTotals.errors > 0) {
|
|
166
|
-
throw new ConfigValidationError();
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import * as colorette from 'colorette';
|
|
2
|
-
import * as chockidar from 'chokidar';
|
|
3
|
-
import { bundle, RedoclyClient, getTotals, getMergedConfig, Config } from '@redocly/openapi-core';
|
|
4
|
-
import {
|
|
5
|
-
getFallbackApisOrExit,
|
|
6
|
-
handleError,
|
|
7
|
-
loadConfigAndHandleErrors,
|
|
8
|
-
} from '../../utils/miscellaneous';
|
|
9
|
-
import startPreviewServer from './preview-server/preview-server';
|
|
10
|
-
|
|
11
|
-
import type { Skips, VerifyConfigOptions } from '../../types';
|
|
12
|
-
import type { CommandArgs } from '../../wrapper';
|
|
13
|
-
|
|
14
|
-
export type PreviewDocsOptions = {
|
|
15
|
-
port: number;
|
|
16
|
-
host: string;
|
|
17
|
-
'use-community-edition'?: boolean;
|
|
18
|
-
config?: string;
|
|
19
|
-
api?: string;
|
|
20
|
-
force?: boolean;
|
|
21
|
-
} & Omit<Skips, 'skip-rule'> &
|
|
22
|
-
VerifyConfigOptions;
|
|
23
|
-
|
|
24
|
-
export async function previewDocs({
|
|
25
|
-
argv,
|
|
26
|
-
config: configFromFile,
|
|
27
|
-
}: CommandArgs<PreviewDocsOptions>) {
|
|
28
|
-
let isAuthorizedWithRedocly = false;
|
|
29
|
-
let redocOptions: any = {};
|
|
30
|
-
let config = await reloadConfig(configFromFile);
|
|
31
|
-
|
|
32
|
-
const apis = await getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
|
|
33
|
-
const api = apis[0];
|
|
34
|
-
|
|
35
|
-
let cachedBundle: any;
|
|
36
|
-
const deps = new Set<string>();
|
|
37
|
-
|
|
38
|
-
async function getBundle() {
|
|
39
|
-
return cachedBundle;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function updateBundle() {
|
|
43
|
-
process.stdout.write('\nBundling...\n\n');
|
|
44
|
-
try {
|
|
45
|
-
const {
|
|
46
|
-
bundle: openapiBundle,
|
|
47
|
-
problems,
|
|
48
|
-
fileDependencies,
|
|
49
|
-
} = await bundle({
|
|
50
|
-
ref: api.path,
|
|
51
|
-
config,
|
|
52
|
-
});
|
|
53
|
-
const removed = [...deps].filter((x) => !fileDependencies.has(x));
|
|
54
|
-
watcher.unwatch(removed);
|
|
55
|
-
watcher.add([...fileDependencies]);
|
|
56
|
-
deps.clear();
|
|
57
|
-
fileDependencies.forEach(deps.add, deps);
|
|
58
|
-
|
|
59
|
-
const fileTotals = getTotals(problems);
|
|
60
|
-
|
|
61
|
-
if (fileTotals.errors === 0) {
|
|
62
|
-
process.stdout.write(
|
|
63
|
-
fileTotals.errors === 0
|
|
64
|
-
? `Created a bundle for ${api.alias || api.path} ${
|
|
65
|
-
fileTotals.warnings > 0 ? 'with warnings' : 'successfully'
|
|
66
|
-
}\n`
|
|
67
|
-
: colorette.yellow(
|
|
68
|
-
`Created a bundle for ${
|
|
69
|
-
api.alias || api.path
|
|
70
|
-
} with errors. Docs may be broken or not accurate\n`
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return openapiBundle.parsed;
|
|
76
|
-
} catch (e) {
|
|
77
|
-
handleError(e, api.path);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
setImmediate(() => {
|
|
82
|
-
cachedBundle = updateBundle();
|
|
83
|
-
}); // initial cache
|
|
84
|
-
|
|
85
|
-
const isAuthorized = isAuthorizedWithRedocly || redocOptions.licenseKey;
|
|
86
|
-
if (!isAuthorized) {
|
|
87
|
-
process.stderr.write(
|
|
88
|
-
`Using Redoc community edition.\nLogin with redocly ${colorette.blue(
|
|
89
|
-
'login'
|
|
90
|
-
)} or use an enterprise license key to preview with the premium docs.\n\n`
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const hotClients = await startPreviewServer(argv.port, argv.host, {
|
|
95
|
-
getBundle,
|
|
96
|
-
getOptions: () => redocOptions,
|
|
97
|
-
useRedocPro: isAuthorized && !redocOptions.useCommunityEdition,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const watchPaths = [api.path, config.configFile!].filter((e) => !!e);
|
|
101
|
-
const watcher = chockidar.watch(watchPaths, {
|
|
102
|
-
disableGlobbing: true,
|
|
103
|
-
ignoreInitial: true,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const debouncedUpdatedBundle = debounce(async () => {
|
|
107
|
-
cachedBundle = updateBundle();
|
|
108
|
-
await cachedBundle;
|
|
109
|
-
hotClients.broadcast('{"type": "reload", "bundle": true}');
|
|
110
|
-
}, 2000);
|
|
111
|
-
|
|
112
|
-
const changeHandler = async (type: string, file: string) => {
|
|
113
|
-
process.stdout.write(`${colorette.green('watch')} ${type} ${colorette.blue(file)}\n`);
|
|
114
|
-
if (file === config.configFile) {
|
|
115
|
-
config = await reloadConfig();
|
|
116
|
-
hotClients.broadcast(JSON.stringify({ type: 'reload' }));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
debouncedUpdatedBundle();
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
watcher.on('change', changeHandler.bind(undefined, 'changed'));
|
|
124
|
-
watcher.on('add', changeHandler.bind(undefined, 'added'));
|
|
125
|
-
watcher.on('unlink', changeHandler.bind(undefined, 'removed'));
|
|
126
|
-
|
|
127
|
-
watcher.on('ready', () => {
|
|
128
|
-
process.stdout.write(
|
|
129
|
-
`\n 👀 Watching ${colorette.blue(api.path)} and all related resources for changes\n\n`
|
|
130
|
-
);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
async function reloadConfig(config?: Config) {
|
|
134
|
-
if (!config) {
|
|
135
|
-
try {
|
|
136
|
-
config = (await loadConfigAndHandleErrors({ configPath: argv.config })) as Config;
|
|
137
|
-
} catch (err) {
|
|
138
|
-
config = new Config({ apis: {}, styleguide: {} });
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const redoclyClient = new RedoclyClient();
|
|
142
|
-
isAuthorizedWithRedocly = await redoclyClient.isAuthorizedWithRedocly();
|
|
143
|
-
const resolvedConfig = getMergedConfig(config, argv.api);
|
|
144
|
-
const { styleguide } = resolvedConfig;
|
|
145
|
-
|
|
146
|
-
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
147
|
-
styleguide.skipDecorators(argv['skip-decorator']);
|
|
148
|
-
|
|
149
|
-
const referenceDocs = resolvedConfig.theme?.openapi;
|
|
150
|
-
redocOptions = {
|
|
151
|
-
...referenceDocs,
|
|
152
|
-
useCommunityEdition: argv['use-community-edition'] || referenceDocs?.useCommunityEdition,
|
|
153
|
-
licenseKey: process.env.REDOCLY_LICENSE_KEY || referenceDocs?.licenseKey,
|
|
154
|
-
whiteLabel: true,
|
|
155
|
-
};
|
|
156
|
-
return resolvedConfig;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
161
|
-
export function debounce(func: Function, wait: number, immediate?: boolean) {
|
|
162
|
-
let timeout: NodeJS.Timeout | null;
|
|
163
|
-
|
|
164
|
-
return function executedFunction(...args: any[]) {
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
168
|
-
const context = this;
|
|
169
|
-
|
|
170
|
-
const later = () => {
|
|
171
|
-
timeout = null;
|
|
172
|
-
if (!immediate) func.apply(context, args);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const callNow = immediate && !timeout;
|
|
176
|
-
|
|
177
|
-
if (timeout) clearTimeout(timeout);
|
|
178
|
-
|
|
179
|
-
timeout = setTimeout(later, wait);
|
|
180
|
-
|
|
181
|
-
if (callNow) func.apply(context, args);
|
|
182
|
-
};
|
|
183
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!DOCTYPE html>
|
|
3
|
-
<html>
|
|
4
|
-
|
|
5
|
-
<head>
|
|
6
|
-
<meta charset="utf8" />
|
|
7
|
-
<title>{{title}}</title>
|
|
8
|
-
<!-- needed for adaptive design -->
|
|
9
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
-
<style>
|
|
11
|
-
body {
|
|
12
|
-
padding: 0;
|
|
13
|
-
margin: 0;
|
|
14
|
-
}
|
|
15
|
-
</style>
|
|
16
|
-
{{{redocHead}}}
|
|
17
|
-
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
|
|
18
|
-
</head>
|
|
19
|
-
|
|
20
|
-
<body>
|
|
21
|
-
{{{redocHTML}}}
|
|
22
|
-
</body>
|
|
23
|
-
|
|
24
|
-
</html>
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
(function run() {
|
|
2
|
-
const Socket = window.SimpleWebsocket;
|
|
3
|
-
const port = window.__OPENAPI_CLI_WS_PORT;
|
|
4
|
-
const host = window.__OPENAPI_CLI_WS_HOST;
|
|
5
|
-
|
|
6
|
-
let socket;
|
|
7
|
-
|
|
8
|
-
reconnect();
|
|
9
|
-
|
|
10
|
-
function getFormattedHost() {
|
|
11
|
-
// Use localhost when bound to all interfaces
|
|
12
|
-
if (host === '::' || host === '0.0.0.0') {
|
|
13
|
-
return 'localhost';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Other IPv6 addresses must be wrapped in brackets
|
|
17
|
-
if (host.includes('::')) {
|
|
18
|
-
return `[${host}]`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Otherwise return as-is
|
|
22
|
-
return host;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function reconnect() {
|
|
26
|
-
socket = new Socket(`ws://${getFormattedHost()}:${port}`);
|
|
27
|
-
socket.on('connect', () => {
|
|
28
|
-
socket.send('{"type": "ping"}');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
socket.on('data', (data) => {
|
|
32
|
-
const message = JSON.parse(data);
|
|
33
|
-
switch (message.type) {
|
|
34
|
-
case 'pong':
|
|
35
|
-
console.log('[hot] hot reloading connected');
|
|
36
|
-
break;
|
|
37
|
-
case 'reload':
|
|
38
|
-
console.log('[hot] full page reload');
|
|
39
|
-
window.location.reload();
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
console.log(`[hot] ${message.type} received`);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
socket.on('close', () => {
|
|
47
|
-
socket.destroy();
|
|
48
|
-
console.log('[hot] Connection lost, trying to reconnect in 4s');
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
reconnect();
|
|
51
|
-
}, 4000);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
socket.on('error', () => {
|
|
55
|
-
console.log('[hot] Error connecting to hot reloading server');
|
|
56
|
-
socket.destroy();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no" />
|
|
6
|
-
<title>Redocly Reference Docs: OAuth2 Redirect</title>
|
|
7
|
-
<style>
|
|
8
|
-
.user-info {
|
|
9
|
-
margin: 150px auto auto;
|
|
10
|
-
width: 50%;
|
|
11
|
-
background-color: whitesmoke;
|
|
12
|
-
padding: 20px;
|
|
13
|
-
text-align: center;
|
|
14
|
-
}
|
|
15
|
-
</style>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<script src="https://cdn.redocly.com/reference-docs/latest/oauth2-redirect.js"></script>
|
|
19
|
-
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
20
|
-
</body>
|
|
21
|
-
</html>
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { compile } from 'handlebars';
|
|
2
|
-
import * as colorette from 'colorette';
|
|
3
|
-
import { getPort } from 'get-port-please';
|
|
4
|
-
import { readFileSync, promises as fsPromises } from 'fs';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import { startHttpServer, startWsServer, respondWithGzip, mimeTypes } from './server';
|
|
7
|
-
import { isSubdir } from '../../../utils/miscellaneous';
|
|
8
|
-
|
|
9
|
-
import type { IncomingMessage } from 'http';
|
|
10
|
-
|
|
11
|
-
function getPageHTML(
|
|
12
|
-
htmlTemplate: string,
|
|
13
|
-
redocOptions: object = {},
|
|
14
|
-
useRedocPro: boolean,
|
|
15
|
-
wsPort: number,
|
|
16
|
-
host: string
|
|
17
|
-
) {
|
|
18
|
-
let templateSrc = readFileSync(htmlTemplate, 'utf-8');
|
|
19
|
-
|
|
20
|
-
// fix template for backward compatibility
|
|
21
|
-
templateSrc = templateSrc
|
|
22
|
-
.replace(/{?{{redocHead}}}?/, '{{{redocHead}}}')
|
|
23
|
-
.replace('{{redocBody}}', '{{{redocHTML}}}');
|
|
24
|
-
|
|
25
|
-
const template = compile(templateSrc);
|
|
26
|
-
|
|
27
|
-
return template({
|
|
28
|
-
redocHead: `
|
|
29
|
-
<script>
|
|
30
|
-
window.__REDOC_EXPORT = '${useRedocPro ? 'RedoclyReferenceDocs' : 'Redoc'}';
|
|
31
|
-
window.__OPENAPI_CLI_WS_PORT = ${wsPort};
|
|
32
|
-
window.__OPENAPI_CLI_WS_HOST = "${host}";
|
|
33
|
-
</script>
|
|
34
|
-
<script src="/simplewebsocket.min.js"></script>
|
|
35
|
-
<script src="/hot.js"></script>
|
|
36
|
-
<script src="${
|
|
37
|
-
useRedocPro
|
|
38
|
-
? 'https://cdn.redocly.com/reference-docs/latest/redocly-reference-docs.min.js'
|
|
39
|
-
: 'https://cdn.redocly.com/redoc/latest/bundles/redoc.standalone.js'
|
|
40
|
-
}"></script>
|
|
41
|
-
`,
|
|
42
|
-
redocHTML: `
|
|
43
|
-
<div id="redoc"></div>
|
|
44
|
-
<script>
|
|
45
|
-
var container = document.getElementById('redoc');
|
|
46
|
-
${
|
|
47
|
-
useRedocPro
|
|
48
|
-
? "window[window.__REDOC_EXPORT].setPublicPath('https://cdn.redocly.com/reference-docs/latest/');"
|
|
49
|
-
: ''
|
|
50
|
-
}
|
|
51
|
-
window[window.__REDOC_EXPORT].init("/openapi.json", ${JSON.stringify(redocOptions)}, container)
|
|
52
|
-
</script>`,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default async function startPreviewServer(
|
|
57
|
-
port: number,
|
|
58
|
-
host: string,
|
|
59
|
-
{
|
|
60
|
-
getBundle,
|
|
61
|
-
getOptions,
|
|
62
|
-
useRedocPro,
|
|
63
|
-
}: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
64
|
-
{ getBundle: Function; getOptions: Function; useRedocPro: boolean }
|
|
65
|
-
) {
|
|
66
|
-
const defaultTemplate = path.join(__dirname, 'default.hbs');
|
|
67
|
-
const handler = async (request: IncomingMessage, response: any) => {
|
|
68
|
-
console.time(colorette.dim(`GET ${request.url}`));
|
|
69
|
-
const { htmlTemplate } = getOptions() || {};
|
|
70
|
-
|
|
71
|
-
if (request.url?.endsWith('/') || path.extname(request.url!) === '') {
|
|
72
|
-
respondWithGzip(
|
|
73
|
-
getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort, host),
|
|
74
|
-
request,
|
|
75
|
-
response,
|
|
76
|
-
{
|
|
77
|
-
'Content-Type': 'text/html',
|
|
78
|
-
}
|
|
79
|
-
);
|
|
80
|
-
} else if (request.url === '/openapi.json') {
|
|
81
|
-
const bundle = await getBundle();
|
|
82
|
-
if (bundle === undefined) {
|
|
83
|
-
respondWithGzip(
|
|
84
|
-
JSON.stringify({
|
|
85
|
-
openapi: '3.0.0',
|
|
86
|
-
info: {
|
|
87
|
-
description:
|
|
88
|
-
'<code> Failed to generate bundle: check out console output for more details </code>',
|
|
89
|
-
},
|
|
90
|
-
paths: {},
|
|
91
|
-
}),
|
|
92
|
-
request,
|
|
93
|
-
response,
|
|
94
|
-
{
|
|
95
|
-
'Content-Type': 'application/json',
|
|
96
|
-
}
|
|
97
|
-
);
|
|
98
|
-
} else {
|
|
99
|
-
respondWithGzip(JSON.stringify(bundle), request, response, {
|
|
100
|
-
'Content-Type': 'application/json',
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
let filePath =
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
{
|
|
108
|
-
'/hot.js': path.join(__dirname, 'hot.js'),
|
|
109
|
-
'/oauth2-redirect.html': path.join(__dirname, 'oauth2-redirect.html'),
|
|
110
|
-
'/simplewebsocket.min.js': require.resolve('simple-websocket/simplewebsocket.min.js'),
|
|
111
|
-
}[request.url || ''];
|
|
112
|
-
|
|
113
|
-
if (!filePath) {
|
|
114
|
-
const basePath = htmlTemplate ? path.dirname(htmlTemplate) : process.cwd();
|
|
115
|
-
|
|
116
|
-
filePath = path.resolve(basePath, `.${request.url}`);
|
|
117
|
-
|
|
118
|
-
if (!isSubdir(basePath, filePath)) {
|
|
119
|
-
respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
120
|
-
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const extname = String(path.extname(filePath)).toLowerCase() as keyof typeof mimeTypes;
|
|
126
|
-
|
|
127
|
-
const contentType = mimeTypes[extname] || 'application/octet-stream';
|
|
128
|
-
try {
|
|
129
|
-
respondWithGzip(await fsPromises.readFile(filePath), request, response, {
|
|
130
|
-
'Content-Type': contentType,
|
|
131
|
-
});
|
|
132
|
-
} catch (e) {
|
|
133
|
-
if (e.code === 'ENOENT') {
|
|
134
|
-
respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
|
|
135
|
-
} else {
|
|
136
|
-
respondWithGzip(
|
|
137
|
-
`Something went wrong: ${e.code || e.message}...\n`,
|
|
138
|
-
request,
|
|
139
|
-
response,
|
|
140
|
-
{},
|
|
141
|
-
500
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
console.timeEnd(colorette.dim(`GET ${request.url}`));
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const wsPort = await getPort({ port: 32201, portRange: [32201, 32301], host });
|
|
150
|
-
|
|
151
|
-
const server = startHttpServer(port, host, handler);
|
|
152
|
-
server.on('listening', () => {
|
|
153
|
-
process.stdout.write(
|
|
154
|
-
`\n 🔎 Preview server running at ${colorette.blue(`http://${host}:${port}\n`)}`
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
return startWsServer(wsPort, host);
|
|
159
|
-
}
|