@redocly/cli 1.3.0 → 1.4.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 +12 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +1 -0
- package/lib/__mocks__/@redocly/openapi-core.js +4 -3
- package/lib/__mocks__/utils.d.ts +2 -0
- package/lib/__mocks__/utils.js +3 -1
- package/lib/__tests__/commands/build-docs.test.js +2 -2
- package/lib/__tests__/commands/bundle.test.js +7 -7
- package/lib/__tests__/commands/join.test.js +25 -18
- package/lib/__tests__/commands/lint.test.js +15 -15
- package/lib/__tests__/commands/push-region.test.js +2 -2
- package/lib/__tests__/commands/push.test.js +30 -30
- package/lib/__tests__/fetch-with-timeout.test.js +2 -2
- package/lib/__tests__/utils.test.js +63 -32
- package/lib/__tests__/wrapper.test.js +3 -3
- package/lib/assert-node-version.js +1 -1
- package/lib/commands/build-docs/index.js +9 -9
- package/lib/commands/build-docs/types.d.ts +2 -2
- package/lib/commands/build-docs/utils.js +10 -10
- package/lib/commands/bundle.d.ts +1 -1
- package/lib/commands/bundle.js +25 -25
- package/lib/commands/join.d.ts +1 -1
- package/lib/commands/join.js +49 -48
- package/lib/commands/lint.d.ts +1 -1
- package/lib/commands/lint.js +22 -22
- package/lib/commands/login.d.ts +1 -1
- package/lib/commands/login.js +3 -3
- package/lib/commands/preview-docs/index.d.ts +1 -1
- package/lib/commands/preview-docs/index.js +7 -7
- package/lib/commands/preview-docs/preview-server/hot.js +19 -2
- package/lib/commands/preview-docs/preview-server/preview-server.js +15 -14
- package/lib/commands/preview-docs/preview-server/server.d.ts +3 -1
- package/lib/commands/preview-docs/preview-server/server.js +2 -2
- package/lib/commands/push.d.ts +2 -2
- package/lib/commands/push.js +31 -31
- package/lib/commands/split/__tests__/index.test.js +9 -9
- package/lib/commands/split/index.d.ts +2 -2
- package/lib/commands/split/index.js +41 -40
- package/lib/commands/split/types.d.ts +2 -2
- package/lib/commands/split/types.js +2 -2
- package/lib/commands/stats.d.ts +1 -1
- package/lib/commands/stats.js +9 -9
- package/lib/fetch-with-timeout.js +5 -2
- package/lib/index.js +11 -12
- package/lib/types.d.ts +6 -6
- package/lib/update-version-notifier.js +18 -18
- package/lib/utils.d.ts +6 -3
- package/lib/utils.js +66 -38
- package/lib/wrapper.js +5 -5
- package/package.json +3 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__mocks__/utils.ts +2 -0
- package/src/__tests__/commands/join.test.ts +37 -7
- package/src/__tests__/utils.test.ts +45 -1
- package/src/commands/join.ts +8 -3
- package/src/commands/preview-docs/preview-server/hot.js +19 -2
- package/src/commands/preview-docs/preview-server/preview-server.ts +6 -4
- package/src/commands/preview-docs/preview-server/server.ts +2 -2
- package/src/commands/split/__tests__/index.test.ts +14 -5
- package/src/commands/split/index.ts +25 -17
- package/src/fetch-with-timeout.ts +3 -0
- package/src/index.ts +0 -1
- package/src/utils.ts +40 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -21,7 +21,7 @@ describe('fetchWithTimeout', () => {
|
|
|
21
21
|
global.AbortController = undefined;
|
|
22
22
|
// @ts-ignore
|
|
23
23
|
global.setTimeout = jest.fn();
|
|
24
|
-
yield fetch_with_timeout_1.default('url', { method: 'GET' });
|
|
24
|
+
yield (0, fetch_with_timeout_1.default)('url', { method: 'GET' });
|
|
25
25
|
expect(node_fetch_1.default).toHaveBeenCalledWith('url', { method: 'GET' });
|
|
26
26
|
expect(global.setTimeout).toHaveBeenCalledTimes(0);
|
|
27
27
|
}));
|
|
@@ -30,7 +30,7 @@ describe('fetchWithTimeout', () => {
|
|
|
30
30
|
// @ts-ignore
|
|
31
31
|
global.setTimeout = jest.fn();
|
|
32
32
|
global.clearTimeout = jest.fn();
|
|
33
|
-
yield fetch_with_timeout_1.default('url');
|
|
33
|
+
yield (0, fetch_with_timeout_1.default)('url');
|
|
34
34
|
expect(global.setTimeout).toHaveBeenCalledTimes(1);
|
|
35
35
|
expect(node_fetch_1.default).toHaveBeenCalledWith('url', { signal: 'something' });
|
|
36
36
|
expect(global.clearTimeout).toHaveBeenCalledTimes(1);
|
|
@@ -31,7 +31,7 @@ describe('isSubdir', () => {
|
|
|
31
31
|
['/foo', './bar', false],
|
|
32
32
|
['/foo', '/foo/..bar', true],
|
|
33
33
|
].forEach(([parent, child, expectRes]) => {
|
|
34
|
-
expect(utils_1.isSubdir(parent, child)).toBe(expectRes);
|
|
34
|
+
expect((0, utils_1.isSubdir)(parent, child)).toBe(expectRes);
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
it('can correctly determine if subdir for windows-based paths', () => {
|
|
@@ -42,7 +42,7 @@ describe('isSubdir', () => {
|
|
|
42
42
|
['C:\\Foo', 'C:\\Bar', false],
|
|
43
43
|
['C:\\Foo', 'D:\\Foo\\Bar', false],
|
|
44
44
|
].forEach(([parent, child, expectRes]) => {
|
|
45
|
-
expect(utils_1.isSubdir(parent, child)).toBe(expectRes);
|
|
45
|
+
expect((0, utils_1.isSubdir)(parent, child)).toBe(expectRes);
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
afterEach(() => {
|
|
@@ -51,14 +51,14 @@ describe('isSubdir', () => {
|
|
|
51
51
|
});
|
|
52
52
|
describe('pathToFilename', () => {
|
|
53
53
|
it('should use correct path separator', () => {
|
|
54
|
-
const processedPath = utils_1.pathToFilename('/user/createWithList', '_');
|
|
54
|
+
const processedPath = (0, utils_1.pathToFilename)('/user/createWithList', '_');
|
|
55
55
|
expect(processedPath).toEqual('user_createWithList');
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
describe('getFallbackApisOrExit', () => {
|
|
59
59
|
it('should find alias by filename', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
60
|
fs_1.existsSync.mockImplementationOnce(() => true);
|
|
61
|
-
const entry = yield utils_1.getFallbackApisOrExit(['./test.yaml'], {
|
|
61
|
+
const entry = yield (0, utils_1.getFallbackApisOrExit)(['./test.yaml'], {
|
|
62
62
|
apis: {
|
|
63
63
|
main: {
|
|
64
64
|
root: 'test.yaml',
|
|
@@ -82,17 +82,17 @@ describe('printConfigLintTotals', () => {
|
|
|
82
82
|
jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
83
83
|
});
|
|
84
84
|
it('should print errors if such exist', () => {
|
|
85
|
-
utils_1.printConfigLintTotals(totalProblemsMock);
|
|
85
|
+
(0, utils_1.printConfigLintTotals)(totalProblemsMock);
|
|
86
86
|
expect(process.stderr.write).toHaveBeenCalledWith('❌ Your config has 1 error.');
|
|
87
87
|
expect(redColoretteMocks).toHaveBeenCalledWith('❌ Your config has 1 error.');
|
|
88
88
|
});
|
|
89
89
|
it('should print warnign if no error', () => {
|
|
90
|
-
utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 }));
|
|
90
|
+
(0, utils_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0, warnings: 2 }));
|
|
91
91
|
expect(process.stderr.write).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
|
|
92
92
|
expect(yellowColoretteMocks).toHaveBeenCalledWith('⚠️ Your config has 2 warnings.\n');
|
|
93
93
|
});
|
|
94
94
|
it('should print nothing if no error and no warnings', () => {
|
|
95
|
-
const result = utils_1.printConfigLintTotals(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 }));
|
|
95
|
+
const result = (0, utils_1.printConfigLintTotals)(Object.assign(Object.assign({}, totalProblemsMock), { errors: 0 }));
|
|
96
96
|
expect(result).toBeUndefined();
|
|
97
97
|
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
98
98
|
expect(yellowColoretteMocks).toHaveBeenCalledTimes(0);
|
|
@@ -124,7 +124,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
124
124
|
};
|
|
125
125
|
expect.assertions(1);
|
|
126
126
|
try {
|
|
127
|
-
yield utils_1.getFallbackApisOrExit([''], apisConfig);
|
|
127
|
+
yield (0, utils_1.getFallbackApisOrExit)([''], apisConfig);
|
|
128
128
|
}
|
|
129
129
|
catch (e) {
|
|
130
130
|
expect(e.message).toEqual('Path cannot be empty.');
|
|
@@ -134,7 +134,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
134
134
|
fs_1.existsSync.mockImplementationOnce(() => false);
|
|
135
135
|
expect.assertions(3);
|
|
136
136
|
try {
|
|
137
|
-
yield utils_1.getFallbackApisOrExit(undefined, config);
|
|
137
|
+
yield (0, utils_1.getFallbackApisOrExit)(undefined, config);
|
|
138
138
|
}
|
|
139
139
|
catch (e) {
|
|
140
140
|
expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
|
|
@@ -145,7 +145,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
145
145
|
it('should return valid array with results if such file exist', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
146
146
|
fs_1.existsSync.mockImplementationOnce(() => true);
|
|
147
147
|
jest.spyOn(path, 'resolve').mockImplementationOnce((_, path) => path);
|
|
148
|
-
const result = yield utils_1.getFallbackApisOrExit(undefined, config);
|
|
148
|
+
const result = yield (0, utils_1.getFallbackApisOrExit)(undefined, config);
|
|
149
149
|
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
150
150
|
expect(process.exit).toHaveBeenCalledTimes(0);
|
|
151
151
|
expect(result).toStrictEqual([
|
|
@@ -162,7 +162,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
162
162
|
fs_1.existsSync.mockImplementationOnce(() => false);
|
|
163
163
|
expect.assertions(3);
|
|
164
164
|
try {
|
|
165
|
-
yield utils_1.getFallbackApisOrExit(['someFile.yaml'], apisConfig);
|
|
165
|
+
yield (0, utils_1.getFallbackApisOrExit)(['someFile.yaml'], apisConfig);
|
|
166
166
|
}
|
|
167
167
|
catch (e) {
|
|
168
168
|
expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
|
|
@@ -177,7 +177,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
177
177
|
fs_1.existsSync.mockImplementationOnce(() => false);
|
|
178
178
|
expect.assertions(3);
|
|
179
179
|
try {
|
|
180
|
-
yield utils_1.getFallbackApisOrExit(['someFile.yaml', 'someFile2.yaml'], apisConfig);
|
|
180
|
+
yield (0, utils_1.getFallbackApisOrExit)(['someFile.yaml', 'someFile2.yaml'], apisConfig);
|
|
181
181
|
}
|
|
182
182
|
catch (e) {
|
|
183
183
|
expect(process.stderr.write).toHaveBeenCalledWith('\nsomeFile.yaml does not exist or is invalid.\n\n');
|
|
@@ -194,7 +194,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
194
194
|
const existSyncMock = fs_1.existsSync.mockImplementation((path) => path.endsWith('someFile.yaml'));
|
|
195
195
|
expect.assertions(4);
|
|
196
196
|
try {
|
|
197
|
-
yield utils_1.getFallbackApisOrExit(undefined, configStub);
|
|
197
|
+
yield (0, utils_1.getFallbackApisOrExit)(undefined, configStub);
|
|
198
198
|
}
|
|
199
199
|
catch (e) {
|
|
200
200
|
expect(process.stderr.write).toHaveBeenCalledWith('\nnotExist.yaml does not exist or is invalid.\n\n');
|
|
@@ -215,7 +215,7 @@ describe('getFallbackApisOrExit', () => {
|
|
|
215
215
|
},
|
|
216
216
|
},
|
|
217
217
|
};
|
|
218
|
-
const result = yield utils_1.getFallbackApisOrExit(undefined, apisConfig);
|
|
218
|
+
const result = yield (0, utils_1.getFallbackApisOrExit)(undefined, apisConfig);
|
|
219
219
|
expect(process.stderr.write).toHaveBeenCalledTimes(0);
|
|
220
220
|
expect(result).toStrictEqual([
|
|
221
221
|
{
|
|
@@ -236,10 +236,10 @@ describe('langToExt', () => {
|
|
|
236
236
|
['js', '.js'],
|
|
237
237
|
['python', '.py'],
|
|
238
238
|
])('should infer file extension from lang - %s', (lang, expected) => {
|
|
239
|
-
expect(utils_1.langToExt(lang)).toBe(expected);
|
|
239
|
+
expect((0, utils_1.langToExt)(lang)).toBe(expected);
|
|
240
240
|
});
|
|
241
241
|
it('should ignore case when inferring file extension', () => {
|
|
242
|
-
expect(utils_1.langToExt('JavaScript')).toBe('.js');
|
|
242
|
+
expect((0, utils_1.langToExt)('JavaScript')).toBe('.js');
|
|
243
243
|
});
|
|
244
244
|
});
|
|
245
245
|
describe('sorTopLevelKeysForOas', () => {
|
|
@@ -270,7 +270,7 @@ describe('sorTopLevelKeysForOas', () => {
|
|
|
270
270
|
'x-webhooks',
|
|
271
271
|
'components',
|
|
272
272
|
];
|
|
273
|
-
const result = utils_1.sortTopLevelKeysForOas(openApi);
|
|
273
|
+
const result = (0, utils_1.sortTopLevelKeysForOas)(openApi);
|
|
274
274
|
Object.keys(result).forEach((key, index) => {
|
|
275
275
|
expect(key).toEqual(orderedKeys[index]);
|
|
276
276
|
});
|
|
@@ -310,7 +310,7 @@ describe('sorTopLevelKeysForOas', () => {
|
|
|
310
310
|
'responses',
|
|
311
311
|
'securityDefinitions',
|
|
312
312
|
];
|
|
313
|
-
const result = utils_1.sortTopLevelKeysForOas(openApi);
|
|
313
|
+
const result = (0, utils_1.sortTopLevelKeysForOas)(openApi);
|
|
314
314
|
Object.keys(result).forEach((key, index) => {
|
|
315
315
|
expect(key).toEqual(orderedKeys[index]);
|
|
316
316
|
});
|
|
@@ -331,31 +331,31 @@ describe('handleErrors', () => {
|
|
|
331
331
|
});
|
|
332
332
|
it('should handle ResolveError', () => {
|
|
333
333
|
const resolveError = new openapi_core_1.ResolveError(new Error('File not found'));
|
|
334
|
-
expect(() => utils_1.handleError(resolveError, ref)).toThrowError(utils_1.HandledError);
|
|
334
|
+
expect(() => (0, utils_1.handleError)(resolveError, ref)).toThrowError(utils_1.HandledError);
|
|
335
335
|
expect(redColoretteMocks).toHaveBeenCalledTimes(1);
|
|
336
336
|
expect(process.stderr.write).toHaveBeenCalledWith(`Failed to resolve API description at openapi/test.yaml:\n\n - File not found.\n\n`);
|
|
337
337
|
});
|
|
338
338
|
it('should handle YamlParseError', () => {
|
|
339
339
|
const yamlParseError = new openapi_core_1.YamlParseError(new Error('Invalid yaml'), {});
|
|
340
|
-
expect(() => utils_1.handleError(yamlParseError, ref)).toThrowError(utils_1.HandledError);
|
|
340
|
+
expect(() => (0, utils_1.handleError)(yamlParseError, ref)).toThrowError(utils_1.HandledError);
|
|
341
341
|
expect(redColoretteMocks).toHaveBeenCalledTimes(1);
|
|
342
342
|
expect(process.stderr.write).toHaveBeenCalledWith(`Failed to parse API description at openapi/test.yaml:\n\n - Invalid yaml.\n\n`);
|
|
343
343
|
});
|
|
344
344
|
it('should handle CircularJSONNotSupportedError', () => {
|
|
345
345
|
const circularError = new utils_1.CircularJSONNotSupportedError(new Error('Circular json'));
|
|
346
|
-
expect(() => utils_1.handleError(circularError, ref)).toThrowError(utils_1.HandledError);
|
|
346
|
+
expect(() => (0, utils_1.handleError)(circularError, ref)).toThrowError(utils_1.HandledError);
|
|
347
347
|
expect(process.stderr.write).toHaveBeenCalledWith(`Detected circular reference which can't be converted to JSON.\n` +
|
|
348
|
-
`Try to use ${colorette_1.blue('yaml')} output or remove ${colorette_1.blue('--dereferenced')}.\n\n`);
|
|
348
|
+
`Try to use ${(0, colorette_1.blue)('yaml')} output or remove ${(0, colorette_1.blue)('--dereferenced')}.\n\n`);
|
|
349
349
|
});
|
|
350
350
|
it('should handle SyntaxError', () => {
|
|
351
351
|
const testError = new SyntaxError('Unexpected identifier');
|
|
352
352
|
testError.stack = 'test stack';
|
|
353
|
-
expect(() => utils_1.handleError(testError, ref)).toThrowError(utils_1.HandledError);
|
|
353
|
+
expect(() => (0, utils_1.handleError)(testError, ref)).toThrowError(utils_1.HandledError);
|
|
354
354
|
expect(process.stderr.write).toHaveBeenCalledWith('Syntax error: Unexpected identifier test stack\n\n');
|
|
355
355
|
});
|
|
356
356
|
it('should throw unknown error', () => {
|
|
357
357
|
const testError = new Error('Test error');
|
|
358
|
-
expect(() => utils_1.handleError(testError, ref)).toThrowError(utils_1.HandledError);
|
|
358
|
+
expect(() => (0, utils_1.handleError)(testError, ref)).toThrowError(utils_1.HandledError);
|
|
359
359
|
expect(process.stderr.write).toHaveBeenCalledWith(`Something went wrong when processing openapi/test.yaml:\n\n - Test error.\n\n`);
|
|
360
360
|
});
|
|
361
361
|
});
|
|
@@ -373,7 +373,7 @@ describe('checkIfRulesetExist', () => {
|
|
|
373
373
|
oas3_1: {},
|
|
374
374
|
async2: {},
|
|
375
375
|
};
|
|
376
|
-
expect(() => utils_1.checkIfRulesetExist(rules)).toThrowError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
|
|
376
|
+
expect(() => (0, utils_1.checkIfRulesetExist)(rules)).toThrowError('⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/');
|
|
377
377
|
});
|
|
378
378
|
it('should not throw an error if rules are provided', () => {
|
|
379
379
|
const rules = {
|
|
@@ -381,13 +381,13 @@ describe('checkIfRulesetExist', () => {
|
|
|
381
381
|
oas3_0: {},
|
|
382
382
|
oas3_1: {},
|
|
383
383
|
};
|
|
384
|
-
utils_1.checkIfRulesetExist(rules);
|
|
384
|
+
(0, utils_1.checkIfRulesetExist)(rules);
|
|
385
385
|
});
|
|
386
386
|
});
|
|
387
387
|
describe('cleanColors', () => {
|
|
388
388
|
it('should remove colors from string', () => {
|
|
389
|
-
const stringWithColors = `String for ${colorette_1.red('test')}`;
|
|
390
|
-
const result = utils_1.cleanColors(stringWithColors);
|
|
389
|
+
const stringWithColors = `String for ${(0, colorette_1.red)('test')}`;
|
|
390
|
+
const result = (0, utils_1.cleanColors)(stringWithColors);
|
|
391
391
|
expect(result).not.toMatch(/\x1b\[\d+m/g);
|
|
392
392
|
});
|
|
393
393
|
});
|
|
@@ -409,7 +409,7 @@ describe('cleanArgs', () => {
|
|
|
409
409
|
apis: ['main@v1', 'fixtures/openapi.yaml', 'http://some.url/openapi.yaml'],
|
|
410
410
|
format: 'codeframe',
|
|
411
411
|
};
|
|
412
|
-
expect(utils_1.cleanArgs(testArgs)).toEqual({
|
|
412
|
+
expect((0, utils_1.cleanArgs)(testArgs)).toEqual({
|
|
413
413
|
config: 'file-yaml',
|
|
414
414
|
apis: ['api-name@api-version', 'file-yaml', 'http://url'],
|
|
415
415
|
format: 'codeframe',
|
|
@@ -419,7 +419,7 @@ describe('cleanArgs', () => {
|
|
|
419
419
|
const testArgs = {
|
|
420
420
|
destination: '@org/name@version',
|
|
421
421
|
};
|
|
422
|
-
expect(utils_1.cleanArgs(testArgs)).toEqual({
|
|
422
|
+
expect((0, utils_1.cleanArgs)(testArgs)).toEqual({
|
|
423
423
|
destination: '@organization/api-name@api-version',
|
|
424
424
|
});
|
|
425
425
|
});
|
|
@@ -447,7 +447,7 @@ describe('cleanRawInput', () => {
|
|
|
447
447
|
'--output',
|
|
448
448
|
'fixtures',
|
|
449
449
|
];
|
|
450
|
-
expect(utils_1.cleanRawInput(rawInput)).toEqual('redocly bundle api-name@api-version file-yaml http://url --config=file-yaml --output folder');
|
|
450
|
+
expect((0, utils_1.cleanRawInput)(rawInput)).toEqual('redocly bundle api-name@api-version file-yaml http://url --config=file-yaml --output folder');
|
|
451
451
|
});
|
|
452
452
|
it('should preserve safe data from raw CLI input', () => {
|
|
453
453
|
const rawInput = [
|
|
@@ -460,6 +460,37 @@ describe('cleanRawInput', () => {
|
|
|
460
460
|
'--skip-rule',
|
|
461
461
|
'operation-4xx-response',
|
|
462
462
|
];
|
|
463
|
-
expect(utils_1.cleanRawInput(rawInput)).toEqual('redocly lint file-json --format stylish --extends=minimal --skip-rule operation-4xx-response');
|
|
463
|
+
expect((0, utils_1.cleanRawInput)(rawInput)).toEqual('redocly lint file-json --format stylish --extends=minimal --skip-rule operation-4xx-response');
|
|
464
|
+
});
|
|
465
|
+
describe('validateFileExtension', () => {
|
|
466
|
+
it('should return current file extension', () => {
|
|
467
|
+
expect((0, utils_1.getAndValidateFileExtension)('test.json')).toEqual('json');
|
|
468
|
+
});
|
|
469
|
+
it('should return yaml and print warning if file extension does not supported', () => {
|
|
470
|
+
const stderrMock = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
471
|
+
colorette_1.yellow.mockImplementation((text) => text);
|
|
472
|
+
expect((0, utils_1.getAndValidateFileExtension)('test.xml')).toEqual('yaml');
|
|
473
|
+
expect(stderrMock).toHaveBeenCalledWith(`Unsupported file extension: xml. Using yaml.\n`);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
describe('writeToFileByExtension', () => {
|
|
477
|
+
beforeEach(() => {
|
|
478
|
+
jest.spyOn(process.stderr, 'write').mockImplementation(jest.fn());
|
|
479
|
+
colorette_1.yellow.mockImplementation((text) => text);
|
|
480
|
+
});
|
|
481
|
+
afterEach(() => {
|
|
482
|
+
jest.restoreAllMocks();
|
|
483
|
+
});
|
|
484
|
+
it('should call stringifyYaml function', () => {
|
|
485
|
+
(0, utils_1.writeToFileByExtension)('test data', 'test.yaml');
|
|
486
|
+
expect(openapi_core_1.stringifyYaml).toHaveBeenCalledWith('test data', { noRefs: false });
|
|
487
|
+
expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
|
|
488
|
+
});
|
|
489
|
+
it('should call JSON.stringify function', () => {
|
|
490
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify').mockImplementation((data) => data);
|
|
491
|
+
(0, utils_1.writeToFileByExtension)('test data', 'test.json');
|
|
492
|
+
expect(stringifySpy).toHaveBeenCalledWith('test data', null, 2);
|
|
493
|
+
expect(process.stderr.write).toHaveBeenCalledWith(`test data`);
|
|
494
|
+
});
|
|
464
495
|
});
|
|
465
496
|
});
|
|
@@ -29,7 +29,7 @@ describe('commandWrapper', () => {
|
|
|
29
29
|
return { telemetry: 'on', styleguide: { recommendedFallback: true } };
|
|
30
30
|
});
|
|
31
31
|
process.env.REDOCLY_TELEMETRY = 'on';
|
|
32
|
-
const wrappedHandler = wrapper_1.commandWrapper(lint_1.handleLint);
|
|
32
|
+
const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
|
|
33
33
|
yield wrappedHandler({});
|
|
34
34
|
expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
|
|
35
35
|
expect(utils_1.sendTelemetry).toHaveBeenCalledTimes(1);
|
|
@@ -40,7 +40,7 @@ describe('commandWrapper', () => {
|
|
|
40
40
|
return { telemetry: 'off', styleguide: { recommendedFallback: true } };
|
|
41
41
|
});
|
|
42
42
|
process.env.REDOCLY_TELEMETRY = 'on';
|
|
43
|
-
const wrappedHandler = wrapper_1.commandWrapper(lint_1.handleLint);
|
|
43
|
+
const wrappedHandler = (0, wrapper_1.commandWrapper)(lint_1.handleLint);
|
|
44
44
|
yield wrappedHandler({});
|
|
45
45
|
expect(lint_1.handleLint).toHaveBeenCalledTimes(1);
|
|
46
46
|
expect(utils_1.sendTelemetry).toHaveBeenCalledTimes(0);
|
|
@@ -51,7 +51,7 @@ describe('commandWrapper', () => {
|
|
|
51
51
|
const argv = {
|
|
52
52
|
files: filesToPush,
|
|
53
53
|
};
|
|
54
|
-
yield wrapper_1.commandWrapper(push_1.handlePush)(argv);
|
|
54
|
+
yield (0, wrapper_1.commandWrapper)(push_1.handlePush)(argv);
|
|
55
55
|
expect(loadConfigMock).toHaveBeenCalledWith(expect.objectContaining({ files: filesToPush }));
|
|
56
56
|
}));
|
|
57
57
|
});
|
|
@@ -8,7 +8,7 @@ try {
|
|
|
8
8
|
const { engines } = require(path.join(__dirname, '../package.json'));
|
|
9
9
|
const version = engines.node;
|
|
10
10
|
if (!semver.satisfies(process.version, version)) {
|
|
11
|
-
process.stderr.write(colorette_1.yellow(`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${version}", Current "${process.version}"\n\n`));
|
|
11
|
+
process.stderr.write((0, colorette_1.yellow)(`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${version}", Current "${process.version}"\n\n`));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
catch (e) {
|
|
@@ -20,8 +20,8 @@ const utils_2 = require("../../utils");
|
|
|
20
20
|
const handlerBuildCommand = (argv, configFromFile) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
var _a;
|
|
22
22
|
const startedAt = perf_hooks_1.performance.now();
|
|
23
|
-
const config = openapi_core_1.getMergedConfig(configFromFile, argv.api);
|
|
24
|
-
const apis = yield utils_2.getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
|
|
23
|
+
const config = (0, openapi_core_1.getMergedConfig)(configFromFile, argv.api);
|
|
24
|
+
const apis = yield (0, utils_2.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
|
|
25
25
|
const { path: pathToApi } = apis[0];
|
|
26
26
|
const options = {
|
|
27
27
|
output: argv.o,
|
|
@@ -29,20 +29,20 @@ const handlerBuildCommand = (argv, configFromFile) => __awaiter(void 0, void 0,
|
|
|
29
29
|
disableGoogleFont: argv.disableGoogleFont,
|
|
30
30
|
templateFileName: argv.template,
|
|
31
31
|
templateOptions: argv.templateOptions || {},
|
|
32
|
-
redocOptions: utils_1.getObjectOrJSON((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi, config),
|
|
32
|
+
redocOptions: (0, utils_1.getObjectOrJSON)((_a = argv.theme) === null || _a === void 0 ? void 0 : _a.openapi, config),
|
|
33
33
|
};
|
|
34
34
|
const redocCurrentVersion = require('../../../package.json').dependencies.redoc.substring(1); // remove ~
|
|
35
35
|
try {
|
|
36
|
-
const elapsed = utils_2.getExecutionTime(startedAt);
|
|
37
|
-
const api = yield redoc_1.loadAndBundleSpec(openapi_core_1.isAbsoluteUrl(pathToApi) ? pathToApi : path_1.resolve(pathToApi));
|
|
38
|
-
const pageHTML = yield utils_1.getPageHTML(api, pathToApi, Object.assign(Object.assign({}, options), { redocCurrentVersion }), argv.config);
|
|
39
|
-
fs_1.mkdirSync(path_1.dirname(options.output), { recursive: true });
|
|
40
|
-
fs_1.writeFileSync(options.output, pageHTML);
|
|
36
|
+
const elapsed = (0, utils_2.getExecutionTime)(startedAt);
|
|
37
|
+
const api = yield (0, redoc_1.loadAndBundleSpec)((0, openapi_core_1.isAbsoluteUrl)(pathToApi) ? pathToApi : (0, path_1.resolve)(pathToApi));
|
|
38
|
+
const pageHTML = yield (0, utils_1.getPageHTML)(api, pathToApi, Object.assign(Object.assign({}, options), { redocCurrentVersion }), argv.config);
|
|
39
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(options.output), { recursive: true });
|
|
40
|
+
(0, fs_1.writeFileSync)(options.output, pageHTML);
|
|
41
41
|
const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
|
|
42
42
|
process.stdout.write(`\n🎉 bundled successfully in: ${options.output} (${sizeInKiB} KiB) [⏱ ${elapsed}].\n`);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
|
-
utils_2.exitWithError(e);
|
|
45
|
+
(0, utils_2.exitWithError)(e);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
exports.handlerBuildCommand = handlerBuildCommand;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type BuildDocsOptions = {
|
|
2
2
|
watch?: boolean;
|
|
3
3
|
output?: string;
|
|
4
4
|
title?: string;
|
|
@@ -9,7 +9,7 @@ export declare type BuildDocsOptions = {
|
|
|
9
9
|
redocOptions?: any;
|
|
10
10
|
redocCurrentVersion: string;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type BuildDocsArgv = {
|
|
13
13
|
api: string;
|
|
14
14
|
o: string;
|
|
15
15
|
title?: string;
|
|
@@ -26,16 +26,16 @@ function getObjectOrJSON(openapiOptions, config) {
|
|
|
26
26
|
return openapiOptions;
|
|
27
27
|
case 'string':
|
|
28
28
|
try {
|
|
29
|
-
if (fs_1.existsSync(openapiOptions) && fs_1.lstatSync(openapiOptions).isFile()) {
|
|
30
|
-
return JSON.parse(fs_1.readFileSync(openapiOptions, 'utf-8'));
|
|
29
|
+
if ((0, fs_1.existsSync)(openapiOptions) && (0, fs_1.lstatSync)(openapiOptions).isFile()) {
|
|
30
|
+
return JSON.parse((0, fs_1.readFileSync)(openapiOptions, 'utf-8'));
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
return JSON.parse(openapiOptions);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
catch (e) {
|
|
37
|
-
process.stderr.write(colorette_1.red(`Encountered error:\n\n${openapiOptions}\n\nis neither a file with a valid JSON object neither a stringified JSON object.`));
|
|
38
|
-
utils_1.exitWithError(e);
|
|
37
|
+
process.stderr.write((0, colorette_1.red)(`Encountered error:\n\n${openapiOptions}\n\nis neither a file with a valid JSON object neither a stringified JSON object.`));
|
|
38
|
+
(0, utils_1.exitWithError)(e);
|
|
39
39
|
}
|
|
40
40
|
break;
|
|
41
41
|
default: {
|
|
@@ -52,18 +52,18 @@ exports.getObjectOrJSON = getObjectOrJSON;
|
|
|
52
52
|
function getPageHTML(api, pathToApi, { title, disableGoogleFont, templateFileName, templateOptions, redocOptions = {}, redocCurrentVersion, }, configPath) {
|
|
53
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
54
|
process.stderr.write('Prerendering docs\n');
|
|
55
|
-
const apiUrl = redocOptions.specUrl || (openapi_core_1.isAbsoluteUrl(pathToApi) ? pathToApi : undefined);
|
|
56
|
-
const store = yield redoc_1.createStore(api, apiUrl, redocOptions);
|
|
55
|
+
const apiUrl = redocOptions.specUrl || ((0, openapi_core_1.isAbsoluteUrl)(pathToApi) ? pathToApi : undefined);
|
|
56
|
+
const store = yield (0, redoc_1.createStore)(api, apiUrl, redocOptions);
|
|
57
57
|
const sheet = new styled_components_1.ServerStyleSheet();
|
|
58
|
-
const html = server_1.renderToString(sheet.collectStyles(react_1.createElement(redoc_1.Redoc, { store })));
|
|
58
|
+
const html = (0, server_1.renderToString)(sheet.collectStyles((0, react_1.createElement)(redoc_1.Redoc, { store })));
|
|
59
59
|
const state = yield store.toJS();
|
|
60
60
|
const css = sheet.getStyleTags();
|
|
61
61
|
templateFileName = templateFileName
|
|
62
62
|
? templateFileName
|
|
63
63
|
: (redocOptions === null || redocOptions === void 0 ? void 0 : redocOptions.htmlTemplate)
|
|
64
|
-
? path_1.resolve(configPath ? path_1.dirname(configPath) : '', redocOptions.htmlTemplate)
|
|
65
|
-
: path_1.join(__dirname, './template.hbs');
|
|
66
|
-
const template = handlebars_1.compile(fs_1.readFileSync(templateFileName).toString());
|
|
64
|
+
? (0, path_1.resolve)(configPath ? (0, path_1.dirname)(configPath) : '', redocOptions.htmlTemplate)
|
|
65
|
+
: (0, path_1.join)(__dirname, './template.hbs');
|
|
66
|
+
const template = (0, handlebars_1.compile)((0, fs_1.readFileSync)(templateFileName).toString());
|
|
67
67
|
return template({
|
|
68
68
|
redocHTML: `
|
|
69
69
|
<div id="redoc">${html || ''}</div>
|
package/lib/commands/bundle.d.ts
CHANGED
package/lib/commands/bundle.js
CHANGED
|
@@ -31,62 +31,62 @@ function handleBundle(argv, config, version) {
|
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
32
|
const removeUnusedComponents = argv['remove-unused-components'] ||
|
|
33
33
|
((_c = (_b = (_a = config.rawConfig) === null || _a === void 0 ? void 0 : _a.styleguide) === null || _b === void 0 ? void 0 : _b.decorators) === null || _c === void 0 ? void 0 : _c.hasOwnProperty('remove-unused-components'));
|
|
34
|
-
const apis = yield utils_1.getFallbackApisOrExit(argv.apis, config);
|
|
34
|
+
const apis = yield (0, utils_1.getFallbackApisOrExit)(argv.apis, config);
|
|
35
35
|
const totals = { errors: 0, warnings: 0, ignored: 0 };
|
|
36
36
|
const maxProblems = argv['max-problems'];
|
|
37
37
|
for (const { path, alias } of apis) {
|
|
38
38
|
try {
|
|
39
39
|
const startedAt = perf_hooks_1.performance.now();
|
|
40
|
-
const resolvedConfig = openapi_core_1.getMergedConfig(config, alias);
|
|
40
|
+
const resolvedConfig = (0, openapi_core_1.getMergedConfig)(config, alias);
|
|
41
41
|
const { styleguide } = resolvedConfig;
|
|
42
42
|
styleguide.skipRules(argv['skip-rule']);
|
|
43
43
|
styleguide.skipPreprocessors(argv['skip-preprocessor']);
|
|
44
44
|
styleguide.skipDecorators(argv['skip-decorator']);
|
|
45
45
|
if (argv.lint) {
|
|
46
|
-
utils_1.checkIfRulesetExist(styleguide.rules);
|
|
46
|
+
(0, utils_1.checkIfRulesetExist)(styleguide.rules);
|
|
47
47
|
if (config.styleguide.recommendedFallback) {
|
|
48
|
-
process.stderr.write(`No configurations were provided -- using built in ${colorette_1.blue('recommended')} configuration by default.\n\n`);
|
|
48
|
+
process.stderr.write(`No configurations were provided -- using built in ${(0, colorette_1.blue)('recommended')} configuration by default.\n\n`);
|
|
49
49
|
}
|
|
50
|
-
const results = yield openapi_core_1.lint({
|
|
50
|
+
const results = yield (0, openapi_core_1.lint)({
|
|
51
51
|
ref: path,
|
|
52
52
|
config: resolvedConfig,
|
|
53
53
|
});
|
|
54
|
-
const fileLintTotals = openapi_core_1.getTotals(results);
|
|
54
|
+
const fileLintTotals = (0, openapi_core_1.getTotals)(results);
|
|
55
55
|
totals.errors += fileLintTotals.errors;
|
|
56
56
|
totals.warnings += fileLintTotals.warnings;
|
|
57
57
|
totals.ignored += fileLintTotals.ignored;
|
|
58
|
-
openapi_core_1.formatProblems(results, {
|
|
58
|
+
(0, openapi_core_1.formatProblems)(results, {
|
|
59
59
|
format: argv.format || 'codeframe',
|
|
60
60
|
totals: fileLintTotals,
|
|
61
61
|
version,
|
|
62
62
|
maxProblems,
|
|
63
63
|
});
|
|
64
|
-
utils_1.printLintTotals(fileLintTotals, 2);
|
|
64
|
+
(0, utils_1.printLintTotals)(fileLintTotals, 2);
|
|
65
65
|
}
|
|
66
|
-
process.stderr.write(colorette_1.gray(`bundling ${path}...\n`));
|
|
67
|
-
const _f = yield openapi_core_1.bundle({
|
|
66
|
+
process.stderr.write((0, colorette_1.gray)(`bundling ${path}...\n`));
|
|
67
|
+
const _f = yield (0, openapi_core_1.bundle)({
|
|
68
68
|
config: resolvedConfig,
|
|
69
69
|
ref: path,
|
|
70
70
|
dereference: argv.dereferenced,
|
|
71
71
|
removeUnusedComponents,
|
|
72
72
|
keepUrlRefs: argv['keep-url-references'],
|
|
73
73
|
}), { bundle: result, problems } = _f, meta = __rest(_f, ["bundle", "problems"]);
|
|
74
|
-
const fileTotals = openapi_core_1.getTotals(problems);
|
|
75
|
-
const { outputFile, ext } = utils_1.getOutputFileName(path, apis.length, argv.output, argv.ext);
|
|
74
|
+
const fileTotals = (0, openapi_core_1.getTotals)(problems);
|
|
75
|
+
const { outputFile, ext } = (0, utils_1.getOutputFileName)(path, apis.length, argv.output, argv.ext);
|
|
76
76
|
if (fileTotals.errors === 0 || argv.force) {
|
|
77
77
|
if (!argv.output) {
|
|
78
|
-
const output = utils_1.dumpBundle(utils_1.sortTopLevelKeysForOas(result.parsed), argv.ext || 'yaml', argv.dereferenced);
|
|
78
|
+
const output = (0, utils_1.dumpBundle)((0, utils_1.sortTopLevelKeysForOas)(result.parsed), argv.ext || 'yaml', argv.dereferenced);
|
|
79
79
|
process.stdout.write(output);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
const output = utils_1.dumpBundle(utils_1.sortTopLevelKeysForOas(result.parsed), ext, argv.dereferenced);
|
|
83
|
-
utils_1.saveBundle(outputFile, output);
|
|
82
|
+
const output = (0, utils_1.dumpBundle)((0, utils_1.sortTopLevelKeysForOas)(result.parsed), ext, argv.dereferenced);
|
|
83
|
+
(0, utils_1.saveBundle)(outputFile, output);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
totals.errors += fileTotals.errors;
|
|
87
87
|
totals.warnings += fileTotals.warnings;
|
|
88
88
|
totals.ignored += fileTotals.ignored;
|
|
89
|
-
openapi_core_1.formatProblems(problems, {
|
|
89
|
+
(0, openapi_core_1.formatProblems)(problems, {
|
|
90
90
|
format: argv.format,
|
|
91
91
|
maxProblems,
|
|
92
92
|
totals: fileTotals,
|
|
@@ -94,34 +94,34 @@ function handleBundle(argv, config, version) {
|
|
|
94
94
|
});
|
|
95
95
|
if (argv.metafile) {
|
|
96
96
|
if (apis.length > 1) {
|
|
97
|
-
process.stderr.write(colorette_1.yellow(`[WARNING] "--metafile" cannot be used with multiple apis. Skipping...`));
|
|
97
|
+
process.stderr.write((0, colorette_1.yellow)(`[WARNING] "--metafile" cannot be used with multiple apis. Skipping...`));
|
|
98
98
|
}
|
|
99
99
|
{
|
|
100
|
-
fs_1.writeFileSync(argv.metafile, JSON.stringify(meta), 'utf-8');
|
|
100
|
+
(0, fs_1.writeFileSync)(argv.metafile, JSON.stringify(meta), 'utf-8');
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
const elapsed = utils_1.getExecutionTime(startedAt);
|
|
103
|
+
const elapsed = (0, utils_1.getExecutionTime)(startedAt);
|
|
104
104
|
if (fileTotals.errors > 0) {
|
|
105
105
|
if (argv.force) {
|
|
106
|
-
process.stderr.write(`❓ Created a bundle for ${colorette_1.blue(path)} at ${colorette_1.blue(outputFile)} with errors ${colorette_1.green(elapsed)}.\n${colorette_1.yellow('Errors ignored because of --force')}.\n`);
|
|
106
|
+
process.stderr.write(`❓ Created a bundle for ${(0, colorette_1.blue)(path)} at ${(0, colorette_1.blue)(outputFile)} with errors ${(0, colorette_1.green)(elapsed)}.\n${(0, colorette_1.yellow)('Errors ignored because of --force')}.\n`);
|
|
107
107
|
}
|
|
108
108
|
else {
|
|
109
|
-
process.stderr.write(`❌ Errors encountered while bundling ${colorette_1.blue(path)}: bundle not created (use --force to ignore errors).\n`);
|
|
109
|
+
process.stderr.write(`❌ Errors encountered while bundling ${(0, colorette_1.blue)(path)}: bundle not created (use --force to ignore errors).\n`);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
process.stderr.write(`📦 Created a bundle for ${colorette_1.blue(path)} at ${colorette_1.blue(outputFile)} ${colorette_1.green(elapsed)}.\n`);
|
|
113
|
+
process.stderr.write(`📦 Created a bundle for ${(0, colorette_1.blue)(path)} at ${(0, colorette_1.blue)(outputFile)} ${(0, colorette_1.green)(elapsed)}.\n`);
|
|
114
114
|
}
|
|
115
115
|
const removedCount = (_e = (_d = meta.visitorsData) === null || _d === void 0 ? void 0 : _d['remove-unused-components']) === null || _e === void 0 ? void 0 : _e.removedCount;
|
|
116
116
|
if (removedCount) {
|
|
117
|
-
process.stderr.write(colorette_1.gray(`🧹 Removed ${removedCount} unused components.\n`));
|
|
117
|
+
process.stderr.write((0, colorette_1.gray)(`🧹 Removed ${removedCount} unused components.\n`));
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
catch (e) {
|
|
121
|
-
utils_1.handleError(e, path);
|
|
121
|
+
(0, utils_1.handleError)(e, path);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
utils_1.printUnusedWarnings(config.styleguide);
|
|
124
|
+
(0, utils_1.printUnusedWarnings)(config.styleguide);
|
|
125
125
|
if (!(totals.errors === 0 || argv.force)) {
|
|
126
126
|
throw new Error('Bundle failed.');
|
|
127
127
|
}
|
package/lib/commands/join.d.ts
CHANGED