@redocly/cli 1.34.3 → 2.0.0-next.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 (321) hide show
  1. package/README.md +34 -3
  2. package/bin/cli.js +1 -1
  3. package/lib/auth/device-flow.d.ts +1 -0
  4. package/lib/auth/device-flow.d.ts.map +1 -0
  5. package/lib/auth/device-flow.js +15 -17
  6. package/lib/auth/device-flow.js.map +1 -0
  7. package/lib/auth/oauth-client.d.ts +1 -0
  8. package/lib/auth/oauth-client.d.ts.map +1 -0
  9. package/lib/auth/oauth-client.js +21 -23
  10. package/lib/auth/oauth-client.js.map +1 -0
  11. package/lib/commands/auth.d.ts +3 -5
  12. package/lib/commands/auth.d.ts.map +1 -0
  13. package/lib/commands/auth.js +19 -44
  14. package/lib/commands/auth.js.map +1 -0
  15. package/lib/commands/build-docs/index.d.ts +4 -3
  16. package/lib/commands/build-docs/index.d.ts.map +1 -0
  17. package/lib/commands/build-docs/index.js +23 -24
  18. package/lib/commands/build-docs/index.js.map +1 -0
  19. package/lib/commands/build-docs/types.d.ts +2 -1
  20. package/lib/commands/build-docs/types.d.ts.map +1 -0
  21. package/lib/commands/build-docs/types.js +2 -2
  22. package/lib/commands/build-docs/types.js.map +1 -0
  23. package/lib/commands/build-docs/utils.d.ts +3 -2
  24. package/lib/commands/build-docs/utils.d.ts.map +1 -0
  25. package/lib/commands/build-docs/utils.js +35 -37
  26. package/lib/commands/build-docs/utils.js.map +1 -0
  27. package/lib/commands/bundle.d.ts +6 -3
  28. package/lib/commands/bundle.d.ts.map +1 -0
  29. package/lib/commands/bundle.js +34 -38
  30. package/lib/commands/bundle.js.map +1 -0
  31. package/lib/commands/eject.d.ts +3 -2
  32. package/lib/commands/eject.d.ts.map +1 -0
  33. package/lib/commands/eject.js +11 -13
  34. package/lib/commands/eject.js.map +1 -0
  35. package/lib/commands/join.d.ts +4 -3
  36. package/lib/commands/join.d.ts.map +1 -0
  37. package/lib/commands/join.js +79 -81
  38. package/lib/commands/join.js.map +1 -0
  39. package/lib/commands/lint.d.ts +8 -6
  40. package/lib/commands/lint.d.ts.map +1 -0
  41. package/lib/commands/lint.js +53 -62
  42. package/lib/commands/lint.js.map +1 -0
  43. package/lib/commands/preview-project/constants.d.ts +2 -1
  44. package/lib/commands/preview-project/constants.d.ts.map +1 -0
  45. package/lib/commands/preview-project/constants.js +4 -6
  46. package/lib/commands/preview-project/constants.js.map +1 -0
  47. package/lib/commands/preview-project/index.d.ts +3 -2
  48. package/lib/commands/preview-project/index.d.ts.map +1 -0
  49. package/lib/commands/preview-project/index.js +21 -23
  50. package/lib/commands/preview-project/index.js.map +1 -0
  51. package/lib/commands/preview-project/types.d.ts +3 -2
  52. package/lib/commands/preview-project/types.d.ts.map +1 -0
  53. package/lib/commands/preview-project/types.js +2 -2
  54. package/lib/commands/preview-project/types.js.map +1 -0
  55. package/lib/commands/split/index.d.ts +4 -3
  56. package/lib/commands/split/index.d.ts.map +1 -0
  57. package/lib/commands/split/index.js +53 -57
  58. package/lib/commands/split/index.js.map +1 -0
  59. package/lib/commands/split/types.d.ts +2 -2
  60. package/lib/commands/split/types.d.ts.map +1 -0
  61. package/lib/commands/split/types.js +11 -13
  62. package/lib/commands/split/types.js.map +1 -0
  63. package/lib/commands/stats.d.ts +3 -2
  64. package/lib/commands/stats.d.ts.map +1 -0
  65. package/lib/commands/stats.js +21 -24
  66. package/lib/commands/stats.js.map +1 -0
  67. package/lib/commands/translations.d.ts +3 -2
  68. package/lib/commands/translations.d.ts.map +1 -0
  69. package/lib/commands/translations.js +11 -13
  70. package/lib/commands/translations.js.map +1 -0
  71. package/lib/index.d.ts +2 -1
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +109 -239
  74. package/lib/index.js.map +1 -0
  75. package/lib/otel.d.ts +2 -1
  76. package/lib/otel.d.ts.map +1 -0
  77. package/lib/otel.js +22 -23
  78. package/lib/otel.js.map +1 -0
  79. package/lib/reunite/api/api-client.d.ts +4 -3
  80. package/lib/reunite/api/api-client.d.ts.map +1 -0
  81. package/lib/reunite/api/api-client.js +14 -20
  82. package/lib/reunite/api/api-client.js.map +1 -0
  83. package/lib/reunite/api/api-keys.d.ts +2 -1
  84. package/lib/reunite/api/api-keys.d.ts.map +1 -0
  85. package/lib/reunite/api/api-keys.js +4 -20
  86. package/lib/reunite/api/api-keys.js.map +1 -0
  87. package/lib/reunite/api/domains.d.ts +5 -2
  88. package/lib/reunite/api/domains.d.ts.map +1 -0
  89. package/lib/reunite/api/domains.js +6 -15
  90. package/lib/reunite/api/domains.js.map +1 -0
  91. package/lib/reunite/api/index.d.ts +4 -3
  92. package/lib/reunite/api/index.d.ts.map +1 -0
  93. package/lib/reunite/api/index.js +4 -19
  94. package/lib/reunite/api/index.js.map +1 -0
  95. package/lib/reunite/api/types.d.ts +1 -0
  96. package/lib/reunite/api/types.d.ts.map +1 -0
  97. package/lib/reunite/api/types.js +2 -2
  98. package/lib/reunite/api/types.js.map +1 -0
  99. package/lib/reunite/commands/push-status.d.ts +6 -5
  100. package/lib/reunite/commands/push-status.d.ts.map +1 -0
  101. package/lib/reunite/commands/push-status.js +31 -37
  102. package/lib/reunite/commands/push-status.js.map +1 -0
  103. package/lib/reunite/commands/push.d.ts +6 -6
  104. package/lib/reunite/commands/push.d.ts.map +1 -0
  105. package/lib/reunite/commands/push.js +31 -40
  106. package/lib/reunite/commands/push.js.map +1 -0
  107. package/lib/reunite/commands/utils.d.ts +4 -3
  108. package/lib/reunite/commands/utils.d.ts.map +1 -0
  109. package/lib/reunite/commands/utils.js +9 -12
  110. package/lib/reunite/commands/utils.js.map +1 -0
  111. package/lib/reunite/utils.d.ts +1 -0
  112. package/lib/reunite/utils.d.ts.map +1 -0
  113. package/lib/reunite/utils.js +2 -5
  114. package/lib/reunite/utils.js.map +1 -0
  115. package/lib/types.d.ts +15 -27
  116. package/lib/types.d.ts.map +1 -0
  117. package/lib/types.js +2 -5
  118. package/lib/types.js.map +1 -0
  119. package/lib/utils/assert-node-version.d.ts +1 -0
  120. package/lib/utils/assert-node-version.d.ts.map +1 -0
  121. package/lib/utils/assert-node-version.js +8 -10
  122. package/lib/utils/assert-node-version.js.map +1 -0
  123. package/lib/utils/error.d.ts +4 -0
  124. package/lib/utils/error.d.ts.map +1 -0
  125. package/lib/utils/error.js +8 -0
  126. package/lib/utils/error.js.map +1 -0
  127. package/lib/utils/fetch-with-timeout.d.ts +1 -0
  128. package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
  129. package/lib/utils/fetch-with-timeout.js +6 -8
  130. package/lib/utils/fetch-with-timeout.js.map +1 -0
  131. package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
  132. package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
  133. package/lib/utils/get-command-name-from-args.js +4 -0
  134. package/lib/utils/get-command-name-from-args.js.map +1 -0
  135. package/lib/utils/js-utils.d.ts +1 -0
  136. package/lib/utils/js-utils.d.ts.map +1 -0
  137. package/lib/utils/js-utils.js +8 -12
  138. package/lib/utils/js-utils.js.map +1 -0
  139. package/lib/utils/miscellaneous.d.ts +9 -48
  140. package/lib/utils/miscellaneous.d.ts.map +1 -0
  141. package/lib/utils/miscellaneous.js +131 -269
  142. package/lib/utils/miscellaneous.js.map +1 -0
  143. package/lib/utils/package.d.ts +2 -0
  144. package/lib/utils/package.d.ts.map +1 -0
  145. package/lib/utils/package.js +4 -0
  146. package/lib/utils/package.js.map +1 -0
  147. package/lib/utils/platform.d.ts +1 -0
  148. package/lib/utils/platform.d.ts.map +1 -0
  149. package/lib/utils/platform.js +5 -9
  150. package/lib/utils/platform.js.map +1 -0
  151. package/lib/utils/proxy-agent.d.ts +3 -0
  152. package/lib/utils/proxy-agent.d.ts.map +1 -0
  153. package/lib/utils/proxy-agent.js +6 -0
  154. package/lib/utils/proxy-agent.js.map +1 -0
  155. package/lib/utils/spinner.d.ts +1 -0
  156. package/lib/utils/spinner.d.ts.map +1 -0
  157. package/lib/utils/spinner.js +8 -10
  158. package/lib/utils/spinner.js.map +1 -0
  159. package/lib/utils/telemetry.d.ts +40 -0
  160. package/lib/utils/telemetry.d.ts.map +1 -0
  161. package/lib/utils/telemetry.js +138 -0
  162. package/lib/utils/telemetry.js.map +1 -0
  163. package/lib/utils/update-version-notifier.d.ts +1 -1
  164. package/lib/utils/update-version-notifier.d.ts.map +1 -0
  165. package/lib/utils/update-version-notifier.js +35 -38
  166. package/lib/utils/update-version-notifier.js.map +1 -0
  167. package/lib/utils/validate-positive-number.d.ts +2 -0
  168. package/lib/utils/validate-positive-number.d.ts.map +1 -0
  169. package/lib/utils/validate-positive-number.js +13 -0
  170. package/lib/utils/validate-positive-number.js.map +1 -0
  171. package/lib/wrapper.d.ts +3 -3
  172. package/lib/wrapper.d.ts.map +1 -0
  173. package/lib/wrapper.js +39 -26
  174. package/lib/wrapper.js.map +1 -0
  175. package/package.json +15 -16
  176. package/CHANGELOG.md +0 -770
  177. package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
  178. package/lib/__mocks__/@redocly/openapi-core.js +0 -84
  179. package/lib/__mocks__/documents.d.ts +0 -150
  180. package/lib/__mocks__/documents.js +0 -123
  181. package/lib/__mocks__/fs.d.ts +0 -8
  182. package/lib/__mocks__/fs.js +0 -9
  183. package/lib/__mocks__/perf_hooks.d.ts +0 -3
  184. package/lib/__mocks__/perf_hooks.js +0 -6
  185. package/lib/__mocks__/redoc.d.ts +0 -6
  186. package/lib/__mocks__/redoc.js +0 -5
  187. package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
  188. package/lib/__tests__/commands/build-docs.test.js +0 -54
  189. package/lib/__tests__/commands/bundle.test.d.ts +0 -1
  190. package/lib/__tests__/commands/bundle.test.js +0 -235
  191. package/lib/__tests__/commands/join.test.d.ts +0 -1
  192. package/lib/__tests__/commands/join.test.js +0 -274
  193. package/lib/__tests__/commands/lint.test.d.ts +0 -1
  194. package/lib/__tests__/commands/lint.test.js +0 -149
  195. package/lib/__tests__/commands/push-region.test.d.ts +0 -1
  196. package/lib/__tests__/commands/push-region.test.js +0 -90
  197. package/lib/__tests__/commands/push.test.d.ts +0 -1
  198. package/lib/__tests__/commands/push.test.js +0 -496
  199. package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
  200. package/lib/__tests__/fetch-with-timeout.test.js +0 -64
  201. package/lib/__tests__/fixtures/config.d.ts +0 -21
  202. package/lib/__tests__/fixtures/config.js +0 -24
  203. package/lib/__tests__/spinner.test.d.ts +0 -1
  204. package/lib/__tests__/spinner.test.js +0 -43
  205. package/lib/__tests__/utils.test.d.ts +0 -1
  206. package/lib/__tests__/utils.test.js +0 -651
  207. package/lib/__tests__/wrapper.test.d.ts +0 -1
  208. package/lib/__tests__/wrapper.test.js +0 -76
  209. package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
  210. package/lib/auth/__tests__/device-flow.test.js +0 -62
  211. package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
  212. package/lib/auth/__tests__/oauth-client.test.js +0 -93
  213. package/lib/commands/preview-docs/index.d.ts +0 -12
  214. package/lib/commands/preview-docs/index.js +0 -127
  215. package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
  216. package/lib/commands/preview-docs/preview-server/hot.js +0 -59
  217. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  218. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
  219. package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
  220. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
  221. package/lib/commands/preview-docs/preview-server/server.js +0 -85
  222. package/lib/commands/push.d.ts +0 -44
  223. package/lib/commands/push.js +0 -301
  224. package/lib/commands/split/__tests__/index.test.d.ts +0 -1
  225. package/lib/commands/split/__tests__/index.test.js +0 -91
  226. package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
  227. package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
  228. package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
  229. package/lib/reunite/api/__tests__/api.client.test.js +0 -337
  230. package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
  231. package/lib/reunite/api/__tests__/domains.test.js +0 -32
  232. package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
  233. package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
  234. package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
  235. package/lib/reunite/commands/__tests__/push.test.js +0 -315
  236. package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
  237. package/lib/reunite/commands/__tests__/utils.test.js +0 -51
  238. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
  239. package/lib/utils/__mocks__/miscellaneous.js +0 -24
  240. package/lib/utils/getCommandNameFromArgs.js +0 -6
  241. package/src/__mocks__/@redocly/openapi-core.ts +0 -88
  242. package/src/__mocks__/documents.ts +0 -124
  243. package/src/__mocks__/fs.ts +0 -6
  244. package/src/__mocks__/perf_hooks.ts +0 -3
  245. package/src/__mocks__/redoc.ts +0 -2
  246. package/src/__tests__/commands/build-docs.test.ts +0 -59
  247. package/src/__tests__/commands/bundle.test.ts +0 -285
  248. package/src/__tests__/commands/join.test.ts +0 -334
  249. package/src/__tests__/commands/lint.test.ts +0 -190
  250. package/src/__tests__/commands/push-region.test.ts +0 -104
  251. package/src/__tests__/commands/push.test.ts +0 -553
  252. package/src/__tests__/fetch-with-timeout.test.ts +0 -81
  253. package/src/__tests__/fixtures/config.ts +0 -21
  254. package/src/__tests__/fixtures/openapi.json +0 -0
  255. package/src/__tests__/fixtures/openapi.yaml +0 -0
  256. package/src/__tests__/fixtures/redocly.yaml +0 -0
  257. package/src/__tests__/spinner.test.ts +0 -51
  258. package/src/__tests__/utils.test.ts +0 -781
  259. package/src/__tests__/wrapper.test.ts +0 -91
  260. package/src/auth/__tests__/device-flow.test.ts +0 -73
  261. package/src/auth/__tests__/oauth-client.test.ts +0 -117
  262. package/src/auth/device-flow.ts +0 -175
  263. package/src/auth/oauth-client.ts +0 -111
  264. package/src/commands/auth.ts +0 -66
  265. package/src/commands/build-docs/index.ts +0 -55
  266. package/src/commands/build-docs/template.hbs +0 -23
  267. package/src/commands/build-docs/types.ts +0 -25
  268. package/src/commands/build-docs/utils.ts +0 -110
  269. package/src/commands/bundle.ts +0 -154
  270. package/src/commands/eject.ts +0 -42
  271. package/src/commands/join.ts +0 -794
  272. package/src/commands/lint.ts +0 -169
  273. package/src/commands/preview-docs/index.ts +0 -183
  274. package/src/commands/preview-docs/preview-server/default.hbs +0 -24
  275. package/src/commands/preview-docs/preview-server/hot.js +0 -59
  276. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  277. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
  278. package/src/commands/preview-docs/preview-server/server.ts +0 -92
  279. package/src/commands/preview-project/constants.ts +0 -23
  280. package/src/commands/preview-project/index.ts +0 -71
  281. package/src/commands/preview-project/types.ts +0 -12
  282. package/src/commands/push.ts +0 -470
  283. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  284. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  285. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
  286. package/src/commands/split/__tests__/index.test.ts +0 -156
  287. package/src/commands/split/index.ts +0 -397
  288. package/src/commands/split/types.ts +0 -60
  289. package/src/commands/stats.ts +0 -140
  290. package/src/commands/translations.ts +0 -32
  291. package/src/custom.d.ts +0 -1
  292. package/src/index.ts +0 -970
  293. package/src/otel.ts +0 -59
  294. package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
  295. package/src/reunite/api/__tests__/api.client.test.ts +0 -452
  296. package/src/reunite/api/__tests__/domains.test.ts +0 -41
  297. package/src/reunite/api/api-client.ts +0 -381
  298. package/src/reunite/api/api-keys.ts +0 -26
  299. package/src/reunite/api/domains.ts +0 -23
  300. package/src/reunite/api/index.ts +0 -3
  301. package/src/reunite/api/types.ts +0 -108
  302. package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
  303. package/src/reunite/commands/__tests__/push.test.ts +0 -385
  304. package/src/reunite/commands/__tests__/utils.test.ts +0 -62
  305. package/src/reunite/commands/push-status.ts +0 -325
  306. package/src/reunite/commands/push.ts +0 -235
  307. package/src/reunite/commands/utils.ts +0 -66
  308. package/src/reunite/utils.ts +0 -1
  309. package/src/types.ts +0 -64
  310. package/src/utils/__mocks__/miscellaneous.ts +0 -24
  311. package/src/utils/assert-node-version.ts +0 -19
  312. package/src/utils/fetch-with-timeout.ts +0 -30
  313. package/src/utils/getCommandNameFromArgs.ts +0 -5
  314. package/src/utils/js-utils.ts +0 -24
  315. package/src/utils/miscellaneous.ts +0 -729
  316. package/src/utils/platform.ts +0 -31
  317. package/src/utils/spinner.ts +0 -50
  318. package/src/utils/update-version-notifier.ts +0 -115
  319. package/src/wrapper.ts +0 -77
  320. package/tsconfig.json +0 -9
  321. package/tsconfig.tsbuildinfo +0 -1
@@ -1,325 +0,0 @@
1
- import * as colors from 'colorette';
2
- import { exitWithError, printExecutionTime } from '../../utils/miscellaneous';
3
- import { Spinner } from '../../utils/spinner';
4
- import { DeploymentError } from '../utils';
5
- import { ReuniteApi, getApiKeys, getDomain } from '../api';
6
- import { capitalize } from '../../utils/js-utils';
7
- import { handleReuniteError, retryUntilConditionMet } from './utils';
8
-
9
- import type { OutputFormat } from '@redocly/openapi-core';
10
- import type { CommandArgs } from '../../wrapper';
11
- import type {
12
- DeploymentStatus,
13
- DeploymentStatusResponse,
14
- PushResponse,
15
- ScorecardItem,
16
- } from '../api/types';
17
-
18
- const RETRY_INTERVAL_MS = 5000; // 5 sec
19
-
20
- export type PushStatusOptions = {
21
- organization: string;
22
- project: string;
23
- pushId: string;
24
- domain?: string;
25
- config?: string;
26
- format?: Extract<OutputFormat, 'stylish'>;
27
- wait?: boolean;
28
- 'max-execution-time'?: number; // in seconds
29
- 'retry-interval'?: number; // in seconds
30
- 'start-time'?: number; // in milliseconds
31
- 'continue-on-deploy-failures'?: boolean;
32
- onRetry?: (lasSummary: PushStatusSummary) => void;
33
- };
34
-
35
- export interface PushStatusSummary {
36
- preview: DeploymentStatusResponse;
37
- production: DeploymentStatusResponse | null;
38
- commit: PushResponse['commit'];
39
- }
40
-
41
- export async function handlePushStatus({
42
- argv,
43
- config,
44
- version,
45
- }: CommandArgs<PushStatusOptions>): Promise<PushStatusSummary | void> {
46
- const startedAt = performance.now();
47
- const spinner = new Spinner();
48
-
49
- const { organization, project: projectId, pushId, wait } = argv;
50
-
51
- const orgId = organization || config.organization;
52
-
53
- if (!orgId) {
54
- exitWithError(
55
- `No organization provided, please use --organization option or specify the 'organization' field in the config file.`
56
- );
57
- return;
58
- }
59
-
60
- const domain = argv.domain || getDomain();
61
- const maxExecutionTime = argv['max-execution-time'] || 1200; // 20 min
62
- const retryIntervalMs = argv['retry-interval']
63
- ? argv['retry-interval'] * 1000
64
- : RETRY_INTERVAL_MS;
65
- const startTime = argv['start-time'] || Date.now();
66
- const retryTimeoutMs = maxExecutionTime * 1000;
67
- const continueOnDeployFailures = argv['continue-on-deploy-failures'] || false;
68
-
69
- try {
70
- const apiKey = getApiKeys(domain);
71
- const client = new ReuniteApi({ domain, apiKey, version, command: 'push-status' });
72
-
73
- let pushResponse: PushResponse;
74
-
75
- pushResponse = await retryUntilConditionMet({
76
- operation: () =>
77
- client.remotes.getPush({
78
- organizationId: orgId,
79
- projectId,
80
- pushId,
81
- }),
82
- condition: wait
83
- ? // Keep retrying if status is "pending" or "running" (returning false, so the operation will be retried)
84
- (result) => !['pending', 'running'].includes(result.status['preview'].deploy.status)
85
- : null,
86
- onConditionNotMet: (lastResult) => {
87
- displayDeploymentAndBuildStatus({
88
- status: lastResult.status['preview'].deploy.status,
89
- url: lastResult.status['preview'].deploy.url,
90
- spinner,
91
- buildType: 'preview',
92
- continueOnDeployFailures,
93
- wait,
94
- });
95
- },
96
- onRetry: (lastResult) => {
97
- if (argv.onRetry) {
98
- argv.onRetry({
99
- preview: lastResult.status.preview,
100
- production: lastResult.isMainBranch ? lastResult.status.production : null,
101
- commit: lastResult.commit,
102
- });
103
- }
104
- },
105
- startTime,
106
- retryTimeoutMs,
107
- retryIntervalMs,
108
- });
109
-
110
- printPushStatus({
111
- buildType: 'preview',
112
- spinner,
113
- wait,
114
- push: pushResponse,
115
- continueOnDeployFailures,
116
- });
117
- printScorecard(pushResponse.status.preview.scorecard);
118
-
119
- const shouldWaitForProdDeployment =
120
- pushResponse.isMainBranch &&
121
- (wait ? pushResponse.status.preview.deploy.status === 'success' : true);
122
-
123
- if (shouldWaitForProdDeployment) {
124
- pushResponse = await retryUntilConditionMet({
125
- operation: () =>
126
- client.remotes.getPush({
127
- organizationId: orgId,
128
- projectId,
129
- pushId,
130
- }),
131
- condition: wait
132
- ? // Keep retrying if status is "pending" or "running" (returning false, so the operation will be retried)
133
- (result) => !['pending', 'running'].includes(result.status['production'].deploy.status)
134
- : null,
135
- onConditionNotMet: (lastResult) => {
136
- displayDeploymentAndBuildStatus({
137
- status: lastResult.status['production'].deploy.status,
138
- url: lastResult.status['production'].deploy.url,
139
- spinner,
140
- buildType: 'production',
141
- continueOnDeployFailures,
142
- wait,
143
- });
144
- },
145
- onRetry: (lastResult) => {
146
- if (argv.onRetry) {
147
- argv.onRetry({
148
- preview: lastResult.status.preview,
149
- production: lastResult.isMainBranch ? lastResult.status.production : null,
150
- commit: lastResult.commit,
151
- });
152
- }
153
- },
154
- startTime,
155
- retryTimeoutMs,
156
- retryIntervalMs,
157
- });
158
- }
159
-
160
- if (pushResponse.isMainBranch) {
161
- printPushStatus({
162
- buildType: 'production',
163
- spinner,
164
- wait,
165
- push: pushResponse,
166
- continueOnDeployFailures,
167
- });
168
- printScorecard(pushResponse.status.production.scorecard);
169
- }
170
- printPushStatusInfo({ orgId, projectId, pushId, startedAt });
171
-
172
- client.reportSunsetWarnings();
173
-
174
- const summary: PushStatusSummary = {
175
- preview: pushResponse.status.preview,
176
- production: pushResponse.isMainBranch ? pushResponse.status.production : null,
177
- commit: pushResponse.commit,
178
- };
179
-
180
- return summary;
181
- } catch (err) {
182
- spinner.stop(); // Spinner can block process exit, so we need to stop it explicitly.
183
-
184
- handleReuniteError('✗ Failed to get push status.', err);
185
- } finally {
186
- spinner.stop(); // Spinner can block process exit, so we need to stop it explicitly.
187
- }
188
- }
189
-
190
- function printPushStatusInfo({
191
- orgId,
192
- projectId,
193
- pushId,
194
- startedAt,
195
- }: {
196
- orgId: string;
197
- projectId: string;
198
- pushId: string;
199
- startedAt: number;
200
- }) {
201
- process.stderr.write(
202
- `\nProcessed push-status for ${colors.yellow(orgId!)}, ${colors.yellow(
203
- projectId
204
- )} and pushID ${colors.yellow(pushId)}.\n`
205
- );
206
- printExecutionTime('push-status', startedAt, 'Finished');
207
- }
208
-
209
- function printPushStatus({
210
- buildType,
211
- spinner,
212
- push,
213
- continueOnDeployFailures,
214
- }: {
215
- buildType: 'preview' | 'production';
216
- spinner: Spinner;
217
- wait?: boolean;
218
- push?: PushResponse | null;
219
- continueOnDeployFailures: boolean;
220
- }) {
221
- if (!push) {
222
- return;
223
- }
224
- if (push.isOutdated || !push.hasChanges) {
225
- process.stderr.write(
226
- colors.yellow(
227
- `Files not added to your project. Reason: ${push.isOutdated ? 'outdated' : 'no changes'}.\n`
228
- )
229
- );
230
- } else {
231
- displayDeploymentAndBuildStatus({
232
- status: push.status[buildType].deploy.status,
233
- url: push.status[buildType].deploy.url,
234
- buildType,
235
- spinner,
236
- continueOnDeployFailures,
237
- });
238
- }
239
- }
240
-
241
- function printScorecard(scorecard?: ScorecardItem[]) {
242
- if (!scorecard || scorecard.length === 0) {
243
- return;
244
- }
245
- process.stdout.write(`\n${colors.magenta('Scorecard')}:`);
246
- for (const scorecardItem of scorecard) {
247
- process.stdout.write(`
248
- ${colors.magenta('Name')}: ${scorecardItem.name}
249
- ${colors.magenta('Status')}: ${scorecardItem.status}
250
- ${colors.magenta('URL')}: ${colors.cyan(scorecardItem.url)}
251
- ${colors.magenta('Description')}: ${scorecardItem.description}\n`);
252
- }
253
- process.stdout.write(`\n`);
254
- }
255
-
256
- function displayDeploymentAndBuildStatus({
257
- status,
258
- url,
259
- spinner,
260
- buildType,
261
- continueOnDeployFailures,
262
- wait,
263
- }: {
264
- status: DeploymentStatus;
265
- url: string | null;
266
- spinner: Spinner;
267
- buildType: 'preview' | 'production';
268
- continueOnDeployFailures: boolean;
269
- wait?: boolean;
270
- }) {
271
- const message = getMessage({ status, url, buildType, wait });
272
-
273
- if (status === 'failed' && !continueOnDeployFailures) {
274
- spinner.stop();
275
- throw new DeploymentError(message);
276
- }
277
-
278
- if (wait && (status === 'pending' || status === 'running')) {
279
- return spinner.start(message);
280
- }
281
-
282
- spinner.stop();
283
- return process.stdout.write(message);
284
- }
285
-
286
- function getMessage({
287
- status,
288
- url,
289
- buildType,
290
- wait,
291
- }: {
292
- status: DeploymentStatus;
293
- url: string | null;
294
- buildType: 'preview' | 'production';
295
- wait?: boolean;
296
- }): string {
297
- switch (status) {
298
- case 'skipped':
299
- return `${colors.yellow(`Skipped ${buildType}`)}\n`;
300
-
301
- case 'pending': {
302
- const message = `${colors.yellow(`Pending ${buildType}`)}`;
303
- return wait ? message : `Status: ${message}\n`;
304
- }
305
- case 'running': {
306
- const message = `${colors.yellow(`Running ${buildType}`)}`;
307
- return wait ? message : `Status: ${message}\n`;
308
- }
309
- case 'success':
310
- return `${colors.green(`🚀 ${capitalize(buildType)} deploy success.`)}\n${colors.magenta(
311
- `${capitalize(buildType)} URL`
312
- )}: ${colors.cyan(url || 'No URL yet.')}\n`;
313
-
314
- case 'failed':
315
- return `${colors.red(`❌ ${capitalize(buildType)} deploy fail.`)}\n${colors.magenta(
316
- `${capitalize(buildType)} URL`
317
- )}: ${colors.cyan(url || 'No URL yet.')}`;
318
-
319
- default: {
320
- const message = `${colors.yellow(`No status yet for ${buildType} deploy`)}`;
321
-
322
- return wait ? message : `Status: ${message}\n`;
323
- }
324
- }
325
- }
@@ -1,235 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { slash } from '@redocly/openapi-core';
4
- import { pluralize } from '@redocly/openapi-core/lib/utils';
5
- import { green, yellow } from 'colorette';
6
- import { exitWithError, printExecutionTime } from '../../utils/miscellaneous';
7
- import { handlePushStatus } from './push-status';
8
- import { ReuniteApi, getDomain, getApiKeys } from '../api';
9
- import { handleReuniteError } from './utils';
10
-
11
- import type { OutputFormat } from '@redocly/openapi-core';
12
- import type { CommandArgs } from '../../wrapper';
13
- import type { VerifyConfigOptions } from '../../types';
14
-
15
- export type PushOptions = {
16
- apis?: string[];
17
- organization?: string;
18
- project: string;
19
- 'mount-path': string;
20
-
21
- branch: string;
22
- author: string;
23
- message: string;
24
- 'commit-sha'?: string;
25
- 'commit-url'?: string;
26
- namespace?: string;
27
- repository?: string;
28
- 'created-at'?: string;
29
-
30
- files: string[];
31
-
32
- 'default-branch': string;
33
- domain?: string;
34
- 'wait-for-deployment'?: boolean;
35
- 'max-execution-time': number;
36
- 'continue-on-deploy-failures'?: boolean;
37
- verbose?: boolean;
38
- format?: Extract<OutputFormat, 'stylish'>;
39
- } & VerifyConfigOptions;
40
-
41
- type FileToUpload = { name: string; path: string };
42
-
43
- export async function handlePush({
44
- argv,
45
- config,
46
- version,
47
- }: CommandArgs<PushOptions>): Promise<{ pushId: string } | void> {
48
- const startedAt = performance.now(); // for printing execution time
49
- const startTime = Date.now(); // for push-status command
50
-
51
- const { organization, project: projectId, 'mount-path': mountPath, verbose } = argv;
52
-
53
- const orgId = organization || config.organization;
54
-
55
- if (!argv.message || !argv.author || !argv.branch) {
56
- exitWithError('Error: message, author and branch are required for push to the Reunite.');
57
- }
58
-
59
- if (!orgId) {
60
- return exitWithError(
61
- `No organization provided, please use --organization option or specify the 'organization' field in the config file.`
62
- );
63
- }
64
-
65
- const domain = argv.domain || getDomain();
66
-
67
- if (!domain) {
68
- return exitWithError(
69
- `No domain provided, please use --domain option or environment variable REDOCLY_AUTHORIZATION.`
70
- );
71
- }
72
-
73
- try {
74
- const {
75
- 'commit-sha': commitSha,
76
- 'commit-url': commitUrl,
77
- 'default-branch': defaultBranch,
78
- 'wait-for-deployment': waitForDeployment,
79
- 'max-execution-time': maxExecutionTime,
80
- } = argv;
81
- const author = parseCommitAuthor(argv.author);
82
- const apiKey = getApiKeys(domain);
83
- const filesToUpload = collectFilesToPush(argv.files || argv.apis);
84
- const commandName = 'push' as const;
85
-
86
- if (!filesToUpload.length) {
87
- return printExecutionTime(commandName, startedAt, `No files to upload`);
88
- }
89
-
90
- const client = new ReuniteApi({ domain, apiKey, version, command: commandName });
91
- const projectDefaultBranch = await client.remotes.getDefaultBranch(orgId, projectId);
92
- const remote = await client.remotes.upsert(orgId, projectId, {
93
- mountBranchName: projectDefaultBranch,
94
- mountPath,
95
- });
96
-
97
- process.stderr.write(
98
- `Uploading to ${remote.mountPath} ${filesToUpload.length} ${pluralize(
99
- 'file',
100
- filesToUpload.length
101
- )}:\n`
102
- );
103
-
104
- const { id } = await client.remotes.push(
105
- orgId,
106
- projectId,
107
- {
108
- remoteId: remote.id,
109
- commit: {
110
- message: argv.message,
111
- branchName: argv.branch,
112
- sha: commitSha,
113
- url: commitUrl,
114
- createdAt: argv['created-at'],
115
- namespace: argv.namespace,
116
- repository: argv.repository,
117
- author,
118
- },
119
- isMainBranch: defaultBranch === argv.branch,
120
- },
121
- filesToUpload.map((f) => ({ path: slash(f.name), stream: fs.createReadStream(f.path) }))
122
- );
123
-
124
- filesToUpload.forEach((f) => {
125
- process.stderr.write(green(`✓ ${f.name}\n`));
126
- });
127
-
128
- process.stdout.write('\n');
129
- process.stdout.write(`Push ID: ${id}\n`);
130
-
131
- if (waitForDeployment) {
132
- process.stdout.write('\n');
133
-
134
- await handlePushStatus({
135
- argv: {
136
- organization: orgId,
137
- project: projectId,
138
- pushId: id,
139
- wait: true,
140
- domain,
141
- 'max-execution-time': maxExecutionTime,
142
- 'start-time': startTime,
143
- 'continue-on-deploy-failures': argv['continue-on-deploy-failures'],
144
- },
145
- config,
146
- version,
147
- });
148
- }
149
- verbose &&
150
- printExecutionTime(
151
- commandName,
152
- startedAt,
153
- `${pluralize(
154
- 'file',
155
- filesToUpload.length
156
- )} uploaded to organization ${orgId}, project ${projectId}. Push ID: ${id}.`
157
- );
158
-
159
- client.reportSunsetWarnings();
160
-
161
- return {
162
- pushId: id,
163
- };
164
- } catch (err) {
165
- handleReuniteError('✗ File upload failed.', err);
166
- }
167
- }
168
-
169
- function parseCommitAuthor(author: string): { name: string; email: string } {
170
- // Author Name <author@email.com>
171
- const reg = /^.+\s<[^<>]+>$/;
172
-
173
- if (!reg.test(author)) {
174
- throw new Error('Invalid author format. Use "Author Name <author@email.com>"');
175
- }
176
-
177
- const [name, email] = author.split('<');
178
-
179
- return {
180
- name: name.trim(),
181
- email: email.replace('>', '').trim(),
182
- };
183
- }
184
-
185
- function collectFilesToPush(files: string[]): FileToUpload[] {
186
- const collectedFiles: Record<string, string> = {};
187
-
188
- for (const file of files) {
189
- if (fs.statSync(file).isDirectory()) {
190
- const dir = file;
191
- const fileList = getFilesList(dir, []);
192
-
193
- fileList.forEach((f) => addFile(f, dir));
194
- } else {
195
- addFile(file, path.dirname(file));
196
- }
197
- }
198
-
199
- function addFile(filePath: string, fileDir: string) {
200
- const fileName = path.relative(fileDir, filePath);
201
-
202
- if (collectedFiles[fileName]) {
203
- process.stdout.write(
204
- yellow(`File ${collectedFiles[fileName]} is overwritten by ${filePath}\n`)
205
- );
206
- }
207
-
208
- collectedFiles[fileName] = filePath;
209
- }
210
-
211
- return Object.entries(collectedFiles).map(([name, filePath]) => getFileEntry(name, filePath));
212
- }
213
-
214
- function getFileEntry(name: string, filePath: string): FileToUpload {
215
- return {
216
- name,
217
- path: path.resolve(filePath),
218
- };
219
- }
220
-
221
- function getFilesList(dir: string, files: string[]): string[] {
222
- const filesAndDirs = fs.readdirSync(dir);
223
-
224
- for (const name of filesAndDirs) {
225
- const currentPath = path.join(dir, name);
226
-
227
- if (fs.statSync(currentPath).isDirectory()) {
228
- files = getFilesList(currentPath, files);
229
- } else {
230
- files.push(currentPath);
231
- }
232
- }
233
-
234
- return files;
235
- }
@@ -1,66 +0,0 @@
1
- import { pause } from '@redocly/openapi-core';
2
- import { DeploymentError } from '../utils';
3
- import { exitWithError } from '../../utils/miscellaneous';
4
-
5
- import type { ReuniteApiError } from '../api';
6
-
7
- /**
8
- * This function retries an operation until a condition is met or a timeout is exceeded.
9
- * If the condition is not met within the timeout, an error is thrown.
10
- * @operation The operation to retry.
11
- * @condition The condition to check after each operation result. Return false to continue retrying. Return true to stop retrying.
12
- * If not provided, the first result will be returned.
13
- * @param onConditionNotMet Will be called with the last result right after checking condition and before timeout and retrying.
14
- * @param onRetry Will be called right before retrying operation with the last result before retrying.
15
- * @param startTime The start time of the operation. Default is the current time.
16
- * @param retryTimeoutMs The maximum time to retry the operation. Default is 10 minutes.
17
- * @param retryIntervalMs The interval between retries. Default is 5 seconds.
18
- */
19
- export async function retryUntilConditionMet<T>({
20
- operation,
21
- condition,
22
- onConditionNotMet,
23
- onRetry,
24
- startTime = Date.now(),
25
- retryTimeoutMs = 600000, // 10 min
26
- retryIntervalMs = 5000, // 5 sec
27
- }: {
28
- operation: () => Promise<T>;
29
- condition?: ((result: T) => boolean) | null;
30
- onConditionNotMet?: (lastResult: T) => void;
31
- onRetry?: (lastResult: T) => void | Promise<void>;
32
- startTime?: number;
33
- retryTimeoutMs?: number;
34
- retryIntervalMs?: number;
35
- }): Promise<T> {
36
- async function attempt(): Promise<T> {
37
- const result = await operation();
38
-
39
- if (!condition) {
40
- return result;
41
- }
42
-
43
- if (condition(result)) {
44
- return result;
45
- } else if (Date.now() - startTime > retryTimeoutMs) {
46
- throw new Error('Timeout exceeded.');
47
- } else {
48
- onConditionNotMet?.(result);
49
- await pause(retryIntervalMs);
50
- await onRetry?.(result);
51
- return attempt();
52
- }
53
- }
54
-
55
- return attempt();
56
- }
57
-
58
- export function handleReuniteError(
59
- message: string,
60
- error: ReuniteApiError | DeploymentError | Error
61
- ) {
62
- const errorMessage =
63
- error instanceof DeploymentError ? error.message : `${message} Reason: ${error.message}\n`;
64
-
65
- return exitWithError(errorMessage);
66
- }
@@ -1 +0,0 @@
1
- export class DeploymentError extends Error {}
package/src/types.ts DELETED
@@ -1,64 +0,0 @@
1
- import type { BundleOutputFormat, Region, Config, RuleSeverity } from '@redocly/openapi-core';
2
- import type { RespectOptions, GenerateArazzoFileOptions } from '@redocly/respect-core';
3
- import type { ArgumentsCamelCase } from 'yargs';
4
- import type { LintOptions } from './commands/lint';
5
- import type { BundleOptions } from './commands/bundle';
6
- import type { JoinOptions } from './commands/join';
7
- import type { LoginOptions, LogoutOptions } from './commands/auth';
8
- import type { PushOptions } from './commands/push';
9
- import type { StatsOptions } from './commands/stats';
10
- import type { SplitOptions } from './commands/split';
11
- import type { PreviewDocsOptions } from './commands/preview-docs';
12
- import type { BuildDocsArgv } from './commands/build-docs/types';
13
- import type { PushOptions as CMSPushOptions } from './reunite/commands/push';
14
- import type { PushStatusOptions } from './reunite/commands/push-status';
15
- import type { PreviewProjectOptions } from './commands/preview-project/types';
16
- import type { TranslationsOptions } from './commands/translations';
17
- import type { EjectOptions } from './commands/eject';
18
-
19
- export type Totals = {
20
- errors: number;
21
- warnings: number;
22
- ignored: number;
23
- };
24
- export type Entrypoint = {
25
- path: string;
26
- alias?: string;
27
- output?: string;
28
- };
29
- export const outputExtensions = ['json', 'yaml', 'yml'] as ReadonlyArray<BundleOutputFormat>;
30
- export type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
31
- export const regionChoices = ['us', 'eu'] as ReadonlyArray<Region>;
32
- export type CommandOptions =
33
- | StatsOptions
34
- | SplitOptions
35
- | JoinOptions
36
- | PushOptions
37
- | CMSPushOptions
38
- | LintOptions
39
- | BundleOptions
40
- | LoginOptions
41
- | LogoutOptions
42
- | PreviewDocsOptions
43
- | BuildDocsArgv
44
- | PushStatusOptions
45
- | PreviewProjectOptions
46
- | TranslationsOptions
47
- | EjectOptions
48
- | RespectOptions
49
- | GenerateArazzoFileOptions;
50
-
51
- export type VerifyConfigOptions = {
52
- config?: string;
53
- 'lint-config'?: RuleSeverity;
54
- };
55
-
56
- export type Skips = {
57
- 'skip-rule'?: string[];
58
- 'skip-decorator'?: string[];
59
- 'skip-preprocessor'?: string[];
60
- };
61
-
62
- export type ConfigApis = Pick<Config, 'apis' | 'configFile'>;
63
-
64
- export type PushArguments = ArgumentsCamelCase<PushOptions & CMSPushOptions & { apis: string[] }>;