@redocly/cli 1.18.1 → 1.19.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
  3. package/lib/__mocks__/@redocly/openapi-core.js +1 -0
  4. package/lib/__mocks__/fs.d.ts +0 -1
  5. package/lib/__mocks__/perf_hooks.d.ts +0 -1
  6. package/lib/__mocks__/redoc.d.ts +0 -1
  7. package/lib/__tests__/commands/build-docs.test.js +21 -23
  8. package/lib/__tests__/commands/bundle.test.js +21 -30
  9. package/lib/__tests__/commands/join.test.js +101 -70
  10. package/lib/__tests__/commands/lint.test.js +54 -54
  11. package/lib/__tests__/commands/push-region.test.js +24 -25
  12. package/lib/__tests__/commands/push.test.js +269 -170
  13. package/lib/__tests__/fetch-with-timeout.test.js +3 -12
  14. package/lib/__tests__/fixtures/config.d.ts +0 -1
  15. package/lib/__tests__/utils.test.js +32 -37
  16. package/lib/__tests__/wrapper.test.js +31 -20
  17. package/lib/cms/api/__tests__/api.client.test.js +29 -38
  18. package/lib/cms/api/api-client.d.ts +0 -2
  19. package/lib/cms/api/api-client.js +106 -127
  20. package/lib/cms/api/api-keys.js +1 -2
  21. package/lib/cms/api/domains.js +1 -2
  22. package/lib/cms/commands/__tests__/push-status.test.js +251 -162
  23. package/lib/cms/commands/__tests__/push.test.js +120 -102
  24. package/lib/cms/commands/__tests__/utils.test.js +12 -21
  25. package/lib/cms/commands/push-status.d.ts +3 -2
  26. package/lib/cms/commands/push-status.js +94 -106
  27. package/lib/cms/commands/push.d.ts +3 -2
  28. package/lib/cms/commands/push.js +66 -74
  29. package/lib/cms/commands/utils.js +20 -34
  30. package/lib/commands/build-docs/index.d.ts +2 -2
  31. package/lib/commands/build-docs/index.js +8 -17
  32. package/lib/commands/build-docs/utils.js +26 -38
  33. package/lib/commands/bundle.d.ts +2 -2
  34. package/lib/commands/bundle.js +70 -94
  35. package/lib/commands/join.d.ts +2 -2
  36. package/lib/commands/join.js +375 -388
  37. package/lib/commands/lint.d.ts +2 -2
  38. package/lib/commands/lint.js +64 -75
  39. package/lib/commands/login.d.ts +3 -2
  40. package/lib/commands/login.js +9 -21
  41. package/lib/commands/preview-docs/index.d.ts +2 -2
  42. package/lib/commands/preview-docs/index.js +92 -106
  43. package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
  44. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
  45. package/lib/commands/preview-docs/preview-server/server.js +6 -6
  46. package/lib/commands/preview-project/index.d.ts +2 -1
  47. package/lib/commands/preview-project/index.js +5 -14
  48. package/lib/commands/push.d.ts +8 -11
  49. package/lib/commands/push.js +177 -195
  50. package/lib/commands/split/__tests__/index.test.js +31 -25
  51. package/lib/commands/split/index.d.ts +2 -1
  52. package/lib/commands/split/index.js +20 -33
  53. package/lib/commands/stats.d.ts +2 -2
  54. package/lib/commands/stats.js +34 -45
  55. package/lib/index.js +32 -46
  56. package/lib/types.d.ts +2 -2
  57. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
  58. package/lib/utils/fetch-with-timeout.js +7 -12
  59. package/lib/utils/getCommandNameFromArgs.js +2 -4
  60. package/lib/utils/js-utils.js +6 -7
  61. package/lib/utils/miscellaneous.d.ts +4 -1
  62. package/lib/utils/miscellaneous.js +130 -152
  63. package/lib/utils/update-version-notifier.js +4 -13
  64. package/lib/wrapper.d.ts +9 -2
  65. package/lib/wrapper.js +27 -16
  66. package/package.json +3 -3
  67. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  68. package/src/__tests__/commands/build-docs.test.ts +5 -4
  69. package/src/__tests__/commands/join.test.ts +51 -51
  70. package/src/__tests__/commands/push-region.test.ts +10 -8
  71. package/src/__tests__/commands/push.test.ts +127 -102
  72. package/src/__tests__/utils.test.ts +1 -0
  73. package/src/__tests__/wrapper.test.ts +24 -2
  74. package/src/cms/commands/__tests__/push-status.test.ts +70 -56
  75. package/src/cms/commands/__tests__/push.test.ts +30 -24
  76. package/src/cms/commands/push-status.ts +8 -7
  77. package/src/cms/commands/push.ts +12 -9
  78. package/src/commands/build-docs/index.ts +10 -5
  79. package/src/commands/bundle.ts +14 -6
  80. package/src/commands/join.ts +6 -2
  81. package/src/commands/lint.ts +9 -3
  82. package/src/commands/login.ts +4 -2
  83. package/src/commands/preview-docs/index.ts +6 -1
  84. package/src/commands/preview-project/index.ts +5 -4
  85. package/src/commands/push.ts +13 -15
  86. package/src/commands/split/__tests__/index.test.ts +17 -6
  87. package/src/commands/split/index.ts +4 -2
  88. package/src/commands/stats.ts +4 -2
  89. package/src/utils/miscellaneous.ts +11 -1
  90. package/src/wrapper.ts +37 -11
  91. package/tsconfig.tsbuildinfo +1 -1
