@cmflow/cli 3.2.1 → 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 (221) hide show
  1. package/{.prettierrc → .oxfmtrc.json} +2 -1
  2. package/.yarn/install-state.gz +0 -0
  3. package/.yarn/releases/yarn-4.18.0.cjs +1000 -0
  4. package/.yarnrc.yml +8 -1
  5. package/README.md +66 -72
  6. package/bin/cm-checkfeatures.ts +10 -0
  7. package/bin/cm-clean.ts +10 -0
  8. package/bin/cm-config.ts +10 -0
  9. package/bin/cm-deploy.ts +10 -0
  10. package/bin/cm-expedit.ts +19 -0
  11. package/bin/cm-fetch.ts +10 -0
  12. package/bin/cm-finish.ts +10 -0
  13. package/bin/cm-jira-releases.ts +10 -0
  14. package/bin/cm-merge.ts +10 -0
  15. package/bin/cm-publish.ts +10 -0
  16. package/bin/cm-pull.ts +8 -0
  17. package/bin/cm-push.ts +10 -0
  18. package/bin/cm-rebase.ts +10 -0
  19. package/bin/{cmrelease.js → cm-release.ts} +0 -0
  20. package/bin/cm-republish.ts +10 -0
  21. package/bin/cm-start.ts +10 -0
  22. package/bin/cm.ts +40 -0
  23. package/dist/bin/cm.mjs +74985 -0
  24. package/dist/bin/cmrelease.mjs +72397 -0
  25. package/dist/cli-truncate-BmHD4ngn.mjs +152 -0
  26. package/dist/cli-truncate-CXNquMRK.mjs +152 -0
  27. package/dist/cli-truncate-DbOyuy2e.mjs +2 -0
  28. package/dist/cli-truncate-DbOyuy2e.mjs.map +1 -0
  29. package/dist/common-CwPbT3So.mjs +66 -0
  30. package/dist/common-CwPbT3So.mjs.map +1 -0
  31. package/dist/docker-clean-tags-Cd-E8IqJ.mjs +2 -0
  32. package/dist/docker-clean-tags-Cd-E8IqJ.mjs.map +1 -0
  33. package/dist/docker-publish-B0E0qYYB.mjs +2 -0
  34. package/dist/docker-publish-B0E0qYYB.mjs.map +1 -0
  35. package/dist/get-config-DoOyLztI.mjs +41 -0
  36. package/dist/get-config-DoOyLztI.mjs.map +1 -0
  37. package/dist/get-east-asian-width-Tfn8qoqd.mjs +2 -0
  38. package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -0
  39. package/dist/get-east-asian-width-eFfEkHwo.mjs +682 -0
  40. package/dist/log-update-B2GqeeDd.mjs +497 -0
  41. package/dist/log-update-BldA9lkm.mjs +497 -0
  42. package/dist/log-update-By8Z-mak.mjs +6 -0
  43. package/dist/log-update-By8Z-mak.mjs.map +1 -0
  44. package/dist/rolldown-runtime-B4iAMlE-.mjs +35 -0
  45. package/dist/semver-D8gwMSFO.mjs +2 -0
  46. package/dist/semver-D8gwMSFO.mjs.map +1 -0
  47. package/dist/src/index.mjs +18 -0
  48. package/dist/src/index.mjs.map +1 -0
  49. package/dist/src/semantic/core/analyze-commits.mjs +2 -0
  50. package/dist/src/semantic/core/analyze-commits.mjs.map +1 -0
  51. package/dist/src/semantic/core/conditional.mjs +2 -0
  52. package/dist/src/semantic/core/conditional.mjs.map +1 -0
  53. package/dist/src/semantic/core/exit.mjs +2 -0
  54. package/dist/src/semantic/core/exit.mjs.map +1 -0
  55. package/dist/src/semantic/core/prepare/bump-version.mjs +48 -0
  56. package/dist/src/semantic/core/prepare/bump-version.mjs.map +1 -0
  57. package/dist/src/semantic/core/prepare/commit.mjs +2 -0
  58. package/dist/src/semantic/core/prepare/commit.mjs.map +1 -0
  59. package/dist/src/semantic/core/prepare/release-info.mjs +2 -0
  60. package/dist/src/semantic/core/prepare/release-info.mjs.map +1 -0
  61. package/dist/src/semantic/core/run.mjs +2 -0
  62. package/dist/src/semantic/core/run.mjs.map +1 -0
  63. package/dist/src/semantic/core/sync-repository.mjs +2 -0
  64. package/dist/src/semantic/core/sync-repository.mjs.map +1 -0
  65. package/dist/src/semantic/core/verify-conditions.mjs +2 -0
  66. package/dist/src/semantic/core/verify-conditions.mjs.map +1 -0
  67. package/dist/src/semantic/core/verify-release.mjs +2 -0
  68. package/dist/src/semantic/core/verify-release.mjs.map +1 -0
  69. package/dist/src/semantic/docker/publish.mjs +2 -0
  70. package/dist/src/semantic/docker/publish.mjs.map +1 -0
  71. package/dist/src/semantic/docker/success.mjs +2 -0
  72. package/dist/src/semantic/docker/success.mjs.map +1 -0
  73. package/dist/strip-ansi-Aeu5cmZe.mjs +174 -0
  74. package/dist/strip-ansi-Cl0pRo-s.mjs +2 -0
  75. package/dist/strip-ansi-Cl0pRo-s.mjs.map +1 -0
  76. package/dist/wrap-ansi-BeIjar2W.mjs +2 -0
  77. package/dist/wrap-ansi-CWIezXNl.mjs +330 -0
  78. package/dist/wrap-ansi-DsMb4WnZ.mjs +9 -0
  79. package/dist/wrap-ansi-DsMb4WnZ.mjs.map +1 -0
  80. package/dist/wrap-ansi-T0rz0Urp.mjs +330 -0
  81. package/mise.toml +2 -0
  82. package/oxlint.json +25 -0
  83. package/package.json +65 -62
  84. package/release.config.mjs +6 -6
  85. package/src/commands/checkfeatures.ts +39 -0
  86. package/src/commands/clean.ts +36 -0
  87. package/src/commands/config.ts +31 -0
  88. package/src/commands/deploy.ts +39 -0
  89. package/src/commands/fetch.ts +30 -0
  90. package/src/commands/finish.ts +50 -0
  91. package/src/commands/{index.js → index.ts} +3 -0
  92. package/src/commands/jira-releases.ts +97 -0
  93. package/src/commands/merge.ts +58 -0
  94. package/src/commands/prompts/{branches.js → branches.ts} +13 -5
  95. package/src/commands/pull.ts +44 -0
  96. package/src/commands/push.ts +48 -0
  97. package/src/commands/rebase.ts +56 -0
  98. package/src/commands/republish.ts +34 -0
  99. package/src/commands/start.ts +123 -0
  100. package/src/commands/tasks/{merge-branch.js → merge-branch.ts} +18 -3
  101. package/src/commands/tasks/push-branch.ts +19 -0
  102. package/src/commands/tasks/{rebase-all-branches.js → rebase-all-branches.ts} +10 -2
  103. package/src/commands/tasks/{refresh-repository.js → refresh-repository.ts} +8 -4
  104. package/src/commands/tasks/run-test.ts +28 -0
  105. package/src/commands/tasks/{update-branch.js → update-branch.ts} +15 -9
  106. package/src/commands/tasks/{update-dependencies.js → update-dependencies.ts} +4 -3
  107. package/src/common/back/directus/{directus-flow.test.js → directus-flow.test.ts} +1 -0
  108. package/src/common/back/directus/{directus-flow.js → directus-flow.ts} +10 -2
  109. package/src/common/back/http/{http-proxy.js → http-proxy.ts} +7 -1
  110. package/src/common/back/http/{http-request.spec.js → http-request.spec.ts} +8 -7
  111. package/src/common/back/http/{http-request.js → http-request.ts} +16 -19
  112. package/src/common/back/jira/{get-sorted-releases.js → get-sorted-releases.ts} +2 -2
  113. package/src/common/back/jira/interfaces/JiraIIssue.d.ts +3 -3
  114. package/src/common/back/jira/{jira-releases.js → jira-releases.ts} +14 -3
  115. package/src/common/back/jira/{jira-request.js → jira-request.ts} +9 -1
  116. package/src/common/back/jira/{jira-search.js → jira-search.ts} +2 -2
  117. package/src/common/cli/{bun.test.js → bun.test.ts} +17 -10
  118. package/src/common/cli/{bun.js → bun.ts} +4 -4
  119. package/src/common/cli/cli.ts +127 -0
  120. package/src/common/cli/{docker.test.js → docker.test.ts} +22 -14
  121. package/src/common/cli/{docker.js → docker.ts} +6 -6
  122. package/src/common/cli/{git.test.js → git.test.ts} +19 -11
  123. package/src/common/cli/{git.js → git.ts} +24 -24
  124. package/src/common/cli/{lerna.test.js → lerna.test.ts} +18 -11
  125. package/src/common/cli/{lerna.js → lerna.ts} +4 -4
  126. package/src/common/cli/{npm.test.js → npm.test.ts} +17 -10
  127. package/src/common/cli/{npm.js → npm.ts} +4 -4
  128. package/src/common/cli/{pnpm.test.js → pnpm.test.ts} +17 -10
  129. package/src/common/cli/{pnpm.js → pnpm.ts} +4 -4
  130. package/src/common/cli/{yarn.test.js → yarn.test.ts} +17 -12
  131. package/src/common/cli/{yarn.js → yarn.ts} +4 -4
  132. package/src/common/configure-git-workspace.ts +39 -0
  133. package/src/common/{get-config.js → get-config.ts} +3 -1
  134. package/src/common/{get-package-json.js → get-package-json.ts} +1 -0
  135. package/src/common/{get-package-manager.js → get-package-manager.ts} +1 -0
  136. package/src/common/{get-release-config.js → get-release-config.ts} +1 -0
  137. package/src/common/{index.js → index.ts} +1 -0
  138. package/src/common/{run-command.test.js → run-command.test.ts} +1 -0
  139. package/src/common/run-command.ts +67 -0
  140. package/src/common/types.ts +26 -0
  141. package/src/common/vendor.d.ts +4 -0
  142. package/src/{index.js → index.ts} +5 -1
  143. package/src/semantic/core/{analyze-commits.js → analyze-commits.ts} +7 -3
  144. package/src/semantic/core/{conditional.js → conditional.ts} +16 -9
  145. package/src/semantic/core/{exit.js → exit.ts} +3 -2
  146. package/src/semantic/core/prepare/{bump-version.js → bump-version.ts} +11 -8
  147. package/src/semantic/core/prepare/{commit.js → commit.ts} +3 -2
  148. package/src/semantic/core/prepare/release-info.ts +6 -0
  149. package/src/semantic/core/{run.js → run.ts} +3 -2
  150. package/src/semantic/core/sync-repository.ts +55 -0
  151. package/src/semantic/core/{verify-conditions.js → verify-conditions.ts} +4 -3
  152. package/src/semantic/core/{verify-release.js → verify-release.ts} +2 -1
  153. package/src/semantic/docker/publish.ts +6 -0
  154. package/src/semantic/docker/{success.js → success.ts} +2 -1
  155. package/src/semantic/utils/__mock__/test1/package.json +7 -1
  156. package/src/semantic/utils/__mock__/test1/packages/a/package.json +9 -1
  157. package/src/semantic/utils/__mock__/test1/packages/b/package.json +7 -1
  158. package/src/semantic/utils/{bump-packages-version.test.js → bump-packages-version.test.ts} +1 -0
  159. package/src/semantic/utils/{bump-packages-version.js → bump-packages-version.ts} +12 -11
  160. package/src/semantic/utils/{calculate-snapshot-version.test.js → calculate-snapshot-version.test.ts} +10 -8
  161. package/src/semantic/utils/calculate-snapshot-version.ts +17 -0
  162. package/src/semantic/utils/display-package-info.ts +12 -0
  163. package/src/semantic/utils/display-release-info.ts +13 -0
  164. package/src/semantic/utils/{docker-clean-tags.test.js → docker-clean-tags.test.ts} +1 -0
  165. package/src/semantic/utils/{docker-clean-tags.js → docker-clean-tags.ts} +11 -4
  166. package/src/semantic/utils/{docker-publish.test.js → docker-publish.test.ts} +1 -0
  167. package/src/semantic/utils/{docker-publish.js → docker-publish.ts} +4 -3
  168. package/src/semantic/utils/{log-section.js → log-section.ts} +5 -1
  169. package/src/semantic/utils/{transform-writer.js → transform-writer.ts} +37 -13
  170. package/tsconfig.build.json +29 -0
  171. package/tsconfig.json +8 -32
  172. package/tsdown.config.ts +63 -0
  173. package/vitest.config.mts +4 -5
  174. package/.prettierignore +0 -5
  175. package/.yarn/releases/yarn-4.7.0.cjs +0 -935
  176. package/bin/checkfeatures.sh +0 -5
  177. package/bin/cm-clean.js +0 -8
  178. package/bin/cm-config.js +0 -15
  179. package/bin/cm-deploy.js +0 -8
  180. package/bin/cm-fetch.js +0 -12
  181. package/bin/cm-finish.js +0 -14
  182. package/bin/cm-jira-releases.js +0 -16
  183. package/bin/cm-merge.js +0 -12
  184. package/bin/cm-publish.js +0 -15
  185. package/bin/cm-push.js +0 -15
  186. package/bin/cm-rebase.js +0 -15
  187. package/bin/cm-republish.js +0 -12
  188. package/bin/cm-start.js +0 -21
  189. package/bin/cm.js +0 -27
  190. package/bin/cmexpedit.sh +0 -9
  191. package/bin/cmpull.sh +0 -7
  192. package/eslint.config.mjs +0 -67
  193. package/src/commands/clean.js +0 -29
  194. package/src/commands/config.js +0 -23
  195. package/src/commands/deploy.js +0 -34
  196. package/src/commands/fetch.js +0 -18
  197. package/src/commands/finish.js +0 -43
  198. package/src/commands/jira-releases.js +0 -62
  199. package/src/commands/merge.js +0 -41
  200. package/src/commands/push.js +0 -23
  201. package/src/commands/rebase.js +0 -35
  202. package/src/commands/republish.js +0 -21
  203. package/src/commands/start.js +0 -109
  204. package/src/commands/tasks/push-branch.js +0 -10
  205. package/src/commands/tasks/run-test.js +0 -21
  206. package/src/common/cli/cli.js +0 -110
  207. package/src/common/configure-git-workspace.js +0 -26
  208. package/src/common/run-command.js +0 -64
  209. package/src/semantic/core/prepare/release-info.js +0 -5
  210. package/src/semantic/core/sync-repository.js +0 -52
  211. package/src/semantic/docker/publish.js +0 -5
  212. package/src/semantic/utils/calculate-snapshot-version.js +0 -15
  213. package/src/semantic/utils/display-package-info.js +0 -11
  214. package/src/semantic/utils/display-release-info.js +0 -12
  215. /package/src/commands/{release.js → release.ts} +0 -0
  216. /package/src/commands/utils/{check-install.js → check-install.ts} +0 -0
  217. /package/src/common/back/jira/{jira-request.spec.js → jira-request.spec.ts} +0 -0
  218. /package/src/common/back/jira/{jira-search.spec.js → jira-search.spec.ts} +0 -0
  219. /package/src/semantic/{define-config.js → define-config.ts} +0 -0
  220. /package/src/semantic/utils/{release-rules.js → release-rules.ts} +0 -0
  221. /package/src/workflow/{index.js → index.ts} +0 -0
@@ -1,6 +1,21 @@
1
1
  import { git } from "../../common/index.js";
2
2
 
3
- function setGHToken(context) {
3
+ interface MergeBranchConfig {
4
+ SCM_TOKEN?: string;
5
+ REPOSITORY_URL: string;
6
+ ORIGIN: string;
7
+ PRODUCTION_BRANCH: string;
8
+ }
9
+
10
+ interface MergeBranchContext {
11
+ logger: { info: (msg: string, ...args: unknown[]) => void };
12
+ branch: { name: string };
13
+ config: MergeBranchConfig;
14
+ BRANCH_NAME: string;
15
+ PRODUCTION_BRANCH: string;
16
+ }
17
+
18
+ function setGHToken(context: MergeBranchContext) {
4
19
  const {
5
20
  logger,
6
21
  config: { SCM_TOKEN, REPOSITORY_URL, ORIGIN }
@@ -15,7 +30,7 @@ function setGHToken(context) {
15
30
  }
16
31
  }
17
32
 
18
- async function gitMep(context) {
33
+ async function gitMep(context: MergeBranchContext) {
19
34
  const {
20
35
  logger,
21
36
  branch,
@@ -54,7 +69,7 @@ async function gitMep(context) {
54
69
  logger.info(`${ORIGIN}/${branch.name} branch correctly removed`);
55
70
  }
56
71
 
57
- export function mergeBranch(context) {
72
+ export function mergeBranch(context: MergeBranchContext) {
58
73
  const { BRANCH_NAME, PRODUCTION_BRANCH } = context;
59
74
  return {
60
75
  title: `Merge ${BRANCH_NAME} into ${PRODUCTION_BRANCH}`,
@@ -0,0 +1,19 @@
1
+ import { git } from "../../common/cli/git.js";
2
+
3
+ interface PushBranchContext {
4
+ origin?: string;
5
+ featureBranch: string;
6
+ upstream?: boolean;
7
+ noVerify?: boolean;
8
+ }
9
+
10
+ export function pushBranch({ origin = "origin", featureBranch, upstream = true, noVerify = true }: PushBranchContext) {
11
+ return {
12
+ title: `Push ${featureBranch}`,
13
+ task: () => {
14
+ return git
15
+ .push(...([upstream ? "-u" : "", "-f", origin, featureBranch, noVerify ? "--no-verify" : ""].filter(Boolean) as string[]))
16
+ .toObservable();
17
+ }
18
+ };
19
+ }
@@ -1,6 +1,14 @@
1
1
  import { git } from "../../common/cli/git.js";
2
2
 
3
- export function rebaseAllBranches(context) {
3
+ interface RebaseAllBranchesContext {
4
+ origin?: string;
5
+ upstream?: boolean;
6
+ noVerify?: boolean;
7
+ PRODUCTION_BRANCH: string;
8
+ DEVELOP_BRANCH: string;
9
+ }
10
+
11
+ export function rebaseAllBranches(context: RebaseAllBranchesContext) {
4
12
  const { origin = "origin", upstream = true, noVerify = true } = context;
5
13
  return {
6
14
  title: "Rebase all branches",
@@ -16,7 +24,7 @@ export function rebaseAllBranches(context) {
16
24
  try {
17
25
  await git.checkout("--track", remoteBranch);
18
26
  await git.rebase(`${origin}/${context.PRODUCTION_BRANCH}`);
19
- await git.push(...[upstream ? "-u" : "", "-f", origin, branch, noVerify ? "--no-verify" : ""].filter(Boolean));
27
+ await git.push(...([upstream ? "-u" : "", "-f", origin, branch, noVerify ? "--no-verify" : ""].filter(Boolean) as string[]));
20
28
  } catch {
21
29
  try {
22
30
  await git.rebase("--abort");
@@ -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,5 +1,5 @@
1
- import type { ADFDocument } from './ADFDocument.js';
2
- import type { JiraChangelog } from './JiraChangelogIssueResponse.js';
1
+ import type { ADFDocument } from "./ADFDocument.js";
2
+ import type { JiraChangelog } from "./JiraChangelogIssueResponse.js";
3
3
 
4
4
  export interface JiraStatus {
5
5
  id: string;
@@ -60,7 +60,7 @@ export interface CreateJiraFieldsIssue {
60
60
  };
61
61
  assignee?: Partial<JiraUser>; // Utilisateur assigné
62
62
  reporter?: Partial<JiraUser>; // Créateur de l'issue
63
- status?: Omit<JiraStatus, 'name'>;
63
+ status?: Omit<JiraStatus, "name">;
64
64
  components?: { name: string }[];
65
65
 
66
66
  [customFieldId: `customfield_${string}`]: unknown; // Autres champs personnalisés
@@ -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
+ }