@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/utils/platform.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sanitizes the input path by removing invalid characters.
|
|
3
|
-
*/
|
|
4
|
-
export const sanitizePath = (input: string): string => {
|
|
5
|
-
return input.replace(/[^a-zA-Z0-9 ._\-:\\/@]/g, '');
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Sanitizes the input locale (ex. en-US) by removing invalid characters.
|
|
10
|
-
*/
|
|
11
|
-
export const sanitizeLocale = (input: string): string => {
|
|
12
|
-
return input.replace(/[^a-zA-Z0-9@._-]/g, '');
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves platform-specific arguments and utilities.
|
|
17
|
-
*/
|
|
18
|
-
export function getPlatformSpawnArgs() {
|
|
19
|
-
const isWindowsPlatform = process.platform === 'win32';
|
|
20
|
-
const npxExecutableName = isWindowsPlatform ? 'npx.cmd' : 'npx';
|
|
21
|
-
|
|
22
|
-
const sanitizeIfWindows = (input: string | undefined, sanitizer: (input: string) => string) => {
|
|
23
|
-
if (isWindowsPlatform && input) {
|
|
24
|
-
return sanitizer(input);
|
|
25
|
-
} else {
|
|
26
|
-
return input || '';
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return { npxExecutableName, sanitize: sanitizeIfWindows, shell: isWindowsPlatform };
|
|
31
|
-
}
|
package/src/utils/spinner.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as process from 'process';
|
|
2
|
-
|
|
3
|
-
const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
4
|
-
|
|
5
|
-
export class Spinner {
|
|
6
|
-
private readonly frames: string[];
|
|
7
|
-
private currentFrame: number;
|
|
8
|
-
private intervalId: NodeJS.Timeout | null;
|
|
9
|
-
private message: string;
|
|
10
|
-
|
|
11
|
-
constructor() {
|
|
12
|
-
this.frames = SPINNER_FRAMES;
|
|
13
|
-
this.currentFrame = 0;
|
|
14
|
-
this.intervalId = null;
|
|
15
|
-
this.message = '';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private showFrame() {
|
|
19
|
-
process.stdout.write('\r' + this.frames[this.currentFrame] + ' ' + this.message);
|
|
20
|
-
this.currentFrame = (this.currentFrame + 1) % this.frames.length;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
start(message: string) {
|
|
24
|
-
if (this.message === message) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
this.message = message;
|
|
29
|
-
// If we're not in a TTY, don't display the spinner.
|
|
30
|
-
if (!process.stdout.isTTY) {
|
|
31
|
-
process.stdout.write(`${message}...\n`);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (this.intervalId === null) {
|
|
36
|
-
this.intervalId = setInterval(() => {
|
|
37
|
-
this.showFrame();
|
|
38
|
-
}, 100);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
stop() {
|
|
43
|
-
if (this.intervalId !== null) {
|
|
44
|
-
clearInterval(this.intervalId);
|
|
45
|
-
this.intervalId = null;
|
|
46
|
-
process.stdout.write('\r');
|
|
47
|
-
}
|
|
48
|
-
this.message = '';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { tmpdir } from 'os';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { existsSync, writeFileSync, readFileSync, statSync } from 'fs';
|
|
4
|
-
import { compare } from 'semver';
|
|
5
|
-
import fetch, { DEFAULT_FETCH_TIMEOUT } from './fetch-with-timeout';
|
|
6
|
-
import { cyan, green, yellow } from 'colorette';
|
|
7
|
-
import { cleanColors } from './miscellaneous';
|
|
8
|
-
|
|
9
|
-
export const { version, name } = require('../../package.json');
|
|
10
|
-
|
|
11
|
-
const VERSION_CACHE_FILE = 'redocly-cli-version';
|
|
12
|
-
const SPACE_TO_BORDER = 4;
|
|
13
|
-
|
|
14
|
-
const INTERVAL_TO_CHECK = 1000 * 60 * 60 * 12;
|
|
15
|
-
const SHOULD_NOT_NOTIFY =
|
|
16
|
-
process.env.NODE_ENV === 'test' ||
|
|
17
|
-
process.env.CI ||
|
|
18
|
-
!!process.env.LAMBDA_TASK_ROOT ||
|
|
19
|
-
process.env.REDOCLY_SUPPRESS_UPDATE_NOTICE === 'true';
|
|
20
|
-
|
|
21
|
-
export const notifyUpdateCliVersion = () => {
|
|
22
|
-
if (SHOULD_NOT_NOTIFY) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const latestVersion = readFileSync(join(tmpdir(), VERSION_CACHE_FILE)).toString();
|
|
27
|
-
|
|
28
|
-
if (isNewVersionAvailable(version, latestVersion)) {
|
|
29
|
-
renderUpdateBanner(version, latestVersion);
|
|
30
|
-
}
|
|
31
|
-
} catch (e) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const isNewVersionAvailable = (current: string, latest: string) => compare(current, latest) < 0;
|
|
37
|
-
|
|
38
|
-
const getLatestVersion = async (packageName: string): Promise<string | undefined> => {
|
|
39
|
-
const latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const response = await fetch(latestUrl, { timeout: DEFAULT_FETCH_TIMEOUT });
|
|
43
|
-
const info = await response.json();
|
|
44
|
-
|
|
45
|
-
return info.version;
|
|
46
|
-
} catch {
|
|
47
|
-
// Do nothing
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const cacheLatestVersion = () => {
|
|
53
|
-
if (!isNeedToBeCached() || SHOULD_NOT_NOTIFY) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getLatestVersion(name)
|
|
58
|
-
.then((version) => {
|
|
59
|
-
if (version) {
|
|
60
|
-
const lastCheckFile = join(tmpdir(), VERSION_CACHE_FILE);
|
|
61
|
-
writeFileSync(lastCheckFile, version);
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
.catch(() => {});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const renderUpdateBanner = (current: string, latest: string) => {
|
|
68
|
-
const messageLines = [
|
|
69
|
-
`A new version of ${cyan('Redocly CLI')} (${green(latest)}) is available.`,
|
|
70
|
-
`Update now: \`${cyan('npm i -g @redocly/cli@latest')}\`.`,
|
|
71
|
-
`Changelog: https://redocly.com/docs/cli/changelog/`,
|
|
72
|
-
];
|
|
73
|
-
const maxLength = Math.max(...messageLines.map((line) => cleanColors(line).length));
|
|
74
|
-
|
|
75
|
-
const border = yellow('═'.repeat(maxLength + SPACE_TO_BORDER));
|
|
76
|
-
const extraSpaces = ' '.repeat(SPACE_TO_BORDER);
|
|
77
|
-
|
|
78
|
-
const banner = [
|
|
79
|
-
'',
|
|
80
|
-
extraSpaces + yellow('╔' + border + '╗'),
|
|
81
|
-
extraSpaces + yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
|
|
82
|
-
messageLines.map(getLineWithPadding(maxLength, extraSpaces)).join('\n'),
|
|
83
|
-
extraSpaces + yellow('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
|
|
84
|
-
extraSpaces + yellow('╚' + border + '╝'),
|
|
85
|
-
'',
|
|
86
|
-
'',
|
|
87
|
-
].join('\n');
|
|
88
|
-
process.stderr.write(banner);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const getLineWithPadding =
|
|
92
|
-
(maxLength: number, extraSpaces: string) =>
|
|
93
|
-
(line: string): string => {
|
|
94
|
-
const padding = ' '.repeat(maxLength - cleanColors(line).length);
|
|
95
|
-
return `${extraSpaces}${yellow('║')} ${line}${padding} ${yellow('║')}`;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const isNeedToBeCached = (): boolean => {
|
|
99
|
-
try {
|
|
100
|
-
// Last version from npm is stored in a file in the OS temp folder
|
|
101
|
-
const versionFile = join(tmpdir(), VERSION_CACHE_FILE);
|
|
102
|
-
|
|
103
|
-
if (!existsSync(versionFile)) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const now = new Date().getTime();
|
|
108
|
-
const stats = statSync(versionFile);
|
|
109
|
-
const lastCheck = stats.mtime.getTime();
|
|
110
|
-
|
|
111
|
-
return now - lastCheck >= INTERVAL_TO_CHECK;
|
|
112
|
-
} catch (e) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
};
|
package/src/wrapper.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { detectSpec, doesYamlFileExist } from '@redocly/openapi-core';
|
|
2
|
-
import { isPlainObject } from '@redocly/openapi-core/lib/utils';
|
|
3
|
-
import { version } from './utils/update-version-notifier';
|
|
4
|
-
import { exitWithError, loadConfigAndHandleErrors, sendTelemetry } from './utils/miscellaneous';
|
|
5
|
-
import { lintConfigCallback } from './commands/lint';
|
|
6
|
-
|
|
7
|
-
import type { Arguments } from 'yargs';
|
|
8
|
-
import type { Config, Region } from '@redocly/openapi-core';
|
|
9
|
-
import type { CollectFn } from '@redocly/openapi-core/lib/utils';
|
|
10
|
-
import type { ExitCode } from './utils/miscellaneous';
|
|
11
|
-
import type { CommandOptions } from './types';
|
|
12
|
-
|
|
13
|
-
export type CommandArgs<T extends CommandOptions> = {
|
|
14
|
-
argv: T;
|
|
15
|
-
config: Config;
|
|
16
|
-
version: string;
|
|
17
|
-
collectSpecData?: CollectFn;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export function commandWrapper<T extends CommandOptions>(
|
|
21
|
-
commandHandler?: (wrapperArgs: CommandArgs<T>) => Promise<unknown>
|
|
22
|
-
) {
|
|
23
|
-
return async (argv: Arguments<T>) => {
|
|
24
|
-
let code: ExitCode = 2;
|
|
25
|
-
let hasConfig;
|
|
26
|
-
let telemetry;
|
|
27
|
-
let specVersion: string | undefined;
|
|
28
|
-
let specKeyword: string | undefined;
|
|
29
|
-
let specFullVersion: string | undefined;
|
|
30
|
-
const collectSpecData: CollectFn = (document) => {
|
|
31
|
-
specVersion = detectSpec(document);
|
|
32
|
-
if (!isPlainObject(document)) return;
|
|
33
|
-
specKeyword = document?.openapi
|
|
34
|
-
? 'openapi'
|
|
35
|
-
: document?.swagger
|
|
36
|
-
? 'swagger'
|
|
37
|
-
: document?.asyncapi
|
|
38
|
-
? 'asyncapi'
|
|
39
|
-
: document?.arazzo
|
|
40
|
-
? 'arazzo'
|
|
41
|
-
: document?.overlay
|
|
42
|
-
? 'overlay'
|
|
43
|
-
: undefined;
|
|
44
|
-
if (specKeyword) {
|
|
45
|
-
specFullVersion = document[specKeyword] as string;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
try {
|
|
49
|
-
if (argv.config && !doesYamlFileExist(argv.config)) {
|
|
50
|
-
exitWithError('Please provide a valid path to the configuration file.');
|
|
51
|
-
}
|
|
52
|
-
const config: Config = (await loadConfigAndHandleErrors({
|
|
53
|
-
configPath: argv.config,
|
|
54
|
-
customExtends: argv.extends as string[] | undefined,
|
|
55
|
-
region: argv.region as Region,
|
|
56
|
-
files: argv.files as string[] | undefined,
|
|
57
|
-
processRawConfig: lintConfigCallback(argv as T & Record<string, undefined>, version),
|
|
58
|
-
})) as Config;
|
|
59
|
-
telemetry = config.telemetry;
|
|
60
|
-
hasConfig = !config.styleguide.recommendedFallback;
|
|
61
|
-
code = 1;
|
|
62
|
-
if (typeof commandHandler === 'function') {
|
|
63
|
-
await commandHandler({ argv, config, version, collectSpecData });
|
|
64
|
-
}
|
|
65
|
-
code = 0;
|
|
66
|
-
} catch (err) {
|
|
67
|
-
// Do nothing
|
|
68
|
-
} finally {
|
|
69
|
-
if (process.env.REDOCLY_TELEMETRY !== 'off' && telemetry !== 'off') {
|
|
70
|
-
await sendTelemetry(argv, code, hasConfig, specVersion, specKeyword, specFullVersion);
|
|
71
|
-
}
|
|
72
|
-
process.once('beforeExit', () => {
|
|
73
|
-
process.exit(code);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}
|