@redocly/cli 1.0.0-beta.96

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 (79) hide show
  1. package/README.md +39 -0
  2. package/bin/cli.js +3 -0
  3. package/lib/__mocks__/utils.d.ts +17 -0
  4. package/lib/__mocks__/utils.js +14 -0
  5. package/lib/__tests__/commands/bundle.test.d.ts +1 -0
  6. package/lib/__tests__/commands/bundle.test.js +92 -0
  7. package/lib/__tests__/commands/push-region.test.d.ts +1 -0
  8. package/lib/__tests__/commands/push-region.test.js +55 -0
  9. package/lib/__tests__/commands/push.test.d.ts +1 -0
  10. package/lib/__tests__/commands/push.test.js +153 -0
  11. package/lib/__tests__/utils.test.d.ts +1 -0
  12. package/lib/__tests__/utils.test.js +41 -0
  13. package/lib/assert-node-version.d.ts +1 -0
  14. package/lib/assert-node-version.js +10 -0
  15. package/lib/commands/bundle.d.ts +19 -0
  16. package/lib/commands/bundle.js +128 -0
  17. package/lib/commands/join.d.ts +7 -0
  18. package/lib/commands/join.js +421 -0
  19. package/lib/commands/lint.d.ts +11 -0
  20. package/lib/commands/lint.js +80 -0
  21. package/lib/commands/login.d.ts +6 -0
  22. package/lib/commands/login.js +28 -0
  23. package/lib/commands/preview-docs/index.d.ts +12 -0
  24. package/lib/commands/preview-docs/index.js +141 -0
  25. package/lib/commands/preview-docs/preview-server/default.hbs +24 -0
  26. package/lib/commands/preview-docs/preview-server/hot.js +42 -0
  27. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +21 -0
  28. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +5 -0
  29. package/lib/commands/preview-docs/preview-server/preview-server.js +120 -0
  30. package/lib/commands/preview-docs/preview-server/server.d.ts +23 -0
  31. package/lib/commands/preview-docs/preview-server/server.js +85 -0
  32. package/lib/commands/push.d.ts +25 -0
  33. package/lib/commands/push.js +247 -0
  34. package/lib/commands/split/__tests__/index.test.d.ts +1 -0
  35. package/lib/commands/split/__tests__/index.test.js +70 -0
  36. package/lib/commands/split/index.d.ts +8 -0
  37. package/lib/commands/split/index.js +279 -0
  38. package/lib/commands/split/types.d.ts +37 -0
  39. package/lib/commands/split/types.js +52 -0
  40. package/lib/commands/stats.d.ts +5 -0
  41. package/lib/commands/stats.js +92 -0
  42. package/lib/index.d.ts +2 -0
  43. package/lib/index.js +269 -0
  44. package/lib/js-utils.d.ts +3 -0
  45. package/lib/js-utils.js +16 -0
  46. package/lib/types.d.ts +13 -0
  47. package/lib/types.js +5 -0
  48. package/lib/utils.d.ts +28 -0
  49. package/lib/utils.js +260 -0
  50. package/package.json +54 -0
  51. package/src/__mocks__/utils.ts +11 -0
  52. package/src/__tests__/commands/bundle.test.ts +120 -0
  53. package/src/__tests__/commands/push-region.test.ts +51 -0
  54. package/src/__tests__/commands/push.test.ts +156 -0
  55. package/src/__tests__/utils.test.ts +50 -0
  56. package/src/assert-node-version.ts +8 -0
  57. package/src/commands/bundle.ts +178 -0
  58. package/src/commands/join.ts +488 -0
  59. package/src/commands/lint.ts +110 -0
  60. package/src/commands/login.ts +19 -0
  61. package/src/commands/preview-docs/index.ts +188 -0
  62. package/src/commands/preview-docs/preview-server/default.hbs +24 -0
  63. package/src/commands/preview-docs/preview-server/hot.js +42 -0
  64. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +21 -0
  65. package/src/commands/preview-docs/preview-server/preview-server.ts +150 -0
  66. package/src/commands/preview-docs/preview-server/server.ts +91 -0
  67. package/src/commands/push.ts +355 -0
  68. package/src/commands/split/__tests__/fixtures/spec.json +70 -0
  69. package/src/commands/split/__tests__/fixtures/webhooks.json +88 -0
  70. package/src/commands/split/__tests__/index.test.ts +96 -0
  71. package/src/commands/split/index.ts +349 -0
  72. package/src/commands/split/types.ts +73 -0
  73. package/src/commands/stats.ts +115 -0
  74. package/src/index.ts +311 -0
  75. package/src/js-utils.ts +12 -0
  76. package/src/types.ts +13 -0
  77. package/src/utils.ts +300 -0
  78. package/tsconfig.json +9 -0
  79. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OPENAPI3_COMPONENT_NAMES = exports.OPENAPI3_COMPONENT = exports.OPENAPI3_METHOD_NAMES = exports.componentsPath = exports.xWEBHOOKS = exports.WEBHOOKS = exports.PATHS = exports.COMPONENTS = void 0;
