@redocly/cli 0.0.0-snapshot.1737554067

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.
Files changed (133) hide show
  1. package/README.md +114 -0
  2. package/bin/cli.js +3 -0
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +99 -0
  4. package/lib/__mocks__/@redocly/openapi-core.js +84 -0
  5. package/lib/__mocks__/documents.d.ts +150 -0
  6. package/lib/__mocks__/documents.js +123 -0
  7. package/lib/__mocks__/fs.d.ts +8 -0
  8. package/lib/__mocks__/fs.js +9 -0
  9. package/lib/__mocks__/perf_hooks.d.ts +3 -0
  10. package/lib/__mocks__/perf_hooks.js +6 -0
  11. package/lib/__mocks__/redoc.d.ts +6 -0
  12. package/lib/__mocks__/redoc.js +5 -0
  13. package/lib/__tests__/commands/build-docs.test.d.ts +1 -0
  14. package/lib/__tests__/commands/build-docs.test.js +54 -0
  15. package/lib/__tests__/commands/bundle.test.d.ts +1 -0
  16. package/lib/__tests__/commands/bundle.test.js +235 -0
  17. package/lib/__tests__/commands/join.test.d.ts +1 -0
  18. package/lib/__tests__/commands/join.test.js +274 -0
  19. package/lib/__tests__/commands/lint.test.d.ts +1 -0
  20. package/lib/__tests__/commands/lint.test.js +149 -0
  21. package/lib/__tests__/commands/push-region.test.d.ts +1 -0
  22. package/lib/__tests__/commands/push-region.test.js +55 -0
  23. package/lib/__tests__/commands/push.test.d.ts +1 -0
  24. package/lib/__tests__/commands/push.test.js +463 -0
  25. package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
  26. package/lib/__tests__/fetch-with-timeout.test.js +44 -0
  27. package/lib/__tests__/fixtures/config.d.ts +21 -0
  28. package/lib/__tests__/fixtures/config.js +24 -0
  29. package/lib/__tests__/spinner.test.d.ts +1 -0
  30. package/lib/__tests__/spinner.test.js +43 -0
  31. package/lib/__tests__/utils.test.d.ts +1 -0
  32. package/lib/__tests__/utils.test.js +593 -0
  33. package/lib/__tests__/wrapper.test.d.ts +1 -0
  34. package/lib/__tests__/wrapper.test.js +68 -0
  35. package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
  36. package/lib/cms/api/__tests__/api-keys.test.js +26 -0
  37. package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
  38. package/lib/cms/api/__tests__/api.client.test.js +333 -0
  39. package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
  40. package/lib/cms/api/__tests__/domains.test.js +13 -0
  41. package/lib/cms/api/api-client.d.ts +75 -0
  42. package/lib/cms/api/api-client.js +225 -0
  43. package/lib/cms/api/api-keys.d.ts +1 -0
  44. package/lib/cms/api/api-keys.js +23 -0
  45. package/lib/cms/api/domains.d.ts +1 -0
  46. package/lib/cms/api/domains.js +11 -0
  47. package/lib/cms/api/index.d.ts +3 -0
  48. package/lib/cms/api/index.js +19 -0
  49. package/lib/cms/api/types.d.ts +102 -0
  50. package/lib/cms/api/types.js +2 -0
  51. package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
  52. package/lib/cms/commands/__tests__/push-status.test.js +563 -0
  53. package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
  54. package/lib/cms/commands/__tests__/push.test.js +315 -0
  55. package/lib/cms/commands/__tests__/utils.test.d.ts +1 -0
  56. package/lib/cms/commands/__tests__/utils.test.js +51 -0
  57. package/lib/cms/commands/push-status.d.ts +23 -0
  58. package/lib/cms/commands/push-status.js +206 -0
  59. package/lib/cms/commands/push.d.ts +28 -0
  60. package/lib/cms/commands/push.js +142 -0
  61. package/lib/cms/commands/utils.d.ts +25 -0
  62. package/lib/cms/commands/utils.js +46 -0
  63. package/lib/cms/utils.d.ts +2 -0
  64. package/lib/cms/utils.js +6 -0
  65. package/lib/commands/build-docs/index.d.ts +3 -0
  66. package/lib/commands/build-docs/index.js +39 -0
  67. package/lib/commands/build-docs/template.hbs +23 -0
  68. package/lib/commands/build-docs/types.d.ts +23 -0
  69. package/lib/commands/build-docs/types.js +2 -0
  70. package/lib/commands/build-docs/utils.d.ts +7 -0
  71. package/lib/commands/build-docs/utils.js +87 -0
  72. package/lib/commands/bundle.d.ts +14 -0
  73. package/lib/commands/bundle.js +91 -0
  74. package/lib/commands/eject.d.ts +9 -0
  75. package/lib/commands/eject.js +28 -0
  76. package/lib/commands/join.d.ts +11 -0
  77. package/lib/commands/join.js +565 -0
  78. package/lib/commands/lint.d.ts +13 -0
  79. package/lib/commands/lint.js +108 -0
  80. package/lib/commands/login.d.ts +9 -0
  81. package/lib/commands/login.js +23 -0
  82. package/lib/commands/preview-docs/index.d.ts +12 -0
  83. package/lib/commands/preview-docs/index.js +127 -0
  84. package/lib/commands/preview-docs/preview-server/default.hbs +24 -0
  85. package/lib/commands/preview-docs/preview-server/hot.js +59 -0
  86. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +21 -0
  87. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +5 -0
  88. package/lib/commands/preview-docs/preview-server/preview-server.js +113 -0
  89. package/lib/commands/preview-docs/preview-server/server.d.ts +22 -0
  90. package/lib/commands/preview-docs/preview-server/server.js +85 -0
  91. package/lib/commands/preview-project/constants.d.ts +14 -0
  92. package/lib/commands/preview-project/constants.js +22 -0
  93. package/lib/commands/preview-project/index.d.ts +3 -0
  94. package/lib/commands/preview-project/index.js +56 -0
  95. package/lib/commands/preview-project/types.d.ts +10 -0
  96. package/lib/commands/preview-project/types.js +2 -0
  97. package/lib/commands/push.d.ts +44 -0
  98. package/lib/commands/push.js +295 -0
  99. package/lib/commands/split/__tests__/index.test.d.ts +1 -0
  100. package/lib/commands/split/__tests__/index.test.js +91 -0
  101. package/lib/commands/split/index.d.ts +13 -0
  102. package/lib/commands/split/index.js +259 -0
  103. package/lib/commands/split/types.d.ts +36 -0
  104. package/lib/commands/split/types.js +51 -0
  105. package/lib/commands/stats.d.ts +8 -0
  106. package/lib/commands/stats.js +96 -0
  107. package/lib/commands/translations.d.ts +7 -0
  108. package/lib/commands/translations.js +20 -0
  109. package/lib/index.d.ts +2 -0
  110. package/lib/index.js +733 -0
  111. package/lib/types.d.ts +43 -0
  112. package/lib/types.js +5 -0
  113. package/lib/utils/__mocks__/miscellaneous.d.ts +43 -0
  114. package/lib/utils/__mocks__/miscellaneous.js +24 -0
  115. package/lib/utils/assert-node-version.d.ts +1 -0
  116. package/lib/utils/assert-node-version.js +16 -0
  117. package/lib/utils/fetch-with-timeout.d.ts +7 -0
  118. package/lib/utils/fetch-with-timeout.js +26 -0
  119. package/lib/utils/getCommandNameFromArgs.d.ts +2 -0
  120. package/lib/utils/getCommandNameFromArgs.js +6 -0
  121. package/lib/utils/js-utils.d.ts +5 -0
  122. package/lib/utils/js-utils.js +28 -0
  123. package/lib/utils/miscellaneous.d.ts +81 -0
  124. package/lib/utils/miscellaneous.js +551 -0
  125. package/lib/utils/platform.d.ts +16 -0
  126. package/lib/utils/platform.js +34 -0
  127. package/lib/utils/spinner.d.ts +10 -0
  128. package/lib/utils/spinner.js +42 -0
  129. package/lib/utils/update-version-notifier.d.ts +3 -0
  130. package/lib/utils/update-version-notifier.js +102 -0
  131. package/lib/wrapper.d.ts +11 -0
  132. package/lib/wrapper.js +65 -0
  133. package/package.json +69 -0
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.cacheLatestVersion = exports.notifyUpdateCliVersion = exports.name = exports.version = void 0;
5
+ const os_1 = require("os");
6
+ const path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ const semver_1 = require("semver");
9
+ const fetch_with_timeout_1 = require("./fetch-with-timeout");
10
+ const colorette_1 = require("colorette");
11
+ const miscellaneous_1 = require("./miscellaneous");
12
+ _a = require('../../package.json'), exports.version = _a.version, exports.name = _a.name;
13
+ const VERSION_CACHE_FILE = 'redocly-cli-version';
14
+ const SPACE_TO_BORDER = 4;
15
+ const INTERVAL_TO_CHECK = 1000 * 60 * 60 * 12;
16
+ const SHOULD_NOT_NOTIFY = process.env.NODE_ENV === 'test' ||
17
+ process.env.CI ||
18
+ !!process.env.LAMBDA_TASK_ROOT ||
19
+ process.env.REDOCLY_SUPPRESS_UPDATE_NOTICE === 'true';
20
+ const notifyUpdateCliVersion = () => {
21
+ if (SHOULD_NOT_NOTIFY) {
22
+ return;
23
+ }
24
+ try {
25
+ const latestVersion = (0, fs_1.readFileSync)((0, path_1.join)((0, os_1.tmpdir)(), VERSION_CACHE_FILE)).toString();
26
+ if (isNewVersionAvailable(exports.version, latestVersion)) {
27
+ renderUpdateBanner(exports.version, latestVersion);
28
+ }
29
+ }
30
+ catch (e) {
31
+ return;
32
+ }
33
+ };
34
+ exports.notifyUpdateCliVersion = notifyUpdateCliVersion;
35
+ const isNewVersionAvailable = (current, latest) => (0, semver_1.compare)(current, latest) < 0;
36
+ const getLatestVersion = async (packageName) => {
37
+ const latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
38
+ try {
39
+ const response = await (0, fetch_with_timeout_1.default)(latestUrl, { timeout: fetch_with_timeout_1.DEFAULT_FETCH_TIMEOUT });
40
+ const info = await response.json();
41
+ return info.version;
42
+ }
43
+ catch {
44
+ // Do nothing
45
+ return;
46
+ }
47
+ };
48
+ const cacheLatestVersion = () => {
49
+ if (!isNeedToBeCached() || SHOULD_NOT_NOTIFY) {
50
+ return;
51
+ }
52
+ getLatestVersion(exports.name)
53
+ .then((version) => {
54
+ if (version) {
55
+ const lastCheckFile = (0, path_1.join)((0, os_1.tmpdir)(), VERSION_CACHE_FILE);
56
+ (0, fs_1.writeFileSync)(lastCheckFile, version);
57
+ }
58
+ })
59
+ .catch(() => { });
60
+ };
61
+ exports.cacheLatestVersion = cacheLatestVersion;
62
+ const renderUpdateBanner = (current, latest) => {
63
+ const messageLines = [
64
+ `A new version of ${(0, colorette_1.cyan)('Redocly CLI')} (${(0, colorette_1.green)(latest)}) is available.`,
65
+ `Update now: \`${(0, colorette_1.cyan)('npm i -g @redocly/cli@latest')}\`.`,
66
+ `Changelog: https://redocly.com/docs/cli/changelog/`,
67
+ ];
68
+ const maxLength = Math.max(...messageLines.map((line) => (0, miscellaneous_1.cleanColors)(line).length));
69
+ const border = (0, colorette_1.yellow)('═'.repeat(maxLength + SPACE_TO_BORDER));
70
+ const extraSpaces = ' '.repeat(SPACE_TO_BORDER);
71
+ const banner = [
72
+ '',
73
+ extraSpaces + (0, colorette_1.yellow)('╔' + border + '╗'),
74
+ extraSpaces + (0, colorette_1.yellow)('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
75
+ messageLines.map(getLineWithPadding(maxLength, extraSpaces)).join('\n'),
76
+ extraSpaces + (0, colorette_1.yellow)('║' + ' '.repeat(maxLength + SPACE_TO_BORDER) + '║'),
77
+ extraSpaces + (0, colorette_1.yellow)('╚' + border + '╝'),
78
+ '',
79
+ '',
80
+ ].join('\n');
81
+ process.stderr.write(banner);
82
+ };
83
+ const getLineWithPadding = (maxLength, extraSpaces) => (line) => {
84
+ const padding = ' '.repeat(maxLength - (0, miscellaneous_1.cleanColors)(line).length);
85
+ return `${extraSpaces}${(0, colorette_1.yellow)('║')} ${line}${padding} ${(0, colorette_1.yellow)('║')}`;
86
+ };
87
+ const isNeedToBeCached = () => {
88
+ try {
89
+ // Last version from npm is stored in a file in the OS temp folder
90
+ const versionFile = (0, path_1.join)((0, os_1.tmpdir)(), VERSION_CACHE_FILE);
91
+ if (!(0, fs_1.existsSync)(versionFile)) {
92
+ return true;
93
+ }
94
+ const now = new Date().getTime();
95
+ const stats = (0, fs_1.statSync)(versionFile);
96
+ const lastCheck = stats.mtime.getTime();
97
+ return now - lastCheck >= INTERVAL_TO_CHECK;
98
+ }
99
+ catch (e) {
100
+ return false;
101
+ }
102
+ };
@@ -0,0 +1,11 @@
1
+ import type { Arguments } from 'yargs';
2
+ import type { Config } from '@redocly/openapi-core';
3
+ import type { CollectFn } from '@redocly/openapi-core/lib/utils';
4
+ import type { CommandOptions } from './types';
5
+ export type CommandArgs<T extends CommandOptions> = {
6
+ argv: T;
7
+ config: Config;
8
+ version: string;
9
+ collectSpecData?: CollectFn;
10
+ };
11
+ export declare function commandWrapper<T extends CommandOptions>(commandHandler?: (wrapperArgs: CommandArgs<T>) => Promise<unknown>): (argv: Arguments<T>) => Promise<void>;
package/lib/wrapper.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commandWrapper = commandWrapper;
4
+ const openapi_core_1 = require("@redocly/openapi-core");
5
+ const utils_1 = require("@redocly/openapi-core/lib/utils");
6
+ const update_version_notifier_1 = require("./utils/update-version-notifier");
7
+ const miscellaneous_1 = require("./utils/miscellaneous");
8
+ const lint_1 = require("./commands/lint");
9
+ function commandWrapper(commandHandler) {
10
+ return async (argv) => {
11
+ let code = 2;
12
+ let hasConfig;
13
+ let telemetry;
14
+ let specVersion;
15
+ let specKeyword;
16
+ let specFullVersion;
17
+ const collectSpecData = (document) => {
18
+ specVersion = (0, openapi_core_1.detectSpec)(document);
19
+ if (!(0, utils_1.isPlainObject)(document))
20
+ return;
21
+ specKeyword = document?.openapi
22
+ ? 'openapi'
23
+ : document?.swagger
24
+ ? 'swagger'
25
+ : document?.asyncapi
26
+ ? 'asyncapi'
27
+ : document?.arazzo
28
+ ? 'arazzo'
29
+ : undefined;
30
+ if (specKeyword) {
31
+ specFullVersion = document[specKeyword];
32
+ }
33
+ };
34
+ try {
35
+ if (argv.config && !(0, openapi_core_1.doesYamlFileExist)(argv.config)) {
36
+ (0, miscellaneous_1.exitWithError)('Please provide a valid path to the configuration file.');
37
+ }
38
+ const config = (await (0, miscellaneous_1.loadConfigAndHandleErrors)({
39
+ configPath: argv.config,
40
+ customExtends: argv.extends,
41
+ region: argv.region,
42
+ files: argv.files,
43
+ processRawConfig: (0, lint_1.lintConfigCallback)(argv, update_version_notifier_1.version),
44
+ }));
45
+ telemetry = config.telemetry;
46
+ hasConfig = !config.styleguide.recommendedFallback;
47
+ code = 1;
48
+ if (typeof commandHandler === 'function') {
49
+ await commandHandler({ argv, config, version: update_version_notifier_1.version, collectSpecData });
50
+ }
51
+ code = 0;
52
+ }
53
+ catch (err) {
54
+ // Do nothing
55
+ }
56
+ finally {
57
+ if (process.env.REDOCLY_TELEMETRY !== 'off' && telemetry !== 'off') {
58
+ await (0, miscellaneous_1.sendTelemetry)(argv, code, hasConfig, specVersion, specKeyword, specFullVersion);
59
+ }
60
+ process.once('beforeExit', () => {
61
+ process.exit(code);
62
+ });
63
+ }
64
+ };
65
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@redocly/cli",
3
+ "version": "0.0.0-snapshot.1737554067",
4
+ "description": "",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "openapi": "bin/cli.js",
8
+ "redocly": "bin/cli.js"
9
+ },
10
+ "engines": {
11
+ "node": ">=14.19.0",
12
+ "npm": ">=7.0.0"
13
+ },
14
+ "engineStrict": true,
15
+ "scripts": {
16
+ "compile": "tsc",
17
+ "copy-assets": "cp src/commands/preview-docs/preview-server/default.hbs lib/commands/preview-docs/preview-server/default.hbs && cp src/commands/preview-docs/preview-server/hot.js lib/commands/preview-docs/preview-server/hot.js && cp src/commands/preview-docs/preview-server/oauth2-redirect.html lib/commands/preview-docs/preview-server/oauth2-redirect.html && cp src/commands/build-docs/template.hbs lib/commands/build-docs/template.hbs ",
18
+ "prepack": "npm run copy-assets",
19
+ "prepublishOnly": "npm run copy-assets && cp ../../README.md ."
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/Redocly/redocly-cli.git"
24
+ },
25
+ "homepage": "https://github.com/Redocly/redocly-cli",
26
+ "keywords": [
27
+ "linter",
28
+ "OpenAPI",
29
+ "Swagger",
30
+ "OpenAPI linter",
31
+ "Swagger linter",
32
+ "AsyncAPI linter",
33
+ "oas"
34
+ ],
35
+ "contributors": [
36
+ "Roman Hotsiy <roman@redocly.com> (https://redocly.com/)"
37
+ ],
38
+ "dependencies": {
39
+ "@redocly/openapi-core": "0.0.0-snapshot.1737554067",
40
+ "abort-controller": "^3.0.0",
41
+ "chokidar": "^3.5.1",
42
+ "colorette": "^1.2.0",
43
+ "core-js": "^3.32.1",
44
+ "form-data": "^4.0.0",
45
+ "get-port-please": "^3.0.1",
46
+ "glob": "^7.1.6",
47
+ "handlebars": "^4.7.6",
48
+ "mobx": "^6.0.4",
49
+ "node-fetch": "^2.6.1",
50
+ "pluralize": "^8.0.0",
51
+ "react": "^17.0.0 || ^18.2.0",
52
+ "react-dom": "^17.0.0 || ^18.2.0",
53
+ "redoc": "~2.2.0",
54
+ "semver": "^7.5.2",
55
+ "simple-websocket": "^9.0.0",
56
+ "styled-components": "^6.0.7",
57
+ "yargs": "17.0.1"
58
+ },
59
+ "devDependencies": {
60
+ "@types/configstore": "^5.0.1",
61
+ "@types/glob": "^8.1.0",
62
+ "@types/pluralize": "^0.0.29",
63
+ "@types/react": "^17.0.0 || ^18.2.21",
64
+ "@types/react-dom": "^17.0.0 || ^18.2.7",
65
+ "@types/semver": "^7.5.0",
66
+ "@types/yargs": "17.0.32",
67
+ "typescript": "5.5.3"
68
+ }
69
+ }