@redocly/cli 1.7.0 → 1.8.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 (118) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/__tests__/commands/build-docs.test.js +3 -3
  3. package/lib/__tests__/commands/bundle.test.js +5 -5
  4. package/lib/__tests__/commands/join.test.js +11 -11
  5. package/lib/__tests__/commands/lint.test.js +14 -14
  6. package/lib/__tests__/commands/push-region.test.js +1 -1
  7. package/lib/__tests__/commands/push.test.js +11 -11
  8. package/lib/__tests__/fetch-with-timeout.test.js +4 -13
  9. package/lib/__tests__/spinner.test.js +43 -0
  10. package/lib/__tests__/utils.test.js +36 -36
  11. package/lib/__tests__/wrapper.test.js +8 -8
  12. package/lib/cms/api/__tests__/api-keys.test.d.ts +1 -0
  13. package/lib/cms/api/__tests__/api-keys.test.js +26 -0
  14. package/lib/cms/api/__tests__/api.client.test.d.ts +1 -0
  15. package/lib/cms/api/__tests__/api.client.test.js +217 -0
  16. package/lib/cms/api/__tests__/domains.test.d.ts +1 -0
  17. package/lib/cms/api/__tests__/domains.test.js +13 -0
  18. package/lib/cms/api/api-client.d.ts +50 -0
  19. package/lib/cms/api/api-client.js +148 -0
  20. package/lib/cms/api/api-keys.d.ts +1 -0
  21. package/lib/cms/api/api-keys.js +24 -0
  22. package/lib/cms/api/domains.d.ts +1 -0
  23. package/lib/cms/api/domains.js +12 -0
  24. package/lib/cms/api/index.d.ts +3 -0
  25. package/lib/cms/api/index.js +19 -0
  26. package/lib/cms/api/types.d.ts +91 -0
  27. package/lib/cms/api/types.js +2 -0
  28. package/lib/cms/commands/__tests__/push-status.test.d.ts +1 -0
  29. package/lib/cms/commands/__tests__/push-status.test.js +164 -0
  30. package/lib/cms/commands/__tests__/push.test.d.ts +1 -0
  31. package/lib/cms/commands/__tests__/push.test.js +226 -0
  32. package/lib/cms/commands/push-status.d.ts +12 -0
  33. package/lib/cms/commands/push-status.js +150 -0
  34. package/lib/cms/commands/push.d.ts +23 -0
  35. package/lib/cms/commands/push.js +142 -0
  36. package/lib/cms/utils.d.ts +2 -0
  37. package/lib/cms/utils.js +6 -0
  38. package/lib/commands/build-docs/index.js +4 -4
  39. package/lib/commands/build-docs/utils.js +2 -2
  40. package/lib/commands/bundle.js +13 -13
  41. package/lib/commands/join.js +25 -25
  42. package/lib/commands/lint.js +10 -10
  43. package/lib/commands/login.js +2 -2
  44. package/lib/commands/preview-docs/index.js +4 -4
  45. package/lib/commands/preview-docs/preview-server/preview-server.js +2 -2
  46. package/lib/commands/preview-project/types.d.ts +1 -1
  47. package/lib/commands/push.d.ts +5 -0
  48. package/lib/commands/push.js +25 -17
  49. package/lib/commands/split/__tests__/index.test.js +2 -2
  50. package/lib/commands/split/index.js +17 -17
  51. package/lib/commands/stats.js +4 -4
  52. package/lib/index.d.ts +1 -1
  53. package/lib/index.js +130 -17
  54. package/lib/types.d.ts +8 -1
  55. package/lib/{__mocks__/utils.js → utils/__mocks__/miscellaneous.js} +1 -1
  56. package/lib/utils/assert-node-version.d.ts +1 -0
  57. package/lib/{fetch-with-timeout.js → utils/fetch-with-timeout.js} +2 -7
  58. package/lib/{utils.d.ts → utils/miscellaneous.d.ts} +1 -1
  59. package/lib/{utils.js → utils/miscellaneous.js} +2 -2
  60. package/lib/utils/spinner.d.ts +10 -0
  61. package/lib/utils/spinner.js +42 -0
  62. package/lib/{update-version-notifier.js → utils/update-version-notifier.js} +4 -4
  63. package/lib/wrapper.js +5 -5
  64. package/package.json +5 -3
  65. package/src/__tests__/commands/build-docs.test.ts +2 -2
  66. package/src/__tests__/commands/bundle.test.ts +2 -2
  67. package/src/__tests__/commands/join.test.ts +2 -2
  68. package/src/__tests__/commands/lint.test.ts +3 -3
  69. package/src/__tests__/commands/push-region.test.ts +1 -1
  70. package/src/__tests__/commands/push.test.ts +2 -2
  71. package/src/__tests__/fetch-with-timeout.test.ts +4 -16
  72. package/src/__tests__/spinner.test.ts +51 -0
  73. package/src/__tests__/utils.test.ts +2 -5
  74. package/src/__tests__/wrapper.test.ts +2 -2
  75. package/src/cms/api/__tests__/api-keys.test.ts +37 -0
  76. package/src/cms/api/__tests__/api.client.test.ts +275 -0
  77. package/src/cms/api/__tests__/domains.test.ts +15 -0
  78. package/src/cms/api/api-client.ts +199 -0
  79. package/src/cms/api/api-keys.ts +26 -0
  80. package/src/cms/api/domains.ts +11 -0
  81. package/src/cms/api/index.ts +3 -0
  82. package/src/cms/api/types.ts +101 -0
  83. package/src/cms/commands/__tests__/push-status.test.ts +212 -0
  84. package/src/cms/commands/__tests__/push.test.ts +293 -0
  85. package/src/cms/commands/push-status.ts +203 -0
  86. package/src/cms/commands/push.ts +215 -0
  87. package/src/cms/utils.ts +1 -0
  88. package/src/commands/build-docs/index.ts +1 -1
  89. package/src/commands/build-docs/utils.ts +1 -1
  90. package/src/commands/bundle.ts +2 -2
  91. package/src/commands/join.ts +2 -2
  92. package/src/commands/lint.ts +1 -1
  93. package/src/commands/login.ts +1 -1
  94. package/src/commands/preview-docs/index.ts +5 -1
  95. package/src/commands/preview-docs/preview-server/preview-server.ts +1 -1
  96. package/src/commands/preview-project/types.ts +1 -1
  97. package/src/commands/push.ts +15 -1
  98. package/src/commands/split/__tests__/index.test.ts +3 -4
  99. package/src/commands/split/index.ts +2 -2
  100. package/src/commands/stats.ts +2 -2
  101. package/src/index.ts +138 -20
  102. package/src/types.ts +8 -0
  103. package/src/{__mocks__/utils.ts → utils/__mocks__/miscellaneous.ts} +1 -1
  104. package/src/{fetch-with-timeout.ts → utils/fetch-with-timeout.ts} +1 -6
  105. package/src/{utils.ts → utils/miscellaneous.ts} +2 -2
  106. package/src/utils/spinner.ts +50 -0
  107. package/src/{update-version-notifier.ts → utils/update-version-notifier.ts} +2 -2
  108. package/src/wrapper.ts +7 -2
  109. package/tsconfig.tsbuildinfo +1 -1
  110. /package/lib/{assert-node-version.d.ts → __tests__/spinner.test.d.ts} +0 -0
  111. /package/lib/{__mocks__/utils.d.ts → utils/__mocks__/miscellaneous.d.ts} +0 -0
  112. /package/lib/{assert-node-version.js → utils/assert-node-version.js} +0 -0
  113. /package/lib/{fetch-with-timeout.d.ts → utils/fetch-with-timeout.d.ts} +0 -0
  114. /package/lib/{js-utils.d.ts → utils/js-utils.d.ts} +0 -0
  115. /package/lib/{js-utils.js → utils/js-utils.js} +0 -0
  116. /package/lib/{update-version-notifier.d.ts → utils/update-version-notifier.d.ts} +0 -0
  117. /package/src/{assert-node-version.ts → utils/assert-node-version.ts} +0 -0
  118. /package/src/{js-utils.ts → utils/js-utils.ts} +0 -0