4
+ exports.COMPONENTS = 'components';
5
+ exports.PATHS = 'paths';
6
+ exports.WEBHOOKS = 'webhooks';
7
+ exports.xWEBHOOKS = 'x-webhooks';
8
+ exports.componentsPath = `#/${exports.COMPONENTS}/`;
9
+ var OPENAPI3_METHOD;
10
+ (function (OPENAPI3_METHOD) {
11
+ OPENAPI3_METHOD["Get"] = "get";
12
+ OPENAPI3_METHOD["Put"] = "put";
13
+ OPENAPI3_METHOD["Post"] = "post";
14
+ OPENAPI3_METHOD["Delete"] = "delete";
15
+ OPENAPI3_METHOD["Options"] = "options";
16
+ OPENAPI3_METHOD["Head"] = "head";
17
+ OPENAPI3_METHOD["Patch"] = "patch";
18
+ OPENAPI3_METHOD["Trace"] = "trace";
19
+ })(OPENAPI3_METHOD || (OPENAPI3_METHOD = {}));
20
+ exports.OPENAPI3_METHOD_NAMES = [
21
+ OPENAPI3_METHOD.Get,
22
+ OPENAPI3_METHOD.Put,
23
+ OPENAPI3_METHOD.Post,
24
+ OPENAPI3_METHOD.Delete,
25
+ OPENAPI3_METHOD.Options,
26
+ OPENAPI3_METHOD.Head,
27
+ OPENAPI3_METHOD.Patch,
28
+ OPENAPI3_METHOD.Trace
29
+ ];
30
+ var OPENAPI3_COMPONENT;
31
+ (function (OPENAPI3_COMPONENT) {
32
+ OPENAPI3_COMPONENT["Schemas"] = "schemas";
33
+ OPENAPI3_COMPONENT["Responses"] = "responses";
34
+ OPENAPI3_COMPONENT["Parameters"] = "parameters";
35
+ OPENAPI3_COMPONENT["Examples"] = "examples";
36
+ OPENAPI3_COMPONENT["Headers"] = "headers";
37
+ OPENAPI3_COMPONENT["RequestBodies"] = "requestBodies";
38
+ OPENAPI3_COMPONENT["Links"] = "links";
39
+ OPENAPI3_COMPONENT["Callbacks"] = "callbacks";
40
+ OPENAPI3_COMPONENT["SecuritySchemes"] = "securitySchemes";
41
+ })(OPENAPI3_COMPONENT = exports.OPENAPI3_COMPONENT || (exports.OPENAPI3_COMPONENT = {}));
42
+ exports.OPENAPI3_COMPONENT_NAMES = [
43
+ OPENAPI3_COMPONENT.RequestBodies,
44
+ OPENAPI3_COMPONENT.Schemas,
45
+ OPENAPI3_COMPONENT.Responses,
46
+ OPENAPI3_COMPONENT.Parameters,
47
+ OPENAPI3_COMPONENT.Examples,
48
+ OPENAPI3_COMPONENT.Headers,
49
+ OPENAPI3_COMPONENT.Links,
50
+ OPENAPI3_COMPONENT.Callbacks,
51
+ OPENAPI3_COMPONENT.SecuritySchemes
52
+ ];
@@ -0,0 +1,5 @@
1
+ export declare function handleStats(argv: {
2
+ config?: string;
3
+ entrypoint?: string;
4
+ format: string;
5
+ }): Promise<void>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.handleStats = void 0;
13
+ const perf_hooks_1 = require("perf_hooks");
14
+ const colors = require("colorette");
15
+ const openapi_core_1 = require("@redocly/openapi-core");
16
+ const utils_1 = require("../utils");
17
+ const utils_2 = require("../utils");
18
+ const statsAccumulator = {
19
+ refs: { metric: '🚗 References', total: 0, color: 'red', items: new Set() },
20
+ externalDocs: { metric: '📦 External Documents', total: 0, color: 'magenta' },
21
+ schemas: { metric: '📈 Schemas', total: 0, color: 'white' },
22
+ parameters: { metric: '👉 Parameters', total: 0, color: 'yellow', items: new Set() },
23
+ links: { metric: '🔗 Links', total: 0, color: 'cyan', items: new Set() },
24
+ pathItems: { metric: '➡️ Path Items', total: 0, color: 'green' },
25
+ operations: { metric: '👷 Operations', total: 0, color: 'yellow' },
26
+ tags: { metric: '🔖 Tags', total: 0, color: 'white', items: new Set() },
27
+ };
28
+ function printStatsStylish(statsAccumulator) {
29
+ for (const node in statsAccumulator) {
30
+ const { metric, total, color } = statsAccumulator[node];
31
+ process.stderr.write(colors[color](`${metric}: ${total} \n`));
32
+ }
33
+ }
34
+ function printStatsJson(statsAccumulator) {
35
+ const json = {};
36
+ for (const key of Object.keys(statsAccumulator)) {
37
+ json[key] = {
38
+ metric: statsAccumulator[key].metric,
39
+ total: statsAccumulator[key].total,
40
+ };
41
+ }
42
+ process.stdout.write(JSON.stringify(json, null, 2));
43
+ }
44
+ function printStats(statsAccumulator, entrypoint, format) {
45
+ process.stderr.write(`Document: ${colors.magenta(entrypoint)} stats:\n\n`);
46
+ switch (format) {
47
+ case 'stylish':
48
+ printStatsStylish(statsAccumulator);
49
+ break;
50
+ case 'json':
51
+ printStatsJson(statsAccumulator);
52
+ break;
53
+ }
54
+ }
55
+ function handleStats(argv) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const config = yield openapi_core_1.loadConfig(argv.config);
58
+ const [{ path }] = yield utils_1.getFallbackEntryPointsOrExit(argv.entrypoint ? [argv.entrypoint] : [], config);
59
+ const externalRefResolver = new openapi_core_1.BaseResolver(config.resolve);
60
+ const { bundle: document } = yield openapi_core_1.bundle({ config, ref: path });
61
+ const lintConfig = config.lint;
62
+ const oasVersion = openapi_core_1.detectOpenAPI(document.parsed);
63
+ const oasMajorVersion = openapi_core_1.openAPIMajor(oasVersion);
64
+ const types = openapi_core_1.normalizeTypes(lintConfig.extendTypes(oasMajorVersion === openapi_core_1.OasMajorVersion.Version3 ? openapi_core_1.Oas3Types : openapi_core_1.Oas2Types, oasVersion), lintConfig);
65
+ const startedAt = perf_hooks_1.performance.now();
66
+ const ctx = {
67
+ problems: [],
68
+ oasVersion: oasVersion,
69
+ visitorsData: {},
70
+ };
71
+ const resolvedRefMap = yield openapi_core_1.resolveDocument({
72
+ rootDocument: document,
73
+ rootType: types.DefinitionRoot,
74
+ externalRefResolver,
75
+ });
76
+ const statsVisitor = openapi_core_1.normalizeVisitors([{
77
+ severity: 'warn',
78
+ ruleId: 'stats',
79
+ visitor: openapi_core_1.Stats(statsAccumulator)
80
+ }], types);
81
+ openapi_core_1.walkDocument({
82
+ document,
83
+ rootType: types.DefinitionRoot,
84
+ normalizedVisitors: statsVisitor,
85
+ resolvedRefMap,
86
+ ctx,
87
+ });
88
+ printStats(statsAccumulator, path, argv.format);
89
+ utils_2.printExecutionTime('stats', startedAt, path);
90
+ });
91
+ }
92
+ exports.handleStats = handleStats;
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './assert-node-version';
package/lib/index.js ADDED
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ require("./assert-node-version");
14
+ const yargs = require("yargs");
15
+ const types_1 = require("./types");
16
+ const openapi_core_1 = require("@redocly/openapi-core");
17
+ const preview_docs_1 = require("./commands/preview-docs");
18
+ const stats_1 = require("./commands/stats");
19
+ const split_1 = require("./commands/split");
20
+ const join_1 = require("./commands/join");
21
+ const push_1 = require("./commands/push");
22
+ const lint_1 = require("./commands/lint");
23
+ const bundle_1 = require("./commands/bundle");
24
+ const login_1 = require("./commands/login");
25
+ const version = require('../package.json').version;
26
+ yargs
27
+ .version('version', 'Show version number.', version)
28
+ .help('help', 'Show help.')
29
+ .command('stats [entrypoint]', 'Gathering statistics for a document.', (yargs) => yargs.positional('entrypoint', { type: 'string' }).option({
30
+ config: { description: 'Specify path to the config file.', type: 'string' },
31
+ format: {
32
+ description: 'Use a specific output format.',
33
+ choices: ['stylish', 'json'],
34
+ default: 'stylish',
35
+ },
36
+ }), stats_1.handleStats)
37
+ .command('split [entrypoint]', 'Split definition into a multi-file structure.', (yargs) => yargs
38
+ .positional('entrypoint', {
39
+ description: 'API definition file that you want to split',
40
+ type: 'string',
41
+ })
42
+ .option({
43
+ outDir: {
44
+ description: 'Output directory where files will be saved.',
45
+ required: true,
46
+ type: 'string',
47
+ },
48
+ separator: {
49
+ description: 'File path separator used while splitting.',
50
+ required: false,
51
+ type: 'string',
52
+ default: '_',
53
+ },
54
+ })
55
+ .demandOption('entrypoint'), split_1.handleSplit)
56
+ .command('join [entrypoints...]', 'Join definitions [experimental].', (yargs) => yargs
57
+ .positional('entrypoints', {
58
+ array: true,
59
+ type: 'string',
60
+ demandOption: true,
61
+ })
62
+ .option({
63
+ lint: { description: 'Lint definitions', type: 'boolean', default: false },
64
+ 'prefix-tags-with-info-prop': {
65
+ description: 'Prefix tags with property value from info object.',
66
+ requiresArg: true,
67
+ type: 'string',
68
+ },
69
+ 'prefix-tags-with-filename': {
70
+ description: 'Prefix tags with property value from file name.',
71
+ type: 'boolean',
72
+ default: false,
73
+ },
74
+ 'prefix-components-with-info-prop': {
75
+ description: 'Prefix components with property value from info object.',
76
+ requiresArg: true,
77
+ type: 'string',
78
+ },
79
+ }), (argv) => {
80
+ join_1.handleJoin(argv, version);
81
+ })
82
+ .command('push [maybeEntrypointOrAliasOrDestination] [maybeDestination] [maybeBranchName]', 'Push an API definition to the Redocly API registry.', (yargs) => yargs
83
+ .positional('maybeEntrypointOrAliasOrDestination', { type: 'string' })
84
+ .positional('maybeDestination', { type: 'string' })
85
+ .positional('maybeBranchName', { type: 'string' })
86
+ .option({
87
+ branch: { type: 'string', alias: 'b' },
88
+ upsert: { type: 'boolean', alias: 'u' },
89
+ 'run-id': { type: 'string', requiresArg: true },
90
+ region: { description: 'Specify a region.', alias: 'r', choices: types_1.regionChoices },
91
+ 'skip-decorator': {
92
+ description: 'Ignore certain decorators.',
93
+ array: true,
94
+ type: 'string',
95
+ },
96
+ }), push_1.transformPush(push_1.handlePush))
97
+ .command('lint [entrypoints...]', 'Lint definition.', (yargs) => yargs.positional('entrypoints', { array: true, type: 'string', demandOption: true }).option({
98
+ format: {
99
+ description: 'Use a specific output format.',
100
+ choices: [
101
+ 'stylish',
102
+ 'codeframe',
103
+ 'json',
104
+ 'checkstyle',
105
+ 'codeclimate',
106
+ ],
107
+ default: 'codeframe',
108
+ },
109
+ 'max-problems': {
110
+ requiresArg: true,
111
+ description: 'Reduce output to max N problems.',
112
+ type: 'number',
113
+ default: 100,
114
+ },
115
+ 'generate-ignore-file': {
116
+ description: 'Generate ignore file.',
117
+ type: 'boolean',
118
+ },
119
+ 'skip-rule': {
120
+ description: 'Ignore certain rules.',
121
+ array: true,
122
+ type: 'string',
123
+ },
124
+ 'skip-preprocessor': {
125
+ description: 'Ignore certain preprocessors.',
126
+ array: true,
127
+ type: 'string',
128
+ },
129
+ config: {
130
+ description: 'Specify path to the config file.',
131
+ requiresArg: true,
132
+ type: 'string',
133
+ },
134
+ extends: {
135
+ description: 'Override extends configurations (defaults or config file settings).',
136
+ requiresArg: true,
137
+ array: true,
138
+ type: 'string',
139
+ },
140
+ }), (argv) => {
141
+ lint_1.handleLint(argv, version);
142
+ })
143
+ .command('bundle [entrypoints...]', 'Bundle definition.', (yargs) => yargs.positional('entrypoints', { array: true, type: 'string', demandOption: true }).options({
144
+ output: { type: 'string', alias: 'o' },
145
+ format: {
146
+ description: 'Use a specific output format.',
147
+ choices: ['stylish', 'codeframe', 'json', 'checkstyle'],
148
+ default: 'codeframe',
149
+ },
150
+ 'max-problems': {
151
+ requiresArg: true,
152
+ description: 'Reduce output to max N problems.',
153
+ type: 'number',
154
+ default: 100,
155
+ },
156
+ ext: {
157
+ description: 'Bundle file extension.',
158
+ requiresArg: true,
159
+ choices: types_1.outputExtensions,
160
+ },
161
+ 'skip-rule': {
162
+ description: 'Ignore certain rules.',
163
+ array: true,
164
+ type: 'string',
165
+ },
166
+ 'skip-preprocessor': {
167
+ description: 'Ignore certain preprocessors.',
168
+ array: true,
169
+ type: 'string',
170
+ },
171
+ 'skip-decorator': {
172
+ description: 'Ignore certain decorators.',
173
+ array: true,
174
+ type: 'string',
175
+ },
176
+ dereferenced: {
177
+ alias: 'd',
178
+ type: 'boolean',
179
+ description: 'Produce fully dereferenced bundle.',
180
+ },
181
+ force: {
182
+ alias: 'f',
183
+ type: 'boolean',
184
+ description: 'Produce bundle output even when errors occur.',
185
+ },
186
+ config: {
187
+ description: 'Specify path to the config file.',
188
+ type: 'string',
189
+ },
190
+ lint: {
191
+ description: 'Lint definitions',
192
+ type: 'boolean',
193
+ default: false,
194
+ },
195
+ metafile: {
196
+ description: 'Produce metadata about the bundle',
197
+ type: 'string',
198
+ },
199
+ extends: {
200
+ description: 'Override extends configurations (defaults or config file settings).',
201
+ requiresArg: true,
202
+ array: true,
203
+ type: 'string',
204
+ },
205
+ 'remove-unused-components': {
206
+ description: 'Remove unused components.',
207
+ type: 'boolean',
208
+ default: false,
209
+ },
210
+ }), (argv) => {
211
+ bundle_1.handleBundle(argv, version);
212
+ })
213
+ .command('login', 'Login to the Redocly API registry with an access token.', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
214
+ return yargs.options({
215
+ verbose: {
216
+ description: 'Include additional output.',
217
+ type: 'boolean',
218
+ },
219
+ region: {
220
+ description: 'Specify a region.',
221
+ alias: 'r',
222
+ choices: types_1.regionChoices,
223
+ },
224
+ });
225
+ }), login_1.handleLogin)
226
+ .command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, () => __awaiter(void 0, void 0, void 0, function* () {
227
+ const client = new openapi_core_1.RedoclyClient();
228
+ client.logout();
229
+ }))
230
+ .command('preview-docs [entrypoint]', 'Preview API reference docs for the specified definition.', (yargs) => yargs.positional('entrypoint', { type: 'string' }).options({
231
+ port: {
232
+ alias: 'p',
233
+ type: 'number',
234
+ default: 8080,
235
+ description: 'Preview port.',
236
+ },
237
+ host: {
238
+ alias: 'h',
239
+ type: 'string',
240
+ default: '127.0.0.1',
241
+ description: 'Preview host.',
242
+ },
243
+ 'skip-preprocessor': {
244
+ description: 'Ignore certain preprocessors.',
245
+ array: true,
246
+ type: 'string',
247
+ },
248
+ 'skip-decorator': {
249
+ description: 'Ignore certain decorators.',
250
+ array: true,
251
+ type: 'string',
252
+ },
253
+ 'use-community-edition': {
254
+ description: 'Force using Redoc CE for docs preview.',
255
+ type: 'boolean',
256
+ },
257
+ force: {
258
+ alias: 'f',
259
+ type: 'boolean',
260
+ description: 'Produce bundle output even when errors occur.',
261
+ },
262
+ config: {
263
+ description: 'Specify path to the config file.',
264
+ type: 'string',
265
+ },
266
+ }), preview_docs_1.previewDocs)
267
+ .completion('completion', 'Generate completion script.')
268
+ .demandCommand(1)
269
+ .strict().argv;
@@ -0,0 +1,3 @@
1
+ export declare function isObject(obj: any): boolean;
2
+ export declare function isEmptyObject(obj: any): boolean;
3
+ export declare function isString(str: string): boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isString = exports.isEmptyObject = exports.isObject = void 0;
4
+ function isObject(obj) {
5
+ const type = typeof obj;
6
+ return type === 'function' || type === 'object' && !!obj;
7
+ }
8
+ exports.isObject = isObject;
9
+ function isEmptyObject(obj) {
10
+ return !!obj && Object.keys(obj).length === 0;
11
+ }
12
+ exports.isEmptyObject = isEmptyObject;
13
+ function isString(str) {
14
+ return Object.prototype.toString.call(str) === "[object String]";
15
+ }
16
+ exports.isString = isString;
package/lib/types.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { BundleOutputFormat, Region } from '@redocly/openapi-core';
2
+ export declare type Totals = {
3
+ errors: number;
4
+ warnings: number;
5
+ ignored: number;
6
+ };
7
+ export declare type Entrypoint = {
8
+ path: string;
9
+ alias?: string;
10
+ };
11
+ export declare const outputExtensions: readonly BundleOutputFormat[];
12
+ export declare type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
13
+ export declare const regionChoices: readonly Region[];
package/lib/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.regionChoices = exports.outputExtensions = void 0;
4
+ exports.outputExtensions = ['json', 'yaml', 'yml'];
5
+ exports.regionChoices = ['us', 'eu'];
package/lib/utils.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { BundleOutputFormat, Config, LintConfig } from '@redocly/openapi-core';
2
+ import { Totals, Entrypoint } from './types';
3
+ export declare function getFallbackEntryPointsOrExit(argsEntrypoints: string[] | undefined, config: Config): Promise<Entrypoint[]>;
4
+ export declare function getExecutionTime(startedAt: number): string;
5
+ export declare function printExecutionTime(commandName: string, startedAt: number, entrypoint: string): void;
6
+ export declare function pathToFilename(path: string, pathSeparator: string): string;
7
+ export declare class CircularJSONNotSupportedError extends Error {
8
+ originalError: Error;
9
+ constructor(originalError: Error);
10
+ }
11
+ export declare function dumpBundle(obj: any, format: BundleOutputFormat, dereference?: boolean): string;
12
+ export declare function saveBundle(filename: string, output: string): void;
13
+ export declare function promptUser(query: string, hideUserInput?: boolean): Promise<string>;
14
+ export declare function readYaml(filename: string): unknown;
15
+ export declare function writeYaml(data: any, filename: string, noRefs?: boolean): void;
16
+ export declare function pluralize(label: string, num: number): string;
17
+ export declare function handleError(e: Error, ref: string): void;
18
+ export declare function printLintTotals(totals: Totals, definitionsCount: number): void;
19
+ export declare function getOutputFileName(entrypoint: string, entries: number, output?: string, ext?: BundleOutputFormat): {
20
+ outputFile: string;
21
+ ext: BundleOutputFormat;
22
+ };
23
+ export declare function printUnusedWarnings(config: LintConfig): void;
24
+ export declare function exitWithError(message: string): void;
25
+ /**
26
+ * Checks if dir is subdir of parent
27
+ */
28
+ export declare function isSubdir(parent: string, dir: string): boolean;