@@ -474,6 +474,7 @@ describe('checkIfRulesetExist', () => {
474
474
  oas3_0: {},
475
475
  oas3_1: {},
476
476
  async2: {},
477
+ async3: {},
477
478
  arazzo: {},
478
479
  };
479
480
  expect(() => checkIfRulesetExist(rules)).toThrowError(
@@ -4,6 +4,7 @@ import { commandWrapper } from '../wrapper';
4
4
  import { handleLint } from '../commands/lint';
5
5
  import { Arguments } from 'yargs';
6
6
  import { handlePush, PushOptions } from '../commands/push';
7
+ import { detectSpec } from '@redocly/openapi-core';
7
8
 
8
9
  jest.mock('node-fetch');
9
10
  jest.mock('../utils/miscellaneous', () => ({
@@ -11,7 +12,9 @@ jest.mock('../utils/miscellaneous', () => ({
11
12
  loadConfigAndHandleErrors: jest.fn(),
12
13
  }));
13
14
  jest.mock('../commands/lint', () => ({
14
- handleLint: jest.fn(),
15
+ handleLint: jest.fn().mockImplementation(({ collectSpecData }) => {
16
+ collectSpecData({ openapi: '3.1.0' });
17
+ }),
15
18
  lintConfigCallback: jest.fn(),
16
19
  }));
17
20
 
@@ -20,13 +23,32 @@ describe('commandWrapper', () => {
20
23
  (loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
21
24
  return { telemetry: 'on', styleguide: { recommendedFallback: true } };
22
25
  });
26
+ (detectSpec as jest.Mock).mockImplementationOnce(() => {
27
+ return 'oas3_1';
28
+ });
29
+ process.env.REDOCLY_TELEMETRY = 'on';
30
+
31
+ const wrappedHandler = commandWrapper(handleLint);
32
+ await wrappedHandler({} as any);
33
+ expect(handleLint).toHaveBeenCalledTimes(1);
34
+ expect(sendTelemetry).toHaveBeenCalledTimes(1);
35
+ expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false, 'oas3_1', 'openapi', '3.1.0');
36
+ });
37
+
38
+ it('should not collect spec version if the file is not parsed to json', async () => {
39
+ (loadConfigAndHandleErrors as jest.Mock).mockImplementation(() => {
40
+ return { telemetry: 'on', styleguide: { recommendedFallback: true } };
41
+ });
42
+ (handleLint as jest.Mock).mockImplementation(({ collectSpecData }) => {
43
+ collectSpecData();
44
+ });
23
45
  process.env.REDOCLY_TELEMETRY = 'on';
24
46
 
25
47
  const wrappedHandler = commandWrapper(handleLint);
26
48
  await wrappedHandler({} as any);
27
49
  expect(handleLint).toHaveBeenCalledTimes(1);
28
50
  expect(sendTelemetry).toHaveBeenCalledTimes(1);
29
- expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false);
51
+ expect(sendTelemetry).toHaveBeenCalledWith({}, 0, false, undefined, undefined, undefined);
30
52
  });
31
53
 
32
54
  it('should NOT send telemetry if there is "telemetry: off" in the config', async () => {
@@ -85,15 +85,16 @@ describe('handlePushStatus()', () => {
85
85
 
86
86
  it('should throw error if organization not provided', async () => {
87
87
  await expect(
88
- handlePushStatus(
89
- {
88
+ handlePushStatus({
89
+ argv: {
90
90
  domain: 'test-domain',
91
91
  organization: '',
92
92
  project: 'test-project',
93
93
  pushId: 'test-push-id',
94
94
  },
95
- mockConfig
96
- )
95
+ config: mockConfig,
96
+ version: 'cli-version',
97
+ })
97
98
  ).rejects.toThrowErrorMatchingInlineSnapshot(
98
99
  `"No organization provided, please use --organization option or specify the 'organization' field in the config file."`
99
100
  );
@@ -108,15 +109,16 @@ describe('handlePushStatus()', () => {
108
109
  process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
109
110
  remotes.getPush.mockResolvedValueOnce(pushResponseStub);
110
111
 
111
- await handlePushStatus(
112
- {
112
+ await handlePushStatus({
113
+ argv: {
113
114
  domain: 'test-domain',
114
115
  organization: 'test-org',
115
116
  project: 'test-project',
116
117
  pushId: 'test-push-id',
117
118
  },
118
- mockConfig
119
- );
119
+ config: mockConfig,
120
+ version: 'cli-version',
121
+ });
120
122
  expect(process.stdout.write).toHaveBeenCalledTimes(1);
121
123
  expect(process.stdout.write).toHaveBeenCalledWith(
122
124
  '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
@@ -127,15 +129,16 @@ describe('handlePushStatus()', () => {
127
129
  process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
128
130
  remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
129
131
 
130
- await handlePushStatus(
131
- {
132
+ await handlePushStatus({
133
+ argv: {
132
134
  domain: 'test-domain',
133
135
  organization: 'test-org',
134
136
  project: 'test-project',
135
137
  pushId: 'test-push-id',
136
138
  },
137
- mockConfig
138
- );
139
+ config: mockConfig,
140
+ version: 'cli-version',
141
+ });
139
142
  expect(process.stdout.write).toHaveBeenCalledTimes(2);
140
143
  expect(process.stdout.write).toHaveBeenCalledWith(
141
144
  '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
@@ -157,15 +160,16 @@ describe('handlePushStatus()', () => {
157
160
  });
158
161
 
159
162
  await expect(
160
- handlePushStatus(
161
- {
163
+ handlePushStatus({
164
+ argv: {
162
165
  domain: 'test-domain',
163
166
  organization: 'test-org',
164
167
  project: 'test-project',
165
168
  pushId: 'test-push-id',
166
169
  },
167
- mockConfig
168
- )
170
+ config: mockConfig,
171
+ version: 'cli-version',
172
+ })
169
173
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
170
174
  "❌ Preview deploy fail.
171
175
  Preview URL: https://preview-test-url"
@@ -197,15 +201,16 @@ describe('handlePushStatus()', () => {
197
201
  },
198
202
  });
199
203
 
200
- await handlePushStatus(
201
- {
204
+ await handlePushStatus({
205
+ argv: {
202
206
  domain: 'test-domain',
203
207
  organization: 'test-org',
204
208
  project: 'test-project',
205
209
  pushId: 'test-push-id',
206
210
  },
207
- mockConfig
208
- );
211
+ config: mockConfig,
212
+ version: 'cli-version',
213
+ });
209
214
  expect(process.stdout.write).toHaveBeenCalledTimes(4);
210
215
  expect(process.stdout.write).toHaveBeenCalledWith(
211
216
  '🚀 Preview deploy success.\nPreview URL: https://preview-test-url\n'
@@ -232,16 +237,17 @@ describe('handlePushStatus()', () => {
232
237
  },
233
238
  });
234
239
 
235
- await handlePushStatus(
236
- {
240
+ await handlePushStatus({
241
+ argv: {
237
242
  domain: 'test-domain',
238
243
  organization: 'test-org',
239
244
  project: 'test-project',
240
245
  pushId: 'test-push-id',
241
246
  wait: true,
242
247
  },
243
- mockConfig
244
- );
248
+ config: mockConfig,
249
+ version: 'cli-version',
250
+ });
245
251
 
246
252
  expect(process.stderr.write).toHaveBeenCalledWith(
247
253
  'Files not added to your project. Reason: no changes.\n'
@@ -253,15 +259,16 @@ describe('handlePushStatus()', () => {
253
259
  process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
254
260
  remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: false });
255
261
 
256
- const result = await handlePushStatus(
257
- {
262
+ const result = await handlePushStatus({
263
+ argv: {
258
264
  domain: 'test-domain',
259
265
  organization: 'test-org',
260
266
  project: 'test-project',
261
267
  pushId: 'test-push-id',
262
268
  },
263
- mockConfig
264
- );
269
+ config: mockConfig,
270
+ version: 'cli-version',
271
+ });
265
272
 
266
273
  expect(result).toEqual({
267
274
  preview: {
@@ -280,15 +287,16 @@ describe('handlePushStatus()', () => {
280
287
  process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
281
288
  remotes.getPush.mockResolvedValue({ ...pushResponseStub, isMainBranch: true });
282
289
 
283
- const result = await handlePushStatus(
284
- {
290
+ const result = await handlePushStatus({
291
+ argv: {
285
292
  domain: 'test-domain',
286
293
  organization: 'test-org',
287
294
  project: 'test-project',
288
295
  pushId: 'test-push-id',
289
296
  },
290
- mockConfig
291
- );
297
+ config: mockConfig,
298
+ version: 'cli-version',
299
+ });
292
300
 
293
301
  expect(result).toEqual({
294
302
  preview: {
@@ -344,8 +352,8 @@ describe('handlePushStatus()', () => {
344
352
  },
345
353
  });
346
354
 
347
- const result = await handlePushStatus(
348
- {
355
+ const result = await handlePushStatus({
356
+ argv: {
349
357
  domain: 'test-domain',
350
358
  organization: 'test-org',
351
359
  project: 'test-project',
@@ -353,8 +361,9 @@ describe('handlePushStatus()', () => {
353
361
  'retry-interval': 0.5, // 500 ms
354
362
  wait: true,
355
363
  },
356
- mockConfig
357
- );
364
+ config: mockConfig,
365
+ version: 'cli-version',
366
+ });
358
367
 
359
368
  expect(result).toEqual({
360
369
  preview: {
@@ -417,8 +426,8 @@ describe('handlePushStatus()', () => {
417
426
  },
418
427
  });
419
428
 
420
- const result = await handlePushStatus(
421
- {
429
+ const result = await handlePushStatus({
430
+ argv: {
422
431
  domain: 'test-domain',
423
432
  organization: 'test-org',
424
433
  project: 'test-project',
@@ -426,8 +435,9 @@ describe('handlePushStatus()', () => {
426
435
  'retry-interval': 0.5, // 500 ms
427
436
  wait: true,
428
437
  },
429
- mockConfig
430
- );
438
+ config: mockConfig,
439
+ version: 'cli-version',
440
+ });
431
441
 
432
442
  expect(result).toEqual({
433
443
  preview: {
@@ -458,16 +468,17 @@ describe('handlePushStatus()', () => {
458
468
  });
459
469
 
460
470
  await expect(
461
- handlePushStatus(
462
- {
471
+ handlePushStatus({
472
+ argv: {
463
473
  domain: 'test-domain',
464
474
  organization: 'test-org',
465
475
  project: 'test-project',
466
476
  pushId: 'test-push-id',
467
477
  'continue-on-deploy-failures': false,
468
478
  },
469
- mockConfig
470
- )
479
+ config: mockConfig,
480
+ version: 'cli-version',
481
+ })
471
482
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
472
483
  "❌ Preview deploy fail.
473
484
  Preview URL: https://preview-test-url"
@@ -488,16 +499,17 @@ describe('handlePushStatus()', () => {
488
499
  });
489
500
 
490
501
  await expect(
491
- handlePushStatus(
492
- {
502
+ handlePushStatus({
503
+ argv: {
493
504
  domain: 'test-domain',
494
505
  organization: 'test-org',
495
506
  project: 'test-project',
496
507
  pushId: 'test-push-id',
497
508
  'continue-on-deploy-failures': true,
498
509
  },
499
- mockConfig
500
- )
510
+ config: mockConfig,
511
+ version: 'cli-version',
512
+ })
501
513
  ).resolves.toStrictEqual({
502
514
  preview: {
503
515
  deploy: { status: 'failed', url: 'https://preview-test-url' },
@@ -545,8 +557,8 @@ describe('handlePushStatus()', () => {
545
557
 
546
558
  const onRetrySpy = jest.fn();
547
559
 
548
- const result = await handlePushStatus(
549
- {
560
+ const result = await handlePushStatus({
561
+ argv: {
550
562
  domain: 'test-domain',
551
563
  organization: 'test-org',
552
564
  project: 'test-project',
@@ -555,8 +567,9 @@ describe('handlePushStatus()', () => {
555
567
  'retry-interval': 0.5, // 500 ms
556
568
  onRetry: onRetrySpy,
557
569
  },
558
- mockConfig
559
- );
570
+ config: mockConfig,
571
+ version: 'cli-version',
572
+ });
560
573
 
561
574
  expect(onRetrySpy).toBeCalledTimes(2);
562
575
 
@@ -617,8 +630,8 @@ describe('handlePushStatus()', () => {
617
630
  });
618
631
 
619
632
  await expect(
620
- handlePushStatus(
621
- {
633
+ handlePushStatus({
634
+ argv: {
622
635
  domain: 'test-domain',
623
636
  organization: 'test-org',
624
637
  project: 'test-project',
@@ -627,8 +640,9 @@ describe('handlePushStatus()', () => {
627
640
  'max-execution-time': 1, // seconds
628
641
  wait: true,
629
642
  },
630
- mockConfig
631
- )
643
+ config: mockConfig,
644
+ version: 'cli-version',
645
+ })
632
646
  ).rejects.toThrowErrorMatchingInlineSnapshot(`
633
647
  "✗ Failed to get push status. Reason: Timeout exceeded
634
648
  "
@@ -63,8 +63,8 @@ describe('handlePush()', () => {
63
63
  pathRelativeSpy.mockImplementationOnce((_, p) => p);
64
64
  pathDirnameSpy.mockImplementation((_: string) => '.');
65
65
 
66
- await handlePush(
67
- {
66
+ await handlePush({
67
+ argv: {
68
68
  domain: 'test-domain',
69
69
  'mount-path': 'test-mount-path',
70
70
  organization: 'test-org',
@@ -81,8 +81,9 @@ describe('handlePush()', () => {
81
81
  files: ['test-file'],
82
82
  'max-execution-time': 10,
83
83
  },
84
- mockConfig
85
- );
84
+ config: mockConfig,
85
+ version: 'cli-version',
86
+ });
86
87
 
87
88
  expect(remotes.getDefaultBranch).toHaveBeenCalledWith('test-org', 'test-project');
88
89
  expect(remotes.upsert).toHaveBeenCalledWith('test-org', 'test-project', {
@@ -132,8 +133,8 @@ describe('handlePush()', () => {
132
133
  pathRelativeSpy.mockImplementationOnce((_, p) => p);
133
134
  pathDirnameSpy.mockImplementation((_: string) => '.');
134
135
 
135
- const result = await handlePush(
136
- {
136
+ const result = await handlePush({
137
+ argv: {
137
138
  domain: 'test-domain',
138
139
  'mount-path': 'test-mount-path',
139
140
  organization: 'test-org',
@@ -150,8 +151,9 @@ describe('handlePush()', () => {
150
151
  files: ['test-file'],
151
152
  'max-execution-time': 10,
152
153
  },
153
- mockConfig
154
- );
154
+ config: mockConfig,
155
+ version: 'cli-version',
156
+ });
155
157
 
156
158
  expect(result).toEqual({ pushId: 'test-id' });
157
159
  });
@@ -188,8 +190,8 @@ describe('handlePush()', () => {
188
190
  throw new Error('Not a directory');
189
191
  });
190
192
 
191
- await handlePush(
192
- {
193
+ await handlePush({
194
+ argv: {
193
195
  domain: 'test-domain',
194
196
  'mount-path': 'test-mount-path',
195
197
  organization: 'test-org',
@@ -201,8 +203,9 @@ describe('handlePush()', () => {
201
203
  files: ['test-folder'],
202
204
  'max-execution-time': 10,
203
205
  },
204
- mockConfig
205
- );
206
+ config: mockConfig,
207
+ version: 'cli-version',
208
+ });
206
209
 
207
210
  expect(remotes.push).toHaveBeenCalledWith(
208
211
  expect.anything(),
@@ -230,8 +233,8 @@ describe('handlePush()', () => {
230
233
  const mockConfig = { apis: {} } as any;
231
234
  process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
232
235
 
233
- await handlePush(
234
- {
236
+ await handlePush({
237
+ argv: {
235
238
  domain: 'test-domain',
236
239
  'mount-path': 'test-mount-path',
237
240
  organization: 'test-org',
@@ -243,8 +246,9 @@ describe('handlePush()', () => {
243
246
  files: [],
244
247
  'max-execution-time': 10,
245
248
  },
246
- mockConfig
247
- );
249
+ config: mockConfig,
250
+ version: 'cli-version',
251
+ });
248
252
 
249
253
  expect(remotes.getDefaultBranch).not.toHaveBeenCalled();
250
254
  expect(remotes.upsert).not.toHaveBeenCalled();
@@ -265,8 +269,8 @@ describe('handlePush()', () => {
265
269
  pathRelativeSpy.mockImplementationOnce((_, p) => p);
266
270
  pathDirnameSpy.mockImplementation((_: string) => '.');
267
271
 
268
- await handlePush(
269
- {
272
+ await handlePush({
273
+ argv: {
270
274
  domain: 'test-domain',
271
275
  'mount-path': 'test-mount-path',
272
276
  project: 'test-project',
@@ -277,8 +281,9 @@ describe('handlePush()', () => {
277
281
  'default-branch': 'main',
278
282
  'max-execution-time': 10,
279
283
  },
280
- mockConfig
281
- );
284
+ config: mockConfig,
285
+ version: 'cli-version',
286
+ });
282
287
 
283
288
  expect(remotes.getDefaultBranch).toHaveBeenCalledWith(
284
289
  'test-org-from-config',
@@ -312,8 +317,8 @@ describe('handlePush()', () => {
312
317
  pathRelativeSpy.mockImplementationOnce((_, p) => p);
313
318
  pathDirnameSpy.mockImplementation((_: string) => '.');
314
319
 
315
- await handlePush(
316
- {
320
+ await handlePush({
321
+ argv: {
317
322
  'mount-path': 'test-mount-path',
318
323
  project: 'test-project',
319
324
  branch: 'test-branch',
@@ -323,8 +328,9 @@ describe('handlePush()', () => {
323
328
  files: ['test-file'],
324
329
  'max-execution-time': 10,
325
330
  },
326
- mockConfig
327
- );
331
+ config: mockConfig,
332
+ version: 'cli-version',
333
+ });
328
334
 
329
335
  expect(ReuniteApiClient).toBeCalledWith('test-domain-from-env', 'test-api-key');
330
336
  });
@@ -1,18 +1,19 @@
1
1
  import * as colors from 'colorette';
2
- import type { Config, OutputFormat } from '@redocly/openapi-core';
3
-
4
2
  import { exitWithError, printExecutionTime } from '../../utils/miscellaneous';
5
3
  import { Spinner } from '../../utils/spinner';
6
4
  import { DeploymentError } from '../utils';
7
5
  import { ReuniteApiClient, getApiKeys, getDomain } from '../api';
8
6
  import { capitalize } from '../../utils/js-utils';
7
+ import { retryUntilConditionMet } from './utils';
8
+
9
+ import type { OutputFormat } from '@redocly/openapi-core';
10
+ import type { CommandArgs } from '../../wrapper';
9
11
  import type {
10
12
  DeploymentStatus,
11
13
  DeploymentStatusResponse,
12
14
  PushResponse,
13
15
  ScorecardItem,
14
16
  } from '../api/types';
15
- import { retryUntilConditionMet } from './utils';
16
17
 
17
18
  const RETRY_INTERVAL_MS = 5000; // 5 sec
18
19
 
@@ -37,10 +38,10 @@ export interface PushStatusSummary {
37
38
  commit: PushResponse['commit'];
38
39
  }
39
40
 
40
- export async function handlePushStatus(
41
- argv: PushStatusOptions,
42
- config: Config
43
- ): Promise<PushStatusSummary | undefined> {
41
+ export async function handlePushStatus({
42
+ argv,
43
+ config,
44
+ }: CommandArgs<PushStatusOptions>): Promise<PushStatusSummary | undefined> {
44
45
  const startedAt = performance.now();
45
46
  const spinner = new Spinner();
46
47
 
@@ -11,7 +11,8 @@ import {
11
11
  import { handlePushStatus } from './push-status';
12
12
  import { ReuniteApiClient, getDomain, getApiKeys } from '../api';
13
13
 
14
- import type { OutputFormat, Config } from '@redocly/openapi-core';
14
+ import type { OutputFormat } from '@redocly/openapi-core';
15
+ import type { CommandArgs } from '../../wrapper';
15
16
 
16
17
  export type PushOptions = {
17
18
  apis?: string[];
@@ -42,10 +43,11 @@ export type PushOptions = {
42
43
 
43
44
  type FileToUpload = { name: string; path: string };
44
45
 
45
- export async function handlePush(
46
- argv: PushOptions,
47
- config: Config
48
- ): Promise<{ pushId: string } | void> {
46
+ export async function handlePush({
47
+ argv,
48
+ config,
49
+ version,
50
+ }: CommandArgs<PushOptions>): Promise<{ pushId: string } | void> {
49
51
  const startedAt = performance.now(); // for printing execution time
50
52
  const startTime = Date.now(); // for push-status command
51
53
 
@@ -131,8 +133,8 @@ export async function handlePush(
131
133
  if (waitForDeployment) {
132
134
  process.stdout.write('\n');
133
135
 
134
- await handlePushStatus(
135
- {
136
+ await handlePushStatus({
137
+ argv: {
136
138
  organization: orgId,
137
139
  project: projectId,
138
140
  pushId: id,
@@ -142,8 +144,9 @@ export async function handlePush(
142
144
  'start-time': startTime,
143
145
  'continue-on-deploy-failures': argv['continue-on-deploy-failures'],
144
146
  },
145
- config
146
- );
147
+ config,
148
+ version,
149
+ });
147
150
  }
148
151
  verbose &&
149
152
  printExecutionTime(
@@ -2,17 +2,21 @@ import { loadAndBundleSpec } from 'redoc';
2
2
  import { dirname, resolve } from 'path';
3
3
  import { writeFileSync, mkdirSync } from 'fs';
4
4
  import { performance } from 'perf_hooks';
5
-
5
+ import { getMergedConfig, isAbsoluteUrl } from '@redocly/openapi-core';
6
6
  import { getObjectOrJSON, getPageHTML } from './utils';
7
- import type { BuildDocsArgv } from './types';
8
- import { Config, getMergedConfig, isAbsoluteUrl } from '@redocly/openapi-core';
9
7
  import { exitWithError, getExecutionTime, getFallbackApisOrExit } from '../../utils/miscellaneous';
10
8
 
11
- export const handlerBuildCommand = async (argv: BuildDocsArgv, configFromFile: Config) => {
9
+ import type { BuildDocsArgv } from './types';
10
+ import type { CommandArgs } from '../../wrapper';
11
+
12
+ export const handlerBuildCommand = async ({
13
+ argv,
14
+ config: configFromFile,
15
+ collectSpecData,
16
+ }: CommandArgs<BuildDocsArgv>) => {
12
17
  const startedAt = performance.now();
13
18
 
14
19
  const config = getMergedConfig(configFromFile, argv.api);
15
-
16
20
  const apis = await getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
17
21
  const { path: pathToApi } = apis[0];
18
22
 
@@ -31,6 +35,7 @@ export const handlerBuildCommand = async (argv: BuildDocsArgv, configFromFile: C
31
35
  const elapsed = getExecutionTime(startedAt);
32
36
 
33
37
  const api = await loadAndBundleSpec(isAbsoluteUrl(pathToApi) ? pathToApi : resolve(pathToApi));
38
+ collectSpecData?.(api);
34
39
  const pageHTML = await getPageHTML(
35
40
  api,
36
41
  pathToApi,
@@ -1,4 +1,7 @@
1
- import { formatProblems, getTotals, getMergedConfig, bundle, Config } from '@redocly/openapi-core';
1
+ import { performance } from 'perf_hooks';
2
+ import { blue, gray, green, yellow } from 'colorette';
3
+ import { writeFileSync } from 'fs';
4
+ import { formatProblems, getTotals, getMergedConfig, bundle } from '@redocly/openapi-core';
2
5
  import {
3
6
  dumpBundle,
4
7
  getExecutionTime,
@@ -8,12 +11,11 @@ import {
8
11
  printUnusedWarnings,
9
12
  saveBundle,
10
13
  sortTopLevelKeysForOas,
14
+ checkForDeprecatedOptions,
11
15
  } from '../utils/miscellaneous';
16
+
12
17
  import type { OutputExtensions, Skips, Totals } from '../types';
13
- import { performance } from 'perf_hooks';
14
- import { blue, gray, green, yellow } from 'colorette';
15
- import { writeFileSync } from 'fs';
16
- import { checkForDeprecatedOptions } from '../utils/miscellaneous';
18
+ import type { CommandArgs } from '../wrapper';
17
19
 
18
20
  export type BundleOptions = {
19
21
  apis?: string[];
@@ -28,7 +30,12 @@ export type BundleOptions = {
28
30
  'keep-url-references'?: boolean;
29
31
  } & Skips;
30
32
 
31
- export async function handleBundle(argv: BundleOptions, config: Config, version: string) {
33
+ export async function handleBundle({
34
+ argv,
35
+ config,
36
+ version,
37
+ collectSpecData,
38
+ }: CommandArgs<BundleOptions>) {
32
39
  const removeUnusedComponents =
33
40
  argv['remove-unused-components'] ||
34
41
  config.rawConfig?.styleguide?.decorators?.hasOwnProperty('remove-unused-components');
@@ -59,6 +66,7 @@ export async function handleBundle(argv: BundleOptions, config: Config, version:
59
66
  dereference: argv.dereferenced,
60
67
  removeUnusedComponents,
61
68
  keepUrlRefs: argv['keep-url-references'],
69
+ collectSpecData,
62
70
  });
63
71
 
64
72
  const fileTotals = getTotals(problems);