@cmflow/cli 3.3.0 → 3.4.0-alpha.1

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 (212) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/.yarn/releases/yarn-4.18.0.cjs +1000 -0
  3. package/.yarnrc.yml +8 -1
  4. package/bin/cm-checkfeatures.ts +10 -0
  5. package/bin/cm-clean.ts +10 -0
  6. package/bin/cm-config.ts +10 -0
  7. package/bin/cm-deploy.ts +10 -0
  8. package/bin/{cm-expedit.js → cm-expedit.ts} +4 -4
  9. package/bin/cm-fetch.ts +10 -0
  10. package/bin/cm-finish.ts +10 -0
  11. package/bin/cm-jira-releases.ts +10 -0
  12. package/bin/cm-merge.ts +10 -0
  13. package/bin/cm-publish.ts +10 -0
  14. package/bin/cm-pull.ts +8 -0
  15. package/bin/cm-push.ts +10 -0
  16. package/bin/cm-rebase.ts +10 -0
  17. package/bin/{cmrelease.js → cm-release.ts} +0 -0
  18. package/bin/cm-republish.ts +10 -0
  19. package/bin/cm-start.ts +10 -0
  20. package/bin/cm.ts +40 -0
  21. package/dist/bin/cm.mjs +74985 -0
  22. package/dist/bin/cmrelease.mjs +72397 -0
  23. package/dist/cli-truncate-BmHD4ngn.mjs +152 -0
  24. package/dist/cli-truncate-CXNquMRK.mjs +152 -0
  25. package/dist/cli-truncate-DbOyuy2e.mjs +2 -0
  26. package/dist/cli-truncate-DbOyuy2e.mjs.map +1 -0
  27. package/dist/common-CwPbT3So.mjs +66 -0
  28. package/dist/common-CwPbT3So.mjs.map +1 -0
  29. package/dist/docker-clean-tags-Cd-E8IqJ.mjs +2 -0
  30. package/dist/docker-clean-tags-Cd-E8IqJ.mjs.map +1 -0
  31. package/dist/docker-publish-B0E0qYYB.mjs +2 -0
  32. package/dist/docker-publish-B0E0qYYB.mjs.map +1 -0
  33. package/dist/get-config-DoOyLztI.mjs +41 -0
  34. package/dist/get-config-DoOyLztI.mjs.map +1 -0
  35. package/dist/get-east-asian-width-Tfn8qoqd.mjs +2 -0
  36. package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -0
  37. package/dist/get-east-asian-width-eFfEkHwo.mjs +682 -0
  38. package/dist/log-update-B2GqeeDd.mjs +497 -0
  39. package/dist/log-update-BldA9lkm.mjs +497 -0
  40. package/dist/log-update-By8Z-mak.mjs +6 -0
  41. package/dist/log-update-By8Z-mak.mjs.map +1 -0
  42. package/dist/rolldown-runtime-B4iAMlE-.mjs +35 -0
  43. package/dist/semver-D8gwMSFO.mjs +2 -0
  44. package/dist/semver-D8gwMSFO.mjs.map +1 -0
  45. package/dist/src/index.mjs +18 -0
  46. package/dist/src/index.mjs.map +1 -0
  47. package/dist/src/semantic/core/analyze-commits.mjs +2 -0
  48. package/dist/src/semantic/core/analyze-commits.mjs.map +1 -0
  49. package/dist/src/semantic/core/conditional.mjs +2 -0
  50. package/dist/src/semantic/core/conditional.mjs.map +1 -0
  51. package/dist/src/semantic/core/exit.mjs +2 -0
  52. package/dist/src/semantic/core/exit.mjs.map +1 -0
  53. package/dist/src/semantic/core/prepare/bump-version.mjs +48 -0
  54. package/dist/src/semantic/core/prepare/bump-version.mjs.map +1 -0
  55. package/dist/src/semantic/core/prepare/commit.mjs +2 -0
  56. package/dist/src/semantic/core/prepare/commit.mjs.map +1 -0
  57. package/dist/src/semantic/core/prepare/release-info.mjs +2 -0
  58. package/dist/src/semantic/core/prepare/release-info.mjs.map +1 -0
  59. package/dist/src/semantic/core/run.mjs +2 -0
  60. package/dist/src/semantic/core/run.mjs.map +1 -0
  61. package/dist/src/semantic/core/sync-repository.mjs +2 -0
  62. package/dist/src/semantic/core/sync-repository.mjs.map +1 -0
  63. package/dist/src/semantic/core/verify-conditions.mjs +2 -0
  64. package/dist/src/semantic/core/verify-conditions.mjs.map +1 -0
  65. package/dist/src/semantic/core/verify-release.mjs +2 -0
  66. package/dist/src/semantic/core/verify-release.mjs.map +1 -0
  67. package/dist/src/semantic/docker/publish.mjs +2 -0
  68. package/dist/src/semantic/docker/publish.mjs.map +1 -0
  69. package/dist/src/semantic/docker/success.mjs +2 -0
  70. package/dist/src/semantic/docker/success.mjs.map +1 -0
  71. package/dist/strip-ansi-Aeu5cmZe.mjs +174 -0
  72. package/dist/strip-ansi-Cl0pRo-s.mjs +2 -0
  73. package/dist/strip-ansi-Cl0pRo-s.mjs.map +1 -0
  74. package/dist/wrap-ansi-BeIjar2W.mjs +2 -0
  75. package/dist/wrap-ansi-CWIezXNl.mjs +330 -0
  76. package/dist/wrap-ansi-DsMb4WnZ.mjs +9 -0
  77. package/dist/wrap-ansi-DsMb4WnZ.mjs.map +1 -0
  78. package/dist/wrap-ansi-T0rz0Urp.mjs +330 -0
  79. package/package.json +47 -38
  80. package/release.config.mjs +6 -6
  81. package/src/commands/checkfeatures.ts +39 -0
  82. package/src/commands/clean.ts +36 -0
  83. package/src/commands/config.ts +31 -0
  84. package/src/commands/deploy.ts +39 -0
  85. package/src/commands/fetch.ts +30 -0
  86. package/src/commands/finish.ts +50 -0
  87. package/src/commands/{index.js → index.ts} +1 -0
  88. package/src/commands/jira-releases.ts +97 -0
  89. package/src/commands/merge.ts +58 -0
  90. package/src/commands/prompts/{branches.js → branches.ts} +13 -5
  91. package/src/commands/pull.ts +44 -0
  92. package/src/commands/push.ts +48 -0
  93. package/src/commands/rebase.ts +56 -0
  94. package/src/commands/republish.ts +34 -0
  95. package/src/commands/start.ts +123 -0
  96. package/src/commands/tasks/{merge-branch.js → merge-branch.ts} +18 -3
  97. package/src/commands/tasks/push-branch.ts +19 -0
  98. package/src/commands/tasks/{rebase-all-branches.js → rebase-all-branches.ts} +10 -2
  99. package/src/commands/tasks/{refresh-repository.js → refresh-repository.ts} +8 -4
  100. package/src/commands/tasks/run-test.ts +28 -0
  101. package/src/commands/tasks/{update-branch.js → update-branch.ts} +15 -9
  102. package/src/commands/tasks/{update-dependencies.js → update-dependencies.ts} +4 -3
  103. package/src/common/back/directus/{directus-flow.test.js → directus-flow.test.ts} +1 -0
  104. package/src/common/back/directus/{directus-flow.js → directus-flow.ts} +10 -2
  105. package/src/common/back/http/{http-proxy.js → http-proxy.ts} +7 -1
  106. package/src/common/back/http/{http-request.spec.js → http-request.spec.ts} +8 -7
  107. package/src/common/back/http/{http-request.js → http-request.ts} +16 -19
  108. package/src/common/back/jira/{get-sorted-releases.js → get-sorted-releases.ts} +2 -2
  109. package/src/common/back/jira/{jira-releases.js → jira-releases.ts} +14 -3
  110. package/src/common/back/jira/{jira-request.js → jira-request.ts} +9 -1
  111. package/src/common/back/jira/{jira-search.js → jira-search.ts} +2 -2
  112. package/src/common/cli/{bun.test.js → bun.test.ts} +17 -10
  113. package/src/common/cli/{bun.js → bun.ts} +4 -4
  114. package/src/common/cli/cli.ts +127 -0
  115. package/src/common/cli/{docker.test.js → docker.test.ts} +22 -14
  116. package/src/common/cli/{docker.js → docker.ts} +6 -6
  117. package/src/common/cli/{git.test.js → git.test.ts} +19 -11
  118. package/src/common/cli/{git.js → git.ts} +24 -24
  119. package/src/common/cli/{lerna.test.js → lerna.test.ts} +18 -11
  120. package/src/common/cli/{lerna.js → lerna.ts} +4 -4
  121. package/src/common/cli/{npm.test.js → npm.test.ts} +17 -10
  122. package/src/common/cli/{npm.js → npm.ts} +4 -4
  123. package/src/common/cli/{pnpm.test.js → pnpm.test.ts} +17 -10
  124. package/src/common/cli/{pnpm.js → pnpm.ts} +4 -4
  125. package/src/common/cli/{yarn.test.js → yarn.test.ts} +17 -12
  126. package/src/common/cli/{yarn.js → yarn.ts} +4 -4
  127. package/src/common/configure-git-workspace.ts +39 -0
  128. package/src/common/{get-config.js → get-config.ts} +3 -1
  129. package/src/common/{get-package-json.js → get-package-json.ts} +1 -0
  130. package/src/common/{get-package-manager.js → get-package-manager.ts} +1 -0
  131. package/src/common/{get-release-config.js → get-release-config.ts} +1 -0
  132. package/src/common/{index.js → index.ts} +1 -0
  133. package/src/common/{run-command.test.js → run-command.test.ts} +1 -0
  134. package/src/common/run-command.ts +67 -0
  135. package/src/common/types.ts +26 -0
  136. package/src/common/vendor.d.ts +4 -0
  137. package/src/{index.js → index.ts} +5 -1
  138. package/src/semantic/core/{analyze-commits.js → analyze-commits.ts} +7 -3
  139. package/src/semantic/core/{conditional.js → conditional.ts} +16 -9
  140. package/src/semantic/core/{exit.js → exit.ts} +3 -2
  141. package/src/semantic/core/prepare/{bump-version.js → bump-version.ts} +11 -8
  142. package/src/semantic/core/prepare/{commit.js → commit.ts} +3 -2
  143. package/src/semantic/core/prepare/release-info.ts +6 -0
  144. package/src/semantic/core/{run.js → run.ts} +3 -2
  145. package/src/semantic/core/sync-repository.ts +55 -0
  146. package/src/semantic/core/{verify-conditions.js → verify-conditions.ts} +4 -3
  147. package/src/semantic/core/{verify-release.js → verify-release.ts} +2 -1
  148. package/src/semantic/docker/publish.ts +6 -0
  149. package/src/semantic/docker/{success.js → success.ts} +2 -1
  150. package/src/semantic/utils/{bump-packages-version.test.js → bump-packages-version.test.ts} +1 -0
  151. package/src/semantic/utils/{bump-packages-version.js → bump-packages-version.ts} +12 -11
  152. package/src/semantic/utils/{calculate-snapshot-version.test.js → calculate-snapshot-version.test.ts} +10 -8
  153. package/src/semantic/utils/calculate-snapshot-version.ts +17 -0
  154. package/src/semantic/utils/display-package-info.ts +12 -0
  155. package/src/semantic/utils/display-release-info.ts +13 -0
  156. package/src/semantic/utils/{docker-clean-tags.test.js → docker-clean-tags.test.ts} +1 -0
  157. package/src/semantic/utils/{docker-clean-tags.js → docker-clean-tags.ts} +11 -4
  158. package/src/semantic/utils/{docker-publish.test.js → docker-publish.test.ts} +1 -0
  159. package/src/semantic/utils/{docker-publish.js → docker-publish.ts} +4 -3
  160. package/src/semantic/utils/{log-section.js → log-section.ts} +5 -1
  161. package/src/semantic/utils/{transform-writer.js → transform-writer.ts} +37 -13
  162. package/tsconfig.build.json +29 -0
  163. package/tsconfig.json +8 -15
  164. package/tsdown.config.ts +63 -0
  165. package/vitest.config.mts +2 -3
  166. package/.yarn/releases/yarn-4.7.0.cjs +0 -935
  167. package/bin/checkfeatures.js +0 -13
  168. package/bin/cm-clean.js +0 -8
  169. package/bin/cm-config.js +0 -15
  170. package/bin/cm-deploy.js +0 -8
  171. package/bin/cm-fetch.js +0 -12
  172. package/bin/cm-finish.js +0 -14
  173. package/bin/cm-jira-releases.js +0 -16
  174. package/bin/cm-merge.js +0 -12
  175. package/bin/cm-publish.js +0 -15
  176. package/bin/cm-push.js +0 -15
  177. package/bin/cm-rebase.js +0 -15
  178. package/bin/cm-republish.js +0 -12
  179. package/bin/cm-start.js +0 -21
  180. package/bin/cm.js +0 -27
  181. package/bin/cmpull.js +0 -22
  182. package/src/commands/checkfeatures.js +0 -20
  183. package/src/commands/clean.js +0 -29
  184. package/src/commands/config.js +0 -23
  185. package/src/commands/deploy.js +0 -34
  186. package/src/commands/fetch.js +0 -18
  187. package/src/commands/finish.js +0 -43
  188. package/src/commands/jira-releases.js +0 -62
  189. package/src/commands/merge.js +0 -41
  190. package/src/commands/pull.js +0 -30
  191. package/src/commands/push.js +0 -23
  192. package/src/commands/rebase.js +0 -35
  193. package/src/commands/republish.js +0 -21
  194. package/src/commands/start.js +0 -109
  195. package/src/commands/tasks/push-branch.js +0 -10
  196. package/src/commands/tasks/run-test.js +0 -21
  197. package/src/common/cli/cli.js +0 -110
  198. package/src/common/configure-git-workspace.js +0 -26
  199. package/src/common/run-command.js +0 -64
  200. package/src/semantic/core/prepare/release-info.js +0 -5
  201. package/src/semantic/core/sync-repository.js +0 -52
  202. package/src/semantic/docker/publish.js +0 -5
  203. package/src/semantic/utils/calculate-snapshot-version.js +0 -15
  204. package/src/semantic/utils/display-package-info.js +0 -11
  205. package/src/semantic/utils/display-release-info.js +0 -12
  206. /package/src/commands/{release.js → release.ts} +0 -0
  207. /package/src/commands/utils/{check-install.js → check-install.ts} +0 -0
  208. /package/src/common/back/jira/{jira-request.spec.js → jira-request.spec.ts} +0 -0
  209. /package/src/common/back/jira/{jira-search.spec.js → jira-search.spec.ts} +0 -0
  210. /package/src/semantic/{define-config.js → define-config.ts} +0 -0
  211. /package/src/semantic/utils/{release-rules.js → release-rules.ts} +0 -0
  212. /package/src/workflow/{index.js → index.ts} +0 -0
