@redocly/cli 1.10.6 → 1.11.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/CHANGELOG.md +13 -0
- package/lib/__tests__/commands/bundle.test.js +3 -32
- package/lib/__tests__/commands/join.test.js +0 -11
- package/lib/commands/bundle.d.ts +1 -4
- package/lib/commands/bundle.js +2 -32
- package/lib/commands/join.d.ts +0 -3
- package/lib/commands/join.js +13 -36
- package/lib/index.js +57 -26
- package/package.json +2 -2
- package/src/__tests__/commands/bundle.test.ts +4 -37
- package/src/__tests__/commands/join.test.ts +0 -17
- package/src/commands/bundle.ts +3 -53
- package/src/commands/join.ts +13 -49
- package/src/index.ts +76 -26
- package/tsconfig.tsbuildinfo +1 -1
package/src/commands/bundle.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatProblems,
|
|
3
|
-
getTotals,
|
|
4
|
-
getMergedConfig,
|
|
5
|
-
lint,
|
|
6
|
-
bundle,
|
|
7
|
-
Config,
|
|
8
|
-
OutputFormat,
|
|
9
|
-
} from '@redocly/openapi-core';
|
|
1
|
+
import { formatProblems, getTotals, getMergedConfig, bundle, Config } from '@redocly/openapi-core';
|
|
10
2
|
import {
|
|
11
3
|
dumpBundle,
|
|
12
4
|
getExecutionTime,
|
|
@@ -15,8 +7,6 @@ import {
|
|
|
15
7
|
handleError,
|
|
16
8
|
printUnusedWarnings,
|
|
17
9
|
saveBundle,
|
|
18
|
-
printLintTotals,
|
|
19
|
-
checkIfRulesetExist,
|
|
20
10
|
sortTopLevelKeysForOas,
|
|
21
11
|
} from '../utils/miscellaneous';
|
|
22
12
|
import type { OutputExtensions, Skips, Totals } from '../types';
|
|
@@ -27,15 +17,12 @@ import { checkForDeprecatedOptions } from '../utils/miscellaneous';
|
|
|
27
17
|
|
|
28
18
|
export type BundleOptions = {
|
|
29
19
|
apis?: string[];
|
|
30
|
-
'max-problems'?: number;
|
|
31
20
|
extends?: string[];
|
|
32
21
|
config?: string;
|
|
33
|
-
format?: OutputFormat;
|
|
34
22
|
output?: string;
|
|
35
23
|
ext: OutputExtensions;
|
|
36
24
|
dereferenced?: boolean;
|
|
37
25
|
force?: boolean;
|
|
38
|
-
lint?: boolean;
|
|
39
26
|
metafile?: string;
|
|
40
27
|
'remove-unused-components'?: boolean;
|
|
41
28
|
'keep-url-references'?: boolean;
|
|
@@ -47,14 +34,7 @@ export async function handleBundle(argv: BundleOptions, config: Config, version:
|
|
|
47
34
|
config.rawConfig?.styleguide?.decorators?.hasOwnProperty('remove-unused-components');
|
|
48
35
|
const apis = await getFallbackApisOrExit(argv.apis, config);
|
|
49
36
|
const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
|
|
50
|
-
const
|
|
51
|
-
const deprecatedOptions: Array<keyof BundleOptions> = [
|
|
52
|
-
'lint',
|
|
53
|
-
'format',
|
|
54
|
-
'skip-rule',
|
|
55
|
-
'extends',
|
|
56
|
-
'max-problems',
|
|
57
|
-
];
|
|
37
|
+
const deprecatedOptions: Array<keyof BundleOptions> = [];
|
|
58
38
|
|
|
59
39
|
checkForDeprecatedOptions(argv, deprecatedOptions);
|
|
60
40
|
|
|
@@ -64,38 +44,9 @@ export async function handleBundle(argv: BundleOptions, config: Config, version:
|
|
|
64
44
|
const resolvedConfig = getMergedConfig(config, alias);
|
|
65
45
|
const { styleguide } = resolvedConfig;
|
|
66
46
|
|
|
67
|
-
styleguide.skipRules(argv['skip-rule']);
|
|
68
47
|
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
69
48
|
styleguide.skipDecorators(argv['skip-decorator']);
|
|
70
49
|
|
|
71
|
-
if (argv.lint) {
|
|
72
|
-
checkIfRulesetExist(styleguide.rules);
|
|
73
|
-
if (config.styleguide.recommendedFallback) {
|
|
74
|
-
process.stderr.write(
|
|
75
|
-
`No configurations were provided -- using built in ${blue(
|
|
76
|
-
'recommended'
|
|
77
|
-
)} configuration by default.\n\n`
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
const results = await lint({
|
|
81
|
-
ref: path,
|
|
82
|
-
config: resolvedConfig,
|
|
83
|
-
});
|
|
84
|
-
const fileLintTotals = getTotals(results);
|
|
85
|
-
|
|
86
|
-
totals.errors += fileLintTotals.errors;
|
|
87
|
-
totals.warnings += fileLintTotals.warnings;
|
|
88
|
-
totals.ignored += fileLintTotals.ignored;
|
|
89
|
-
|
|
90
|
-
formatProblems(results, {
|
|
91
|
-
format: argv.format || 'codeframe',
|
|
92
|
-
totals: fileLintTotals,
|
|
93
|
-
version,
|
|
94
|
-
maxProblems: maxProblems,
|
|
95
|
-
});
|
|
96
|
-
printLintTotals(fileLintTotals, 2);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
50
|
process.stderr.write(gray(`bundling ${path}...\n`));
|
|
100
51
|
|
|
101
52
|
const {
|
|
@@ -132,8 +83,7 @@ export async function handleBundle(argv: BundleOptions, config: Config, version:
|
|
|
132
83
|
totals.ignored += fileTotals.ignored;
|
|
133
84
|
|
|
134
85
|
formatProblems(problems, {
|
|
135
|
-
format:
|
|
136
|
-
maxProblems: maxProblems,
|
|
86
|
+
format: 'codeframe',
|
|
137
87
|
totals: fileTotals,
|
|
138
88
|
version,
|
|
139
89
|
});
|
package/src/commands/join.ts
CHANGED
|
@@ -6,10 +6,8 @@ import {
|
|
|
6
6
|
Config,
|
|
7
7
|
SpecVersion,
|
|
8
8
|
BaseResolver,
|
|
9
|
-
StyleguideConfig,
|
|
10
9
|
formatProblems,
|
|
11
10
|
getTotals,
|
|
12
|
-
lintDocument,
|
|
13
11
|
detectSpec,
|
|
14
12
|
bundleDocument,
|
|
15
13
|
isRef,
|
|
@@ -17,13 +15,10 @@ import {
|
|
|
17
15
|
import {
|
|
18
16
|
getFallbackApisOrExit,
|
|
19
17
|
printExecutionTime,
|
|
20
|
-
handleError,
|
|
21
|
-
printLintTotals,
|
|
22
18
|
exitWithError,
|
|
23
19
|
sortTopLevelKeysForOas,
|
|
24
20
|
getAndValidateFileExtension,
|
|
25
21
|
writeToFileByExtension,
|
|
26
|
-
checkForDeprecatedOptions,
|
|
27
22
|
} from '../utils/miscellaneous';
|
|
28
23
|
import { isObject, isString, keysOf } from '../utils/js-utils';
|
|
29
24
|
import { COMPONENTS, OPENAPI3_METHOD } from './split/types';
|
|
@@ -60,9 +55,6 @@ type JoinDocumentContext = {
|
|
|
60
55
|
|
|
61
56
|
export type JoinOptions = {
|
|
62
57
|
apis: string[];
|
|
63
|
-
lint?: boolean;
|
|
64
|
-
decorate?: boolean;
|
|
65
|
-
preprocess?: boolean;
|
|
66
58
|
'prefix-tags-with-info-prop'?: string;
|
|
67
59
|
'prefix-tags-with-filename'?: boolean;
|
|
68
60
|
'prefix-components-with-info-prop'?: string;
|
|
@@ -79,8 +71,6 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
|
|
79
71
|
return exitWithError(`At least 2 apis should be provided. \n\n`);
|
|
80
72
|
}
|
|
81
73
|
|
|
82
|
-
checkForDeprecatedOptions(argv, ['lint'] as Array<keyof JoinOptions>);
|
|
83
|
-
|
|
84
74
|
const fileExtension = getAndValidateFileExtension(argv.output || argv.apis[0]);
|
|
85
75
|
|
|
86
76
|
const {
|
|
@@ -111,23 +101,19 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
|
|
111
101
|
)
|
|
112
102
|
);
|
|
113
103
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
config.styleguide.skipDecorators(Array.from(decorators));
|
|
121
|
-
}
|
|
104
|
+
const decorators = new Set([
|
|
105
|
+
...Object.keys(config.styleguide.decorators.oas3_0),
|
|
106
|
+
...Object.keys(config.styleguide.decorators.oas3_1),
|
|
107
|
+
...Object.keys(config.styleguide.decorators.oas2),
|
|
108
|
+
]);
|
|
109
|
+
config.styleguide.skipDecorators(Array.from(decorators));
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
config.styleguide.skipPreprocessors(Array.from(preprocessors));
|
|
130
|
-
}
|
|
111
|
+
const preprocessors = new Set([
|
|
112
|
+
...Object.keys(config.styleguide.preprocessors.oas3_0),
|
|
113
|
+
...Object.keys(config.styleguide.preprocessors.oas3_1),
|
|
114
|
+
...Object.keys(config.styleguide.preprocessors.oas2),
|
|
115
|
+
]);
|
|
116
|
+
config.styleguide.skipPreprocessors(Array.from(preprocessors));
|
|
131
117
|
|
|
132
118
|
const bundleResults = await Promise.all(
|
|
133
119
|
documents.map((document) =>
|
|
@@ -146,7 +132,7 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
|
|
146
132
|
if (fileTotals.errors) {
|
|
147
133
|
formatProblems(problems, {
|
|
148
134
|
totals: fileTotals,
|
|
149
|
-
version:
|
|
135
|
+
version: packageVersion,
|
|
150
136
|
});
|
|
151
137
|
exitWithError(
|
|
152
138
|
`❌ Errors encountered while bundling ${blue(
|
|
@@ -179,12 +165,6 @@ export async function handleJoin(argv: JoinOptions, config: Config, packageVersi
|
|
|
179
165
|
}
|
|
180
166
|
}
|
|
181
167
|
|
|
182
|
-
if (argv.lint) {
|
|
183
|
-
for (const document of documents) {
|
|
184
|
-
await validateApi(document, config.styleguide, externalRefResolver, packageVersion);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
168
|
const joinedDef: any = {};
|
|
189
169
|
const potentialConflicts = {
|
|
190
170
|
tags: {},
|
|
@@ -787,22 +767,6 @@ function getInfoPrefix(info: any, prefixArg: string | undefined, type: string) {
|
|
|
787
767
|
return info[prefixArg].replaceAll(/\s/g, '_');
|
|
788
768
|
}
|
|
789
769
|
|
|
790
|
-
async function validateApi(
|
|
791
|
-
document: Document,
|
|
792
|
-
config: StyleguideConfig,
|
|
793
|
-
externalRefResolver: BaseResolver,
|
|
794
|
-
packageVersion: string
|
|
795
|
-
) {
|
|
796
|
-
try {
|
|
797
|
-
const results = await lintDocument({ document, config, externalRefResolver });
|
|
798
|
-
const fileTotals = getTotals(results);
|
|
799
|
-
formatProblems(results, { format: 'stylish', totals: fileTotals, version: packageVersion });
|
|
800
|
-
printLintTotals(fileTotals, 2);
|
|
801
|
-
} catch (err) {
|
|
802
|
-
handleError(err, document.parsed);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
770
|
function replace$Refs(obj: unknown, componentsPrefix: string) {
|
|
807
771
|
crawl(obj, (node: Record<string, unknown>) => {
|
|
808
772
|
if (node.$ref && typeof node.$ref === 'string' && startsWithComponents(node.$ref)) {
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import './utils/assert-node-version';
|
|
4
4
|
import * as yargs from 'yargs';
|
|
5
|
+
import * as colors from 'colorette';
|
|
5
6
|
import { outputExtensions, PushArguments, regionChoices } from './types';
|
|
6
7
|
import { RedoclyClient } from '@redocly/openapi-core';
|
|
7
8
|
import { previewDocs } from './commands/preview-docs';
|
|
@@ -104,9 +105,6 @@ yargs
|
|
|
104
105
|
demandOption: true,
|
|
105
106
|
})
|
|
106
107
|
.option({
|
|
107
|
-
lint: { description: 'Lint descriptions', type: 'boolean', default: false, hidden: true },
|
|
108
|
-
decorate: { description: 'Run decorators', type: 'boolean', default: false },
|
|
109
|
-
preprocess: { description: 'Run preprocessors', type: 'boolean', default: false },
|
|
110
108
|
'prefix-tags-with-info-prop': {
|
|
111
109
|
description: 'Prefix tags with property value from info object.',
|
|
112
110
|
requiresArg: true,
|
|
@@ -141,8 +139,47 @@ yargs
|
|
|
141
139
|
choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
|
|
142
140
|
default: 'warn' as RuleSeverity,
|
|
143
141
|
},
|
|
142
|
+
lint: {
|
|
143
|
+
hidden: true,
|
|
144
|
+
deprecated: true,
|
|
145
|
+
},
|
|
146
|
+
decorate: {
|
|
147
|
+
hidden: true,
|
|
148
|
+
deprecated: true,
|
|
149
|
+
},
|
|
150
|
+
preprocess: {
|
|
151
|
+
hidden: true,
|
|
152
|
+
deprecated: true,
|
|
153
|
+
},
|
|
144
154
|
}),
|
|
145
155
|
(argv) => {
|
|
156
|
+
const DEPRECATED_OPTIONS = ['lint', 'preprocess', 'decorate'];
|
|
157
|
+
const DECORATORS_DOCUMENTATION_LINK = 'https://redocly.com/docs/cli/decorators/#decorators';
|
|
158
|
+
const JOIN_COMMAND_DOCUMENTATION_LINK = 'https://redocly.com/docs/cli/commands/join/#join';
|
|
159
|
+
|
|
160
|
+
DEPRECATED_OPTIONS.forEach((option) => {
|
|
161
|
+
if (argv[option]) {
|
|
162
|
+
process.stdout.write(
|
|
163
|
+
`${colors.red(
|
|
164
|
+
`Option --${option} is no longer supported. Please review join command documentation ${JOIN_COMMAND_DOCUMENTATION_LINK}.`
|
|
165
|
+
)}`
|
|
166
|
+
);
|
|
167
|
+
process.stdout.write('\n\n');
|
|
168
|
+
|
|
169
|
+
if (['preprocess', 'decorate'].includes(option)) {
|
|
170
|
+
process.stdout.write(
|
|
171
|
+
`${colors.red(
|
|
172
|
+
`If you are looking for decorators, please review the decorators documentation ${DECORATORS_DOCUMENTATION_LINK}.`
|
|
173
|
+
)}`
|
|
174
|
+
);
|
|
175
|
+
process.stdout.write('\n\n');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
yargs.showHelp();
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
146
183
|
process.env.REDOCLY_CLI_COMMAND = 'join';
|
|
147
184
|
commandWrapper(handleJoin)(argv);
|
|
148
185
|
}
|
|
@@ -360,6 +397,7 @@ yargs
|
|
|
360
397
|
'checkstyle',
|
|
361
398
|
'codeclimate',
|
|
362
399
|
'summary',
|
|
400
|
+
'github-actions',
|
|
363
401
|
] as ReadonlyArray<OutputFormat>,
|
|
364
402
|
default: 'codeframe' as OutputFormat,
|
|
365
403
|
},
|
|
@@ -415,28 +453,11 @@ yargs
|
|
|
415
453
|
description: 'Output file.',
|
|
416
454
|
alias: 'o',
|
|
417
455
|
},
|
|
418
|
-
format: {
|
|
419
|
-
description: 'Use a specific output format.',
|
|
420
|
-
choices: ['stylish', 'codeframe', 'json', 'checkstyle'] as ReadonlyArray<OutputFormat>,
|
|
421
|
-
hidden: true,
|
|
422
|
-
},
|
|
423
|
-
'max-problems': {
|
|
424
|
-
requiresArg: true,
|
|
425
|
-
description: 'Reduce output to a maximum of N problems.',
|
|
426
|
-
type: 'number',
|
|
427
|
-
hidden: true,
|
|
428
|
-
},
|
|
429
456
|
ext: {
|
|
430
457
|
description: 'Bundle file extension.',
|
|
431
458
|
requiresArg: true,
|
|
432
459
|
choices: outputExtensions,
|
|
433
460
|
},
|
|
434
|
-
'skip-rule': {
|
|
435
|
-
description: 'Ignore certain rules.',
|
|
436
|
-
array: true,
|
|
437
|
-
type: 'string',
|
|
438
|
-
hidden: true,
|
|
439
|
-
},
|
|
440
461
|
'skip-preprocessor': {
|
|
441
462
|
description: 'Ignore certain preprocessors.',
|
|
442
463
|
array: true,
|
|
@@ -461,12 +482,6 @@ yargs
|
|
|
461
482
|
description: 'Path to the config file.',
|
|
462
483
|
type: 'string',
|
|
463
484
|
},
|
|
464
|
-
lint: {
|
|
465
|
-
description: 'Lint API descriptions',
|
|
466
|
-
type: 'boolean',
|
|
467
|
-
default: false,
|
|
468
|
-
hidden: true,
|
|
469
|
-
},
|
|
470
485
|
metafile: {
|
|
471
486
|
description: 'Produce metadata about the bundle',
|
|
472
487
|
type: 'string',
|
|
@@ -493,8 +508,43 @@ yargs
|
|
|
493
508
|
choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
|
|
494
509
|
default: 'warn' as RuleSeverity,
|
|
495
510
|
},
|
|
511
|
+
format: {
|
|
512
|
+
hidden: true,
|
|
513
|
+
deprecated: true,
|
|
514
|
+
},
|
|
515
|
+
lint: {
|
|
516
|
+
hidden: true,
|
|
517
|
+
deprecated: true,
|
|
518
|
+
},
|
|
519
|
+
'skip-rule': {
|
|
520
|
+
hidden: true,
|
|
521
|
+
deprecated: true,
|
|
522
|
+
array: true,
|
|
523
|
+
type: 'string',
|
|
524
|
+
},
|
|
525
|
+
'max-problems': {
|
|
526
|
+
hidden: true,
|
|
527
|
+
deprecated: true,
|
|
528
|
+
},
|
|
496
529
|
}),
|
|
497
530
|
(argv) => {
|
|
531
|
+
const DEPRECATED_OPTIONS = ['lint', 'format', 'skip-rule', 'max-problems'];
|
|
532
|
+
const LINT_AND_BUNDLE_DOCUMENTATION_LINK =
|
|
533
|
+
'https://redocly.com/docs/cli/guides/lint-and-bundle/#lint-and-bundle-api-descriptions-with-redocly-cli';
|
|
534
|
+
|
|
535
|
+
DEPRECATED_OPTIONS.forEach((option) => {
|
|
536
|
+
if (argv[option]) {
|
|
537
|
+
process.stdout.write(
|
|
538
|
+
`${colors.red(
|
|
539
|
+
`Option --${option} is no longer supported. Please use separate commands, as described in the ${LINT_AND_BUNDLE_DOCUMENTATION_LINK}.`
|
|
540
|
+
)}`
|
|
541
|
+
);
|
|
542
|
+
process.stdout.write('\n\n');
|
|
543
|
+
yargs.showHelp();
|
|
544
|
+
process.exit(1);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
|
|
498
548
|
process.env.REDOCLY_CLI_COMMAND = 'bundle';
|
|
499
549
|
commandWrapper(handleBundle)(argv);
|
|
500
550
|
}
|