package/src/index.ts CHANGED
@@ -1,26 +1,27 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import './assert-node-version';
3
+ import './utils/assert-node-version';
4
4
  import * as yargs from 'yargs';
5
- import { outputExtensions, regionChoices } from './types';
5
+ import { outputExtensions, PushArguments, regionChoices } from './types';
6
6
  import { RedoclyClient } from '@redocly/openapi-core';
7
7
  import { previewDocs } from './commands/preview-docs';
8
8
  import { handleStats } from './commands/stats';
9
9
  import { handleSplit } from './commands/split';
10
10
  import { handleJoin } from './commands/join';
11
- import { handlePush, transformPush } from './commands/push';
11
+ import { handlePushStatus, PushStatusOptions } from './cms/commands/push-status';
12
12
  import { handleLint } from './commands/lint';
13
13
  import { handleBundle } from './commands/bundle';
14
14
  import { handleLogin } from './commands/login';
15
15
  import { handlerBuildCommand } from './commands/build-docs';
16
- import { cacheLatestVersion, notifyUpdateCliVersion } from './update-version-notifier';
16
+ import { cacheLatestVersion, notifyUpdateCliVersion } from './utils/update-version-notifier';
17
17
  import { commandWrapper } from './wrapper';
18
- import { version } from './update-version-notifier';
18
+ import { version } from './utils/update-version-notifier';
19
19
  import type { Arguments } from 'yargs';
20
20
  import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
21
21
  import type { BuildDocsArgv } from './commands/build-docs/types';
22
22
  import { previewProject } from './commands/preview-project';
23
23
  import { PRODUCT_PLANS } from './commands/preview-project/constants';
24
+ import { commonPushHandler } from './commands/push';
24
25
 
25
26
  if (!('replaceAll' in String.prototype)) {
26
27
  require('core-js/actual/string/replace-all');
@@ -146,23 +147,75 @@ yargs
146
147
  commandWrapper(handleJoin)(argv);
147
148
  }
148
149
  )
149
-
150
150
  .command(
151
- 'push [api] [maybeDestination] [maybeBranchName]',
152
- 'Push an API description to the Redocly API registry.',
151
+ 'push-status [pushId]',
152
+ false,
153
153
  (yargs) =>
154
154
  yargs
155
- .usage('push [api]')
156
- .positional('api', { type: 'string' })
157
- .positional('maybeDestination', { type: 'string' })
158
- .hide('maybeDestination')
159
- .hide('maybeBranchName')
155
+ .positional('pushId', {
156
+ description: 'Push id.',
157
+ type: 'string',
158
+ required: true,
159
+ })
160
+ .implies('max-execution-time', 'wait')
160
161
  .option({
161
162
  organization: {
162
163
  description: 'Name of the organization to push to.',
163
164
  type: 'string',
164
165
  alias: 'o',
165
166
  },
167
+ project: {
168
+ description: 'Name of the project to push to.',
169
+ type: 'string',
170
+ alias: 'p',
171
+ },
172
+ domain: { description: 'Specify a domain.', alias: 'd', type: 'string' },
173
+ wait: {
174
+ description: 'Wait for build to finish.',
175
+ type: 'boolean',
176
+ default: false,
177
+ },
178
+ 'max-execution-time': {
179
+ description: 'Maximum execution time in seconds.',
180
+ type: 'number',
181
+ },
182
+ }),
183
+ (argv) => {
184
+ process.env.REDOCLY_CLI_COMMAND = 'push-status';
185
+ commandWrapper(handlePushStatus)(argv as Arguments<PushStatusOptions>);
186
+ }
187
+ )
188
+ .command(
189
+ 'push [apis...]',
190
+ 'Push an API description to the Redocly API registry.',
191
+ (yargs) =>
192
+ yargs
193
+ .positional('apis', {
194
+ type: 'string',
195
+ array: true,
196
+ required: true,
197
+ default: [],
198
+ })
199
+ .hide('project')
200
+ .hide('domain')
201
+ .hide('mount-path')
202
+ .hide('author')
203
+ .hide('message')
204
+ .hide('default-branch')
205
+ .hide('verbose')
206
+ .hide('commit-sha')
207
+ .hide('commit-url')
208
+ .hide('namespace')
209
+ .hide('repository')
210
+ .hide('wait-for-deployment')
211
+ .hide('created-at')
212
+ .hide('max-execution-time')
213
+ .deprecateOption('batch-id', 'use --job-id')
214
+ .implies('job-id', 'batch-size')
215
+ .implies('batch-id', 'batch-size')
216
+ .implies('batch-size', 'job-id')
217
+ .implies('max-execution-time', 'wait-for-deployment')
218
+ .option({
166
219
  destination: {
167
220
  description: 'API name and version in the format `name@version`.',
168
221
  type: 'string',
@@ -217,15 +270,80 @@ yargs
217
270
  choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
218
271
  default: 'warn' as RuleSeverity,
219
272
  },
220
- })
221
- .deprecateOption('batch-id', 'use --job-id')
222
- .deprecateOption('maybeDestination')
223
- .implies('job-id', 'batch-size')
224
- .implies('batch-id', 'batch-size')
225
- .implies('batch-size', 'job-id'),
273
+ organization: {
274
+ description: 'Name of the organization to push to.',
275
+ type: 'string',
276
+ alias: 'o',
277
+ },
278
+ project: {
279
+ description: 'Name of the project to push to.',
280
+ type: 'string',
281
+ alias: 'p',
282
+ },
283
+ 'mount-path': {
284
+ description: 'The path files should be pushed to.',
285
+ type: 'string',
286
+ alias: 'mp',
287
+ },
288
+ author: {
289
+ description: 'Author of the commit.',
290
+ type: 'string',
291
+ alias: 'a',
292
+ },
293
+ message: {
294
+ description: 'Commit message.',
295
+ type: 'string',
296
+ alias: 'm',
297
+ },
298
+ 'commit-sha': {
299
+ description: 'Commit SHA.',
300
+ type: 'string',
301
+ alias: 'sha',
302
+ },
303
+ 'commit-url': {
304
+ description: 'Commit URL.',
305
+ type: 'string',
306
+ alias: 'url',
307
+ },
308
+ namespace: {
309
+ description: 'Repository namespace.',
310
+ type: 'string',
311
+ },
312
+ repository: {
313
+ description: 'Repository name.',
314
+ type: 'string',
315
+ },
316
+ 'created-at': {
317
+ description: 'Commit creation date.',
318
+ type: 'string',
319
+ },
320
+ domain: { description: 'Specify a domain.', alias: 'd', type: 'string' },
321
+ config: {
322
+ description: 'Path to the config file.',
323
+ requiresArg: true,
324
+ type: 'string',
325
+ },
326
+ 'default-branch': {
327
+ type: 'string',
328
+ default: 'main',
329
+ },
330
+ 'max-execution-time': {
331
+ description: 'Maximum execution time in seconds.',
332
+ type: 'number',
333
+ },
334
+ 'wait-for-deployment': {
335
+ description: 'Wait for build to finish.',
336
+ type: 'boolean',
337
+ default: false,
338
+ },
339
+ verbose: {
340
+ type: 'boolean',
341
+ default: false,
342
+ },
343
+ }),
226
344
  (argv) => {
227
345
  process.env.REDOCLY_CLI_COMMAND = 'push';
228
- commandWrapper(transformPush(handlePush))(argv);
346
+ commandWrapper(commonPushHandler(argv))(argv as PushArguments);
229
347
  }
230
348
  )
231
349
  .command(
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { BundleOutputFormat, Region, Config } from '@redocly/openapi-core';
2
+ import type { ArgumentsCamelCase } from 'yargs';
2
3
  import type { LintOptions } from './commands/lint';
3
4
  import type { BundleOptions } from './commands/bundle';
4
5
  import type { JoinOptions } from './commands/join';
@@ -8,6 +9,9 @@ import type { StatsOptions } from './commands/stats';
8
9
  import type { SplitOptions } from './commands/split';
9
10
  import type { PreviewDocsOptions } from './commands/preview-docs';
10
11
  import type { BuildDocsArgv } from './commands/build-docs/types';
12
+ import type { PushOptions as PushBhOptions } from './cms/commands/push';
13
+ import type { PushStatusOptions } from './cms/commands/push-status';
14
+ import type { PushOptions as CMSPushOptions } from './cms/commands/push';
11
15
  import type { PreviewProjectOptions } from './commands/preview-project/types';
12
16
 
13
17
  export type Totals = {
@@ -27,11 +31,13 @@ export type CommandOptions =
27
31
  | SplitOptions
28
32
  | JoinOptions
29
33
  | PushOptions
34
+ | PushBhOptions
30
35
  | LintOptions
31
36
  | BundleOptions
32
37
  | LoginOptions
33
38
  | PreviewDocsOptions
34
39
  | BuildDocsArgv
40
+ | PushStatusOptions
35
41
  | PreviewProjectOptions;
36
42
 
37
43
  export type Skips = {
@@ -41,3 +47,5 @@ export type Skips = {
41
47
  };
42
48
 
43
49
  export type ConfigApis = Pick<Config, 'apis' | 'configFile'>;
50
+
51
+ export type PushArguments = ArgumentsCamelCase<PushOptions & CMSPushOptions & { apis: string[] }>;
@@ -1,4 +1,4 @@
1
- import { ConfigFixture } from '../__tests__/fixtures/config';
1
+ import { ConfigFixture } from '../../__tests__/fixtures/config';
2
2
 
3
3
  export const getFallbackApisOrExit = jest.fn((entrypoints) =>
4
4
  entrypoints.map((path: string) => ({ path }))
@@ -1,20 +1,15 @@
1
1
  import nodeFetch from 'node-fetch';
2
+ import AbortController from 'abort-controller';
2
3
 
3
4
  const TIMEOUT = 3000;
4
5
 
5
6
  export default async (url: string, options = {}) => {
6
7
  try {
7
- if (!global.AbortController) {
8
- return nodeFetch(url, options);
9
- }
10
8
  const controller = new AbortController();
11
9
  const timeout = setTimeout(() => {
12
10
  controller.abort();
13
11
  }, TIMEOUT);
14
12
 
15
- // FIXME: fix this (possibly along with this issue: https://github.com/Redocly/redocly-cli/issues/1260)
16
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
17
- // @ts-ignore
18
13
  const res = await nodeFetch(url, { signal: controller.signal, ...options });
19
14
  clearTimeout(timeout);
20
15
  return res;
@@ -30,11 +30,11 @@ import {
30
30
  ConfigApis,
31
31
  CommandOptions,
32
32
  OutputExtensions,
33
- } from './types';
33
+ } from '../types';
34
34
  import { isEmptyObject } from '@redocly/openapi-core/lib/utils';
35
35
  import { Arguments } from 'yargs';
36
36
  import { version } from './update-version-notifier';
37
- import { DESTINATION_REGEX } from './commands/push';
37
+ import { DESTINATION_REGEX } from '../commands/push';
38
38
  import { ConfigValidationError } from '@redocly/openapi-core/lib/config';
39
39
 
40
40
  import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
@@ -0,0 +1,50 @@
1
+ import * as process from 'process';
2
+
3
+ const SPINNER_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
4
+
5
+ export class Spinner {
6
+ private readonly frames: string[];
7
+ private currentFrame: number;
8
+ private intervalId: NodeJS.Timeout | null;
9
+ private message: string;
10
+
11
+ constructor() {
12
+ this.frames = SPINNER_FRAMES;
13
+ this.currentFrame = 0;
14
+ this.intervalId = null;
15
+ this.message = '';
16
+ }
17
+
18
+ private showFrame() {
19
+ process.stdout.write('\r' + this.frames[this.currentFrame] + ' ' + this.message);
20
+ this.currentFrame = (this.currentFrame + 1) % this.frames.length;
21
+ }
22
+
23
+ start(message: string) {
24
+ if (this.message === message) {
25
+ return;
26
+ }
27
+
28
+ this.message = message;
29
+ // If we're not in a TTY, don't display the spinner.
30
+ if (!process.stdout.isTTY) {
31
+ process.stdout.write(`${message}...\n`);
32
+ return;
33
+ }
34
+
35
+ if (this.intervalId === null) {
36
+ this.intervalId = setInterval(() => {
37
+ this.showFrame();
38
+ }, 100);
39
+ }
40
+ }
41
+
42
+ stop() {
43
+ if (this.intervalId !== null) {
44
+ clearInterval(this.intervalId);
45
+ this.intervalId = null;
46
+ process.stdout.write('\r');
47
+ }
48
+ this.message = '';
49
+ }
50
+ }
@@ -4,9 +4,9 @@ import { existsSync, writeFileSync, readFileSync, statSync } from 'fs';
4
4
  import { compare } from 'semver';
5
5
  import fetch from './fetch-with-timeout';
6
6
  import { cyan, green, yellow } from 'colorette';
7
- import { cleanColors } from './utils';
7
+ import { cleanColors } from './miscellaneous';
8
8
 
9
- export const { version, name } = require('../package.json');
9
+ export const { version, name } = require('../../package.json');
10
10
 
11
11
  const VERSION_CACHE_FILE = 'redocly-cli-version';
12
12
  const SPACE_TO_BORDER = 4;
package/src/wrapper.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { Config, Region, doesYamlFileExist } from '@redocly/openapi-core';
2
2
  import type { Arguments } from 'yargs';
3
- import { version } from './update-version-notifier';
4
- import { ExitCode, exitWithError, loadConfigAndHandleErrors, sendTelemetry } from './utils';
3
+ import { version } from './utils/update-version-notifier';
4
+ import {
5
+ ExitCode,
6
+ exitWithError,
7
+ loadConfigAndHandleErrors,
8
+ sendTelemetry,
9
+ } from './utils/miscellaneous';
5
10
  import { lintConfigCallback } from './commands/lint';
6
11
  import type { CommandOptions } from './types';
7
12