@@ -1,9 +1,9 @@
1
- import Listr from "listr";
2
- import { catchError, EMPTY } from "rxjs";
1
+ import { Listr } from "listr2";
2
+ import { catchError, EMPTY, type Observable } from "rxjs";
3
3
 
4
4
  import { git } from "../../common/index.js";
5
5
 
6
- function pipe(observable, output) {
6
+ function pipe(observable: Observable<string>, output: unknown[]) {
7
7
  observable.pipe(
8
8
  catchError((err) => {
9
9
  output.push(err);
@@ -18,7 +18,11 @@ function pipe(observable, output) {
18
18
  return observable;
19
19
  }
20
20
 
21
- export function refreshRepository(context) {
21
+ interface RefreshRepositoryContext {
22
+ output?: unknown[];
23
+ }
24
+
25
+ export function refreshRepository(context: RefreshRepositoryContext) {
22
26
  const { output = [] } = context;
23
27
 
24
28
  return {
@@ -0,0 +1,28 @@
1
+ import { getPackageManager, git } from "../../common/index.js";
2
+ import type { CmContext, ListrTask } from "../../common/types";
3
+
4
+ type RunTestContext = CmContext<{
5
+ skipTest?: boolean;
6
+ skipUnit?: boolean;
7
+ skipE2E?: boolean;
8
+ }>;
9
+
10
+ export const runTest = ({ config: { E2E_CMD, PACKAGE_MANAGER }, skipTest, skipUnit, skipE2E }: RunTestContext): ListrTask[] => {
11
+ return [
12
+ {
13
+ title: "Unit test",
14
+ skip: () => Boolean(skipTest || skipUnit),
15
+ task: () => getPackageManager(PACKAGE_MANAGER).run("test")
16
+ },
17
+ {
18
+ title: "E2E test",
19
+ skip: () => Boolean(skipTest || skipE2E),
20
+ task: () => getPackageManager(PACKAGE_MANAGER).run(E2E_CMD || "test_e2e")
21
+ },
22
+ {
23
+ title: "Reset changes",
24
+ skip: () => !!skipTest,
25
+ task: () => git.reset("--hard") as unknown as void // reset files updated unit test
26
+ }
27
+ ];
28
+ };
@@ -1,9 +1,19 @@
1
1
  import chalk from "chalk";
2
- import Listr from "listr";
2
+ import { Listr } from "listr2";
3
3
 
4
4
  import { git } from "../../common/cli/git.js";
5
+ import type { CmContext, ListrTask } from "../../common/types";
5
6
 
6
- async function checkBranchRemoteStatus({ featureBranch, origin, force }) {
7
+ type UpdateBranchContext = CmContext<{
8
+ origin: string;
9
+ featureBranch: string;
10
+ fromBranch: string;
11
+ force: boolean;
12
+ checkStatus?: boolean;
13
+ rebase?: boolean;
14
+ }>;
15
+
16
+ async function checkBranchRemoteStatus({ featureBranch, origin, force }: UpdateBranchContext) {
7
17
  const isBranchExists = git.branchExists(featureBranch, origin);
8
18
 
9
19
  if (isBranchExists && !force) {
@@ -15,7 +25,8 @@ async function checkBranchRemoteStatus({ featureBranch, origin, force }) {
15
25
  }
16
26
  }
17
27
 
18
- export const updateBranch = ({ origin, featureBranch, fromBranch, force, checkStatus = true, rebase = true }) => {
28
+ export const updateBranch = (context: UpdateBranchContext): ListrTask => {
29
+ const { origin, fromBranch, checkStatus = true, rebase = true } = context;
19
30
  return {
20
31
  title: "Rebase branch",
21
32
  task: () =>
@@ -24,12 +35,7 @@ export const updateBranch = ({ origin, featureBranch, fromBranch, force, checkSt
24
35
  {
25
36
  title: "Check status",
26
37
  enabled: () => checkStatus,
27
- task: () =>
28
- checkBranchRemoteStatus({
29
- force,
30
- featureBranch,
31
- origin
32
- })
38
+ task: () => checkBranchRemoteStatus(context)
33
39
  },
34
40
  {
35
41
  title: `Rebase from ${origin}/${chalk.green(fromBranch)}`,
@@ -1,10 +1,11 @@
1
- import Listr from "listr";
1
+ import { Listr } from "listr2";
2
2
  import { catchError } from "rxjs";
3
3
 
4
4
  import { getPackageManager } from "../../common/index.js";
5
+ import type { CmContext, ListrTask } from "../../common/types";
5
6
  import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
6
7
 
7
- export const updateDependencies = ({ PACKAGE_MANAGER }) => {
8
+ export const updateDependencies = ({ config: { PACKAGE_MANAGER } }: CmContext): ListrTask => {
8
9
  const reinstall = shouldReinstall();
9
10
 
10
11
  return {
@@ -36,7 +37,7 @@ export const updateDependencies = ({ PACKAGE_MANAGER }) => {
36
37
  task: () => refreshMetadata()
37
38
  }
38
39
  ],
39
- { concurrency: false }
40
+ { concurrent: false }
40
41
  )
41
42
  };
42
43
  };
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  // Use vi.hoisted to create mock references that are available to mock factories
2
3
  const httpRequestMock = vi.hoisted(() => vi.fn());
3
4
 
@@ -11,12 +11,20 @@ import { httpRequest } from "../http/http-request.js";
11
11
  * @param {object} [opts] - Additional request options (e.g., rejectUnauthorized)
12
12
  * @returns {Promise<unknown>} The parsed JSON response
13
13
  */
14
- export async function triggerDirectusFlow(projectId, versions, opts = {}) {
14
+ export async function triggerDirectusFlow(projectId: string, versions: string[], opts: Record<string, unknown> = {}) {
15
15
  const { DIRECTUS_URL, DIRECTUS_FLOW_ID, DIRECTUS_ACCESS_TOKEN } = getConfig();
16
16
 
17
17
  const endpoint = `${DIRECTUS_URL}/flows/trigger/${DIRECTUS_FLOW_ID}`;
18
18
 
19
- const options = {
19
+ const options: {
20
+ method: string;
21
+ callee: string;
22
+ headers: Record<string, string>;
23
+ data: Record<string, unknown> | string;
24
+ retries: number;
25
+ retryDelay: unknown;
26
+ [key: string]: unknown;
27
+ } = {
20
28
  method: "post",
21
29
  callee: "DIRECTUS",
22
30
  headers: {
@@ -4,7 +4,13 @@ import { getConfig } from "../../get-config.js";
4
4
 
5
5
  const { HTTPS_PROXY } = getConfig();
6
6
 
7
- export const getHttpProxy = (opts) => {
7
+ interface HttpProxyOptions {
8
+ callee?: string;
9
+ rejectUnauthorized?: boolean;
10
+ [key: string]: unknown;
11
+ }
12
+
13
+ export const getHttpProxy = (opts: HttpProxyOptions) => {
8
14
  if (HTTPS_PROXY) {
9
15
  console.debug({
10
16
  message: `Using proxy agent for ${opts.callee} requests`,
@@ -9,12 +9,12 @@ vi.mock("axios-retry");
9
9
  vi.mock("./http-proxy.js");
10
10
 
11
11
  describe("httpRequest", () => {
12
- let mockInstance;
12
+ let mockInstance: ReturnType<typeof vi.fn>;
13
13
 
14
14
  beforeEach(() => {
15
15
  vi.clearAllMocks();
16
16
  mockInstance = vi.fn();
17
- vi.mocked(axios.create).mockReturnValue(mockInstance);
17
+ vi.mocked(axios.create).mockReturnValue(mockInstance as unknown as ReturnType<typeof axios.create>);
18
18
  });
19
19
 
20
20
  it("should create an agent in production with proxy", async () => {
@@ -37,11 +37,12 @@ describe("httpRequest", () => {
37
37
  });
38
38
 
39
39
  it("should throw an error if the response is not ok", async () => {
40
- const axiosError = new Error("Request failed");
41
- axiosError.response = {
42
- status: 500,
43
- data: { error: "Internal server error" }
44
- };
40
+ const axiosError = Object.assign(new Error("Request failed"), {
41
+ response: {
42
+ status: 500,
43
+ data: { error: "Internal server error" }
44
+ }
45
+ });
45
46
  mockInstance.mockRejectedValue(axiosError);
46
47
 
47
48
  await expect(httpRequest("http://example.com/test-endpoint", { callee: "test" })).rejects.toThrow("HTTP error! status: 500");
@@ -11,23 +11,19 @@ import { getHttpProxy } from "./http-proxy.js";
11
11
  * @property {boolean} [retryOnIdempotentRequests=true] - Retry on 5xx for idempotent requests
12
12
  */
13
13
 
14
- /**
15
- * @typedef {Object} HttpRequestOptions
16
- * @property {boolean} [rejectUnauthorized] - Whether to reject unauthorized SSL certificates
17
- * @property {string} [callee] - The name of the caller
18
- * @property {Record<string, string>} [params] - Query parameters to be included in the request
19
- * @property {string} [method] - HTTP method (default: 'get')
20
- * @property {Record<string, string>} [headers] - Custom headers to be included in the request
21
- * @property {RetryOptions|boolean} [retry] - Retry configuration (true for defaults, or custom config)
22
- */
14
+ interface HttpRequestOptions {
15
+ rejectUnauthorized?: boolean;
16
+ callee?: string;
17
+ params?: Record<string, string>;
18
+ method?: string;
19
+ headers?: Record<string, string>;
20
+ retries?: number;
21
+ retryDelay?: unknown;
22
+ data?: unknown;
23
+ [key: string]: unknown;
24
+ }
23
25
 
24
- /**
25
- *
26
- * @param endpoint {string}
27
- * @param options {HttpRequestOptions}
28
- * @return {Promise<*>}
29
- */
30
- export async function httpRequest(endpoint, options = {}) {
26
+ export async function httpRequest(endpoint: string, options: HttpRequestOptions = {}) {
31
27
  const { callee, headers, method = "get", params = {}, rejectUnauthorized, ...rest } = options;
32
28
  const httpsAgent = getHttpProxy({
33
29
  rejectUnauthorized,
@@ -36,7 +32,7 @@ export async function httpRequest(endpoint, options = {}) {
36
32
 
37
33
  const instance = axios.create();
38
34
 
39
- axiosRetry(instance, options);
35
+ axiosRetry(instance, options as Parameters<typeof axiosRetry>[1]);
40
36
 
41
37
  try {
42
38
  const response = await instance({
@@ -60,8 +56,9 @@ export async function httpRequest(endpoint, options = {}) {
60
56
 
61
57
  return response.data;
62
58
  } catch (error) {
63
- const status = error.response?.status;
64
- const responseData = error.response?.data;
59
+ const axiosError = error as { response?: { status: number; data: unknown } };
60
+ const status = axiosError.response?.status;
61
+ const responseData = axiosError.response?.data;
65
62
 
66
63
  console.error({
67
64
  ...options,
@@ -8,7 +8,7 @@ import { getJiraReleases } from "./jira-releases.js";
8
8
  * @param component {string}
9
9
  * @param tagVersion {string}
10
10
  */
11
- export async function getSortedReleases(projectId, component, tagVersion) {
11
+ export async function getSortedReleases(projectId: string, component: string, tagVersion: string) {
12
12
  const releases = await getJiraReleases(projectId);
13
13
 
14
14
  const promises = releases
@@ -24,7 +24,7 @@ export async function getSortedReleases(projectId, component, tagVersion) {
24
24
  }
25
25
  })
26
26
  .sort((ra, rb) => {
27
- return semver.rcompare(ra.version, rb.version);
27
+ return semver.rcompare(ra.version!, rb.version!);
28
28
  });
29
29
 
30
30
  const [current, ...others] = await Promise.all(promises);
@@ -1,6 +1,17 @@
1
1
  import { jiraRequest } from "./jira-request.js";
2
2
 
3
- export async function getJiraReleases(projectId) {
3
+ interface JiraRelease {
4
+ id: string;
5
+ name: string;
6
+ description?: string;
7
+ archived?: boolean;
8
+ released?: boolean;
9
+ projectId?: string;
10
+ releaseDate?: string;
11
+ version?: string;
12
+ }
13
+
14
+ export async function getJiraReleases(projectId: string): Promise<JiraRelease[]> {
4
15
  const endpoint = `/rest/api/3/project/${projectId}/versions?expand`;
5
16
  const response = await jiraRequest(endpoint);
6
17
 
@@ -8,10 +19,10 @@ export async function getJiraReleases(projectId) {
8
19
  return [];
9
20
  }
10
21
 
11
- return response;
22
+ return response as JiraRelease[];
12
23
  }
13
24
 
14
- export async function updateJiraRelease(release) {
25
+ export async function updateJiraRelease(release: JiraRelease) {
15
26
  const endpoint = `/rest/api/3/version/${release.id}`;
16
27
  try {
17
28
  await jiraRequest(endpoint, {
@@ -3,7 +3,15 @@ import axiosRetry from "axios-retry";
3
3
  import { getConfig } from "../../get-config.js";
4
4
  import { httpRequest } from "../http/http-request.js";
5
5
 
6
- export async function jiraRequest(endpoint, opts = {}) {
6
+ interface JiraRequestOptions {
7
+ method?: string;
8
+ headers?: Record<string, string>;
9
+ data?: unknown;
10
+ params?: Record<string, string>;
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ export async function jiraRequest(endpoint: string, opts: JiraRequestOptions = {}) {
7
15
  const { JIRA_API, JIRA_TOKEN, JIRA_EMAIL } = getConfig();
8
16
  const jiraUrl = `${JIRA_API}${endpoint}`;
9
17
  const auth = Buffer.from(`${JIRA_EMAIL}:${JIRA_TOKEN}`).toString("base64");
@@ -7,10 +7,10 @@ import { jiraRequest } from "./jira-request.js";
7
7
  * @param opts {object} Options
8
8
  * @returns {Promise<{issues: (import("./interfaces/JiraIIssue.d.ts").JiraIssue & Expand)[], total: number, maxResults: number}>}
9
9
  */
10
- export function jiraSearch(jql, opts) {
10
+ export function jiraSearch(jql: string, opts?: Record<string, unknown>) {
11
11
  return jiraRequest("/rest/api/3/search/jql", {
12
12
  params: {
13
- ...opts,
13
+ ...(opts as Record<string, string>),
14
14
  jql
15
15
  }
16
16
  });
@@ -1,24 +1,31 @@
1
+ import execa from "execa";
2
+ import { bun } from "./bun.js";
3
+ import { Cli } from "./cli.js";
4
+
1
5
  vi.mock("execa", () => {
2
- const execaMock = vi.fn();
3
- execaMock.sync = vi.fn();
6
+ const sync = vi.fn();
7
+ const execaMock = Object.assign(vi.fn(), { sync });
4
8
  return { default: execaMock };
5
9
  });
6
10
 
7
- const { default: execa } = await import("execa");
8
- const { bun } = await import("./bun.js");
9
- const { Cli } = await import("./cli.js");
11
+ type ExecaMock = {
12
+ sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
13
+ mockReturnValue(v: unknown): void;
14
+ };
15
+
16
+ const execaMock = execa as unknown as ExecaMock;
10
17
 
11
- execa.sync.mockImplementation((...args) => {
18
+ execaMock.sync.mockImplementation((...args) => {
12
19
  return {
13
- stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
20
+ stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
14
21
  };
15
22
  });
16
- execa.mockReturnValue({});
23
+ execaMock.mockReturnValue({});
17
24
 
18
25
  describe("BunCli", () => {
19
26
  beforeEach(() => {
20
- vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
21
- return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
27
+ vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
28
+ return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
22
29
  });
23
30
  });
24
31
  describe("newVersion", () => {
@@ -5,19 +5,19 @@ class BunCli extends Cli {
5
5
  super("bun");
6
6
  }
7
7
 
8
- newVersion(version) {
8
+ newVersion(version: string) {
9
9
  return this.pm("version", "--no-git-tag-version", version);
10
10
  }
11
11
 
12
- pm(...args) {
12
+ pm(...args: string[]) {
13
13
  return this.sync("pm", ...args);
14
14
  }
15
15
 
16
- run(...args) {
16
+ run(...args: string[]) {
17
17
  return super.run("run", ...args);
18
18
  }
19
19
 
20
- install(...args) {
20
+ install(...args: string[]) {
21
21
  return super.run("install", ...args);
22
22
  }
23
23
 
@@ -0,0 +1,127 @@
1
+ import "any-observable/register/rxjs-all.js";
2
+
3
+ import { spawnSync, type SpawnSyncOptions } from "child_process";
4
+ import execa from "execa";
5
+ import { filter, fromEvent, map, merge, takeUntil } from "rxjs";
6
+ import type { Observable } from "rxjs";
7
+
8
+ type RunOptions = Record<string, unknown>;
9
+
10
+ export interface CliResult extends Promise<unknown> {
11
+ toObservable(opt?: RunOptions): Observable<string>;
12
+ toStream(opt?: RunOptions): execa.ExecaChildProcess<string>;
13
+ cwd(cwd: string): CliResult;
14
+ sync(opt?: RunOptions): execa.ExecaSyncReturnValue<string>;
15
+ getRaw(opt?: RunOptions): string;
16
+ get(opt?: RunOptions): string;
17
+ }
18
+
19
+ export class Cli {
20
+ cmd: string;
21
+
22
+ constructor(cmd: string) {
23
+ this.cmd = cmd;
24
+ }
25
+
26
+ sync(...args: string[]): execa.ExecaSyncReturnValue<string> {
27
+ return (Cli.run(this.cmd, args) as CliResult).sync();
28
+ }
29
+
30
+ run(...args: string[]): CliResult {
31
+ return Cli.run(this.cmd, args);
32
+ }
33
+
34
+ get(...args: string[]): string {
35
+ return (Cli.run(this.cmd, args) as CliResult).get();
36
+ }
37
+
38
+ static run(cmd: string, args: string[] = [], options: RunOptions = {}): CliResult {
39
+ const run = (opt: RunOptions = {}) => {
40
+ return execa(cmd, args, {
41
+ cwd: process.cwd(),
42
+ ...opt,
43
+ ...options
44
+ } as execa.Options);
45
+ };
46
+
47
+ let isPromise = true;
48
+
49
+ const promise = new Promise<void>((resolve, reject) => {
50
+ setTimeout(async () => {
51
+ if (isPromise) {
52
+ try {
53
+ const result = await run({
54
+ stdio: "inherit"
55
+ });
56
+
57
+ resolve(result as unknown as void);
58
+ } catch (err) {
59
+ reject(err);
60
+ }
61
+ } else {
62
+ resolve();
63
+ }
64
+ }, 10);
65
+ });
66
+
67
+ const cliResult = promise as unknown as CliResult;
68
+
69
+ cliResult.toObservable = (opt?: RunOptions): Observable<string> => {
70
+ isPromise = false;
71
+ const cp = run(opt);
72
+ const end$ = fromEvent(cp, "close");
73
+ const stdout$ = fromEvent(cp.stdout!, "data").pipe(
74
+ takeUntil(end$),
75
+ map((data) => (data as Buffer).toString())
76
+ );
77
+ const stderr$ = fromEvent(cp.stderr!, "data").pipe(
78
+ takeUntil(end$),
79
+ map((data) => (data as Buffer).toString())
80
+ );
81
+
82
+ return merge(stdout$, stderr$).pipe(filter(Boolean));
83
+ };
84
+
85
+ cliResult.toStream = (opt?: RunOptions) => {
86
+ isPromise = false;
87
+
88
+ return run(opt);
89
+ };
90
+
91
+ cliResult.cwd = (cwd: string) => {
92
+ options.cwd = cwd;
93
+ return cliResult;
94
+ };
95
+
96
+ cliResult.sync = (opt?: RunOptions) => {
97
+ isPromise = false;
98
+ return execa.sync(cmd, args, {
99
+ cwd: process.cwd(),
100
+ stdio: "inherit",
101
+ ...options,
102
+ ...opt
103
+ } as execa.SyncOptions);
104
+ };
105
+
106
+ cliResult.getRaw = (opt?: RunOptions): string => {
107
+ isPromise = false;
108
+ return Cli.getRaw(cmd, args, {
109
+ cwd: process.cwd(),
110
+ ...options,
111
+ ...opt
112
+ });
113
+ };
114
+
115
+ cliResult.get = cliResult.getRaw;
116
+
117
+ return cliResult;
118
+ }
119
+
120
+ static getRaw(cmd: string, args: string[], options?: RunOptions): string {
121
+ return (spawnSync(cmd, args, options as SpawnSyncOptions).output as (Buffer | null)[])
122
+ .filter((o): o is Buffer => o !== null)
123
+ .map((o) => o.toString())
124
+ .join("\n")
125
+ .trim();
126
+ }
127
+ }
@@ -1,28 +1,36 @@
1
+ import execa from "execa";
2
+ import axios from "axios";
3
+ import { docker } from "./docker.js";
4
+ import { Cli } from "./cli.js";
5
+
1
6
  vi.mock("axios", () => {
2
7
  return { default: vi.fn() };
3
8
  });
4
9
  vi.mock("execa", () => {
5
- const execaMock = vi.fn();
6
- execaMock.sync = vi.fn();
10
+ const sync = vi.fn();
11
+ const execaMock = Object.assign(vi.fn(), { sync });
7
12
  return { default: execaMock };
8
13
  });
9
- const { default: execa } = await import("execa");
10
- const { default: axios } = await import("axios");
11
- const { docker } = await import("./docker.js");
12
- const { Cli } = await import("./cli.js");
13
14
 
14
- execa.mockReturnValue({});
15
+ type ExecaMock = {
16
+ sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
17
+ mockReturnValue(v: unknown): void;
18
+ };
19
+
20
+ const execaMock = execa as unknown as ExecaMock;
15
21
 
16
- execa.sync.mockImplementation((...args) => {
22
+ execaMock.mockReturnValue({});
23
+
24
+ execaMock.sync.mockImplementation((...args) => {
17
25
  return {
18
- stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
26
+ stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
19
27
  };
20
28
  });
21
29
 
22
30
  describe("DockerCli", () => {
23
31
  beforeEach(() => {
24
- vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
25
- return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
32
+ vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
33
+ return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
26
34
  });
27
35
  });
28
36
  describe("tag", () => {
@@ -58,7 +66,7 @@ describe("DockerCli", () => {
58
66
  });
59
67
  describe("getToken", () => {
60
68
  beforeEach(() => {
61
- axios.mockReturnValue({ data: { token: "token" } });
69
+ vi.mocked(axios).mockReturnValue({ data: { token: "token" } } as unknown as ReturnType<typeof axios>);
62
70
  });
63
71
  it("should get token", async () => {
64
72
  const token = await docker.getToken("username", "password");
@@ -80,7 +88,7 @@ describe("DockerCli", () => {
80
88
  });
81
89
  describe("getTags", () => {
82
90
  beforeEach(() => {
83
- axios.mockReturnValue({
91
+ vi.mocked(axios).mockReturnValue({
84
92
  data: {
85
93
  results: [
86
94
  {
@@ -89,7 +97,7 @@ describe("DockerCli", () => {
89
97
  }
90
98
  ]
91
99
  }
92
- });
100
+ } as unknown as ReturnType<typeof axios>);
93
101
  });
94
102
  it("should get token", async () => {
95
103
  const tags = await docker.getTags({
@@ -7,19 +7,19 @@ class DockerCli extends Cli {
7
7
  super("docker");
8
8
  }
9
9
 
10
- tag(...args) {
10
+ tag(...args: string[]) {
11
11
  return this.get("tag", ...args);
12
12
  }
13
13
 
14
- login(...args) {
14
+ login(...args: string[]) {
15
15
  return this.sync("login", ...args);
16
16
  }
17
17
 
18
- push(...args) {
18
+ push(...args: string[]) {
19
19
  return this.run("push", ...args);
20
20
  }
21
21
 
22
- async getToken(username, password) {
22
+ async getToken(username: string, password: string) {
23
23
  const {
24
24
  data: { token }
25
25
  } = await axios({
@@ -38,7 +38,7 @@ class DockerCli extends Cli {
38
38
  return token;
39
39
  }
40
40
 
41
- async getTags({ token, repository }) {
41
+ async getTags({ token, repository }: { token: string; repository: string }) {
42
42
  const { data } = await axios({
43
43
  method: "GET",
44
44
  url: `https://hub.docker.com/v2/repositories/${repository}/tags/?page=1&page_size=500`,
@@ -51,7 +51,7 @@ class DockerCli extends Cli {
51
51
  return data.results;
52
52
  }
53
53
 
54
- async deleteTag(tag, { token, repository }) {
54
+ async deleteTag(tag: string, { token, repository }: { token: string; repository: string }) {
55
55
  await axios({
56
56
  method: "DELETE",
57
57
  url: `https://hub.docker.com/v2/repositories/${repository}/tags/${tag}/`,