@cmflow/cli 3.4.0-alpha.1 → 3.4.0-alpha.5

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 (209) hide show
  1. package/README.md +110 -294
  2. package/dist/bin/cm.mjs +9985 -1348
  3. package/dist/bin/cmrelease.mjs +3875 -1193
  4. package/dist/{cli-truncate-CXNquMRK.mjs → cli-truncate-Bi2MjGwF.mjs} +177 -6
  5. package/dist/cli-truncate-DMcpM5Q7.mjs +2 -0
  6. package/dist/cli-truncate-DMcpM5Q7.mjs.map +1 -0
  7. package/dist/{cli-truncate-BmHD4ngn.mjs → cli-truncate-DsW0mgI_.mjs} +177 -6
  8. package/dist/{common-CwPbT3So.mjs → common-BdfXquG0.mjs} +31 -36
  9. package/dist/common-BdfXquG0.mjs.map +1 -0
  10. package/dist/compile-packages-BB08_q2B.mjs +2 -0
  11. package/dist/compile-packages-BB08_q2B.mjs.map +1 -0
  12. package/dist/docker-Cc30aRzl.mjs +34 -0
  13. package/dist/docker-Cc30aRzl.mjs.map +1 -0
  14. package/dist/docker-clean-tags-EvFdWykP.mjs +2 -0
  15. package/dist/docker-clean-tags-EvFdWykP.mjs.map +1 -0
  16. package/dist/docker-publish-CG0aN9se.mjs +2 -0
  17. package/dist/docker-publish-CG0aN9se.mjs.map +1 -0
  18. package/dist/find-packages-611B-66T.mjs +42 -0
  19. package/dist/find-packages-611B-66T.mjs.map +1 -0
  20. package/dist/get-config-8ivgd1KC.mjs +9 -0
  21. package/dist/get-config-8ivgd1KC.mjs.map +1 -0
  22. package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -1
  23. package/dist/{get-east-asian-width-eFfEkHwo.mjs → get-east-asian-width-wiVWCFXf.mjs} +4 -4
  24. package/dist/log-update-CLbF3iV6.mjs +6 -0
  25. package/dist/log-update-CLbF3iV6.mjs.map +1 -0
  26. package/dist/{log-update-B2GqeeDd.mjs → log-update-CTXRtajW.mjs} +185 -14
  27. package/dist/{log-update-BldA9lkm.mjs → log-update-Dy1vPMGY.mjs} +185 -14
  28. package/dist/npm-VM_GgazT.mjs +2 -0
  29. package/dist/npm-VM_GgazT.mjs.map +1 -0
  30. package/dist/{semver-D8gwMSFO.mjs → semver-DFjVbN1S.mjs} +2 -2
  31. package/dist/semver-DFjVbN1S.mjs.map +1 -0
  32. package/dist/source-CwLcYLzI.mjs +7 -0
  33. package/dist/source-CwLcYLzI.mjs.map +1 -0
  34. package/dist/{wrap-ansi-DsMb4WnZ.mjs → wrap-ansi-9ugahFCy.mjs} +2 -2
  35. package/dist/wrap-ansi-9ugahFCy.mjs.map +1 -0
  36. package/dist/{wrap-ansi-CWIezXNl.mjs → wrap-ansi-BRr0GA6g.mjs} +5 -5
  37. package/dist/{wrap-ansi-T0rz0Urp.mjs → wrap-ansi-Cupoo4Yg.mjs} +5 -5
  38. package/dist/wrap-ansi-dwgEjNWf.mjs +2 -0
  39. package/dist/write-package-cxki9d3K.mjs +8 -0
  40. package/dist/write-package-cxki9d3K.mjs.map +1 -0
  41. package/dist/write-packages-CxCAl_AG.mjs +10 -0
  42. package/dist/write-packages-CxCAl_AG.mjs.map +1 -0
  43. package/package.json +9 -41
  44. package/.oxfmtrc.json +0 -11
  45. package/.yarn/install-state.gz +0 -0
  46. package/.yarn/releases/yarn-4.18.0.cjs +0 -1000
  47. package/.yarnrc.yml +0 -10
  48. package/bin/cm-checkfeatures.ts +0 -10
  49. package/bin/cm-clean.ts +0 -10
  50. package/bin/cm-config.ts +0 -10
  51. package/bin/cm-deploy.ts +0 -10
  52. package/bin/cm-expedit.ts +0 -19
  53. package/bin/cm-fetch.ts +0 -10
  54. package/bin/cm-finish.ts +0 -10
  55. package/bin/cm-jira-releases.ts +0 -10
  56. package/bin/cm-merge.ts +0 -10
  57. package/bin/cm-publish.ts +0 -10
  58. package/bin/cm-pull.ts +0 -8
  59. package/bin/cm-push.ts +0 -10
  60. package/bin/cm-rebase.ts +0 -10
  61. package/bin/cm-release.ts +0 -5
  62. package/bin/cm-republish.ts +0 -10
  63. package/bin/cm-start.ts +0 -10
  64. package/bin/cm.ts +0 -40
  65. package/dist/cli-truncate-DbOyuy2e.mjs +0 -2
  66. package/dist/cli-truncate-DbOyuy2e.mjs.map +0 -1
  67. package/dist/common-CwPbT3So.mjs.map +0 -1
  68. package/dist/docker-clean-tags-Cd-E8IqJ.mjs +0 -2
  69. package/dist/docker-clean-tags-Cd-E8IqJ.mjs.map +0 -1
  70. package/dist/docker-publish-B0E0qYYB.mjs +0 -2
  71. package/dist/docker-publish-B0E0qYYB.mjs.map +0 -1
  72. package/dist/get-config-DoOyLztI.mjs +0 -41
  73. package/dist/get-config-DoOyLztI.mjs.map +0 -1
  74. package/dist/log-update-By8Z-mak.mjs +0 -6
  75. package/dist/log-update-By8Z-mak.mjs.map +0 -1
  76. package/dist/semver-D8gwMSFO.mjs.map +0 -1
  77. package/dist/src/index.mjs +0 -18
  78. package/dist/src/index.mjs.map +0 -1
  79. package/dist/src/semantic/core/analyze-commits.mjs +0 -2
  80. package/dist/src/semantic/core/analyze-commits.mjs.map +0 -1
  81. package/dist/src/semantic/core/conditional.mjs +0 -2
  82. package/dist/src/semantic/core/conditional.mjs.map +0 -1
  83. package/dist/src/semantic/core/exit.mjs +0 -2
  84. package/dist/src/semantic/core/exit.mjs.map +0 -1
  85. package/dist/src/semantic/core/prepare/bump-version.mjs +0 -48
  86. package/dist/src/semantic/core/prepare/bump-version.mjs.map +0 -1
  87. package/dist/src/semantic/core/prepare/commit.mjs +0 -2
  88. package/dist/src/semantic/core/prepare/commit.mjs.map +0 -1
  89. package/dist/src/semantic/core/prepare/release-info.mjs +0 -2
  90. package/dist/src/semantic/core/prepare/release-info.mjs.map +0 -1
  91. package/dist/src/semantic/core/run.mjs +0 -2
  92. package/dist/src/semantic/core/run.mjs.map +0 -1
  93. package/dist/src/semantic/core/sync-repository.mjs +0 -2
  94. package/dist/src/semantic/core/sync-repository.mjs.map +0 -1
  95. package/dist/src/semantic/core/verify-conditions.mjs +0 -2
  96. package/dist/src/semantic/core/verify-conditions.mjs.map +0 -1
  97. package/dist/src/semantic/core/verify-release.mjs +0 -2
  98. package/dist/src/semantic/core/verify-release.mjs.map +0 -1
  99. package/dist/src/semantic/docker/publish.mjs +0 -2
  100. package/dist/src/semantic/docker/publish.mjs.map +0 -1
  101. package/dist/src/semantic/docker/success.mjs +0 -2
  102. package/dist/src/semantic/docker/success.mjs.map +0 -1
  103. package/dist/strip-ansi-Aeu5cmZe.mjs +0 -174
  104. package/dist/strip-ansi-Cl0pRo-s.mjs +0 -2
  105. package/dist/strip-ansi-Cl0pRo-s.mjs.map +0 -1
  106. package/dist/wrap-ansi-BeIjar2W.mjs +0 -2
  107. package/dist/wrap-ansi-DsMb4WnZ.mjs.map +0 -1
  108. package/mise.toml +0 -2
  109. package/oxlint.json +0 -25
  110. package/release.config.mjs +0 -39
  111. package/src/commands/checkfeatures.ts +0 -39
  112. package/src/commands/clean.ts +0 -36
  113. package/src/commands/config.ts +0 -31
  114. package/src/commands/deploy.ts +0 -39
  115. package/src/commands/fetch.ts +0 -30
  116. package/src/commands/finish.ts +0 -50
  117. package/src/commands/index.ts +0 -13
  118. package/src/commands/jira-releases.ts +0 -97
  119. package/src/commands/merge.ts +0 -58
  120. package/src/commands/prompts/branches.ts +0 -46
  121. package/src/commands/pull.ts +0 -44
  122. package/src/commands/push.ts +0 -48
  123. package/src/commands/rebase.ts +0 -56
  124. package/src/commands/release.ts +0 -21
  125. package/src/commands/republish.ts +0 -34
  126. package/src/commands/start.ts +0 -123
  127. package/src/commands/tasks/merge-branch.ts +0 -80
  128. package/src/commands/tasks/push-branch.ts +0 -19
  129. package/src/commands/tasks/rebase-all-branches.ts +0 -37
  130. package/src/commands/tasks/refresh-repository.ts +0 -38
  131. package/src/commands/tasks/run-test.ts +0 -28
  132. package/src/commands/tasks/update-branch.ts +0 -49
  133. package/src/commands/tasks/update-dependencies.ts +0 -43
  134. package/src/commands/utils/check-install.ts +0 -31
  135. package/src/common/back/directus/directus-flow.test.ts +0 -63
  136. package/src/common/back/directus/directus-flow.ts +0 -48
  137. package/src/common/back/http/http-proxy.ts +0 -21
  138. package/src/common/back/http/http-request.spec.ts +0 -50
  139. package/src/common/back/http/http-request.ts +0 -74
  140. package/src/common/back/jira/get-sorted-releases.ts +0 -40
  141. package/src/common/back/jira/interfaces/JiraIIssue.d.ts +0 -100
  142. package/src/common/back/jira/jira-releases.ts +0 -47
  143. package/src/common/back/jira/jira-request.spec.ts +0 -59
  144. package/src/common/back/jira/jira-request.ts +0 -29
  145. package/src/common/back/jira/jira-search.spec.ts +0 -44
  146. package/src/common/back/jira/jira-search.ts +0 -17
  147. package/src/common/cli/bun.test.ts +0 -58
  148. package/src/common/cli/bun.ts +0 -33
  149. package/src/common/cli/cli.ts +0 -127
  150. package/src/common/cli/docker.test.ts +0 -141
  151. package/src/common/cli/docker.ts +0 -66
  152. package/src/common/cli/git.test.ts +0 -215
  153. package/src/common/cli/git.ts +0 -121
  154. package/src/common/cli/lerna.test.ts +0 -58
  155. package/src/common/cli/lerna.ts +0 -25
  156. package/src/common/cli/npm.test.ts +0 -58
  157. package/src/common/cli/npm.ts +0 -33
  158. package/src/common/cli/pnpm.test.ts +0 -58
  159. package/src/common/cli/pnpm.ts +0 -34
  160. package/src/common/cli/yarn.test.ts +0 -58
  161. package/src/common/cli/yarn.ts +0 -33
  162. package/src/common/configure-git-workspace.ts +0 -39
  163. package/src/common/get-config.ts +0 -159
  164. package/src/common/get-package-json.ts +0 -15
  165. package/src/common/get-package-manager.ts +0 -13
  166. package/src/common/get-release-config.ts +0 -9
  167. package/src/common/index.ts +0 -14
  168. package/src/common/run-command.test.ts +0 -66
  169. package/src/common/run-command.ts +0 -67
  170. package/src/common/types.ts +0 -26
  171. package/src/common/vendor.d.ts +0 -4
  172. package/src/index.ts +0 -14
  173. package/src/semantic/core/analyze-commits.ts +0 -21
  174. package/src/semantic/core/conditional.ts +0 -62
  175. package/src/semantic/core/exit.ts +0 -15
  176. package/src/semantic/core/prepare/bump-version.ts +0 -41
  177. package/src/semantic/core/prepare/commit.ts +0 -30
  178. package/src/semantic/core/prepare/release-info.ts +0 -6
  179. package/src/semantic/core/run.ts +0 -23
  180. package/src/semantic/core/sync-repository.ts +0 -55
  181. package/src/semantic/core/verify-conditions.ts +0 -41
  182. package/src/semantic/core/verify-release.ts +0 -10
  183. package/src/semantic/define-config.ts +0 -42
  184. package/src/semantic/docker/publish.ts +0 -6
  185. package/src/semantic/docker/success.ts +0 -10
  186. package/src/semantic/utils/__mock__/test1/package.json +0 -7
  187. package/src/semantic/utils/__mock__/test1/packages/a/package.json +0 -9
  188. package/src/semantic/utils/__mock__/test1/packages/b/package.json +0 -7
  189. package/src/semantic/utils/__mock__/test2/package.json +0 -4
  190. package/src/semantic/utils/__mock__/test2/packages/a/package.json +0 -7
  191. package/src/semantic/utils/__mock__/test2/packages/b/package.json +0 -5
  192. package/src/semantic/utils/bump-packages-version.test.ts +0 -76
  193. package/src/semantic/utils/bump-packages-version.ts +0 -53
  194. package/src/semantic/utils/calculate-snapshot-version.test.ts +0 -69
  195. package/src/semantic/utils/calculate-snapshot-version.ts +0 -17
  196. package/src/semantic/utils/display-package-info.ts +0 -12
  197. package/src/semantic/utils/display-release-info.ts +0 -13
  198. package/src/semantic/utils/docker-clean-tags.test.ts +0 -62
  199. package/src/semantic/utils/docker-clean-tags.ts +0 -58
  200. package/src/semantic/utils/docker-publish.test.ts +0 -45
  201. package/src/semantic/utils/docker-publish.ts +0 -24
  202. package/src/semantic/utils/log-section.ts +0 -9
  203. package/src/semantic/utils/release-rules.ts +0 -15
  204. package/src/semantic/utils/transform-writer.ts +0 -101
  205. package/src/workflow/index.ts +0 -42
  206. package/tsconfig.build.json +0 -29
  207. package/tsconfig.json +0 -30
  208. package/tsdown.config.ts +0 -63
  209. package/vitest.config.mts +0 -9
@@ -1,80 +0,0 @@
1
- import { git } from "../../common/index.js";
2
-
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) {
19
- const {
20
- logger,
21
- config: { SCM_TOKEN, REPOSITORY_URL, ORIGIN }
22
- } = context;
23
-
24
- if (SCM_TOKEN) {
25
- const repository = REPOSITORY_URL.replace("https://", "");
26
-
27
- logger.info(`Configure remote repository ${repository}`);
28
- git.remote("remove", ORIGIN).sync();
29
- git.remote("add", ORIGIN, `https://${SCM_TOKEN}@${repository}`).sync();
30
- }
31
- }
32
-
33
- async function gitMep(context: MergeBranchContext) {
34
- const {
35
- logger,
36
- branch,
37
- config: { PRODUCTION_BRANCH, ORIGIN }
38
- } = context;
39
-
40
- logger.info(`Branch ${branch.name} is candidate to MEP`);
41
-
42
- git.reset("--hard");
43
- git.clean("-f", "-d").sync();
44
-
45
- logger.info("Checkout production branch");
46
-
47
- git.config("--replace-all", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*");
48
- git.fetch().sync();
49
- git.fetch("--tags").sync();
50
- git.checkout("-qf", PRODUCTION_BRANCH).sync();
51
-
52
- logger.info(`Current branch: ${PRODUCTION_BRANCH}`);
53
-
54
- const building = git.getLastCommitMsg();
55
- logger.info("Last commit message on production", building);
56
-
57
- logger.info(`Merge ${branch.name} into ${PRODUCTION_BRANCH} branch`);
58
- git.merge("--no-ff", "-m", `${branch.name}`, branch.name);
59
- logger.info(`${branch.name} merged into ${PRODUCTION_BRANCH} branch`);
60
-
61
- setGHToken(context);
62
-
63
- logger.info(`Push ${PRODUCTION_BRANCH} branch`);
64
- await git.push(ORIGIN, PRODUCTION_BRANCH);
65
- logger.info(`${PRODUCTION_BRANCH} branch pushed`);
66
-
67
- logger.info(`Remove ${ORIGIN}/${branch.name} branch`);
68
- await git.push(ORIGIN, ":" + branch.name);
69
- logger.info(`${ORIGIN}/${branch.name} branch correctly removed`);
70
- }
71
-
72
- export function mergeBranch(context: MergeBranchContext) {
73
- const { BRANCH_NAME, PRODUCTION_BRANCH } = context;
74
- return {
75
- title: `Merge ${BRANCH_NAME} into ${PRODUCTION_BRANCH}`,
76
- task: async () => {
77
- await gitMep(context);
78
- }
79
- };
80
- }
@@ -1,19 +0,0 @@
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,37 +0,0 @@
1
- import { git } from "../../common/cli/git.js";
2
-
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) {
12
- const { origin = "origin", upstream = true, noVerify = true } = context;
13
- return {
14
- title: "Rebase all branches",
15
- task: async () => {
16
- const remoteBranches = git
17
- .branches("-r")
18
- .filter((b) => !new RegExp(`${context.PRODUCTION_BRANCH}|${context.DEVELOP_BRANCH}`).test(b));
19
- for (const remoteBranch of remoteBranches) {
20
- const branch = remoteBranch.split("/")[1];
21
- try {
22
- await git.branch("-D", branch);
23
- } catch {}
24
- try {
25
- await git.checkout("--track", remoteBranch);
26
- await git.rebase(`${origin}/${context.PRODUCTION_BRANCH}`);
27
- await git.push(...([upstream ? "-u" : "", "-f", origin, branch, noVerify ? "--no-verify" : ""].filter(Boolean) as string[]));
28
- } catch {
29
- try {
30
- await git.rebase("--abort");
31
- await git.reset("--hard");
32
- } catch {}
33
- }
34
- }
35
- }
36
- };
37
- }
@@ -1,38 +0,0 @@
1
- import { Listr } from "listr2";
2
- import { catchError, EMPTY, type Observable } from "rxjs";
3
-
4
- import { git } from "../../common/index.js";
5
-
6
- function pipe(observable: Observable<string>, output: unknown[]) {
7
- observable.pipe(
8
- catchError((err) => {
9
- output.push(err);
10
- return EMPTY;
11
- })
12
- );
13
-
14
- observable.subscribe((result) => {
15
- output.push(result);
16
- });
17
-
18
- return observable;
19
- }
20
-
21
- interface RefreshRepositoryContext {
22
- output?: unknown[];
23
- }
24
-
25
- export function refreshRepository(context: RefreshRepositoryContext) {
26
- const { output = [] } = context;
27
-
28
- return {
29
- title: "Refresh local repository",
30
- task: () =>
31
- new Listr([
32
- {
33
- title: "Git fetch",
34
- task: () => pipe(git.fetch("--prune").toObservable(), output)
35
- }
36
- ])
37
- };
38
- }
@@ -1,28 +0,0 @@
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,49 +0,0 @@
1
- import chalk from "chalk";
2
- import { Listr } from "listr2";
3
-
4
- import { git } from "../../common/cli/git.js";
5
- import type { CmContext, ListrTask } from "../../common/types";
6
-
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) {
17
- const isBranchExists = git.branchExists(featureBranch, origin);
18
-
19
- if (isBranchExists && !force) {
20
- const result = git.checkBranchRemoteStatus(featureBranch);
21
-
22
- if (result) {
23
- throw new Error("Remote branch changed, check diff before continue");
24
- }
25
- }
26
- }
27
-
28
- export const updateBranch = (context: UpdateBranchContext): ListrTask => {
29
- const { origin, fromBranch, checkStatus = true, rebase = true } = context;
30
- return {
31
- title: "Rebase branch",
32
- task: () =>
33
- new Listr(
34
- [
35
- {
36
- title: "Check status",
37
- enabled: () => checkStatus,
38
- task: () => checkBranchRemoteStatus(context)
39
- },
40
- {
41
- title: `Rebase from ${origin}/${chalk.green(fromBranch)}`,
42
- enabled: () => rebase,
43
- task: () => git.rebase(`${origin}/${fromBranch}`).toObservable()
44
- }
45
- ],
46
- { concurrent: false }
47
- )
48
- };
49
- };
@@ -1,43 +0,0 @@
1
- import { Listr } from "listr2";
2
- import { catchError } from "rxjs";
3
-
4
- import { getPackageManager } from "../../common/index.js";
5
- import type { CmContext, ListrTask } from "../../common/types";
6
- import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
7
-
8
- export const updateDependencies = ({ config: { PACKAGE_MANAGER } }: CmContext): ListrTask => {
9
- const reinstall = shouldReinstall();
10
-
11
- return {
12
- title: "Install",
13
- enabled: () => reinstall,
14
- task: () =>
15
- new Listr(
16
- [
17
- {
18
- title: `Restore dependencies using ${PACKAGE_MANAGER.toUpperCase()}`,
19
- task: () =>
20
- getPackageManager(PACKAGE_MANAGER)
21
- .restore()
22
- .toObservable()
23
- .pipe(
24
- catchError((error) => {
25
- if (PACKAGE_MANAGER === "yarn") {
26
- if (error.stderr.startsWith("error Your lockfile needs to be updated")) {
27
- throw new Error("yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.");
28
- }
29
- }
30
-
31
- throw error;
32
- })
33
- )
34
- },
35
- {
36
- title: "Refresh metadata",
37
- task: () => refreshMetadata()
38
- }
39
- ],
40
- { concurrent: false }
41
- )
42
- };
43
- };
@@ -1,31 +0,0 @@
1
- import isEqual from "lodash/isEqual.js";
2
-
3
- import { getPackageJson, git } from "../../common/index.js";
4
-
5
- function getDeps() {
6
- const pkg = getPackageJson();
7
- return {
8
- dependencies: pkg.dependencies,
9
- devDependencies: pkg.devDependencies
10
- };
11
- }
12
-
13
- export function getHash() {
14
- return Buffer.from(JSON.stringify(getDeps())).toString("base64");
15
- }
16
-
17
- export function getDepsFromHash() {
18
- try {
19
- return JSON.parse(Buffer.from(git.config("--local", "npm.hash"), "base64").toString("utf8"));
20
- } catch {
21
- return "";
22
- }
23
- }
24
-
25
- export function shouldReinstall() {
26
- return !isEqual(getDeps(), getDepsFromHash());
27
- }
28
-
29
- export function refreshMetadata() {
30
- git.config("--local", "npm.hash", `${getHash()}`);
31
- }
@@ -1,63 +0,0 @@
1
- // @ts-nocheck
2
- // Use vi.hoisted to create mock references that are available to mock factories
3
- const httpRequestMock = vi.hoisted(() => vi.fn());
4
-
5
- // Mock get-config to provide DIRECTUS_* env values
6
- vi.mock("../../get-config.js", () => ({
7
- getConfig: () => ({
8
- DIRECTUS_URL: "https://directus.example.com",
9
- DIRECTUS_FLOW_ID: "flow-123",
10
- DIRECTUS_ACCESS_TOKEN: "token-abc"
11
- })
12
- }));
13
-
14
- // Spy/mock for httpRequest
15
- vi.mock("../http/http-request.js", () => ({
16
- httpRequest: httpRequestMock
17
- }));
18
-
19
- // Now import the SUT after mocks are in place
20
- import { triggerDirectusFlow } from "./directus-flow.js";
21
-
22
- describe("triggerDirectusFlow", () => {
23
- beforeEach(() => {
24
- httpRequestMock.mockReset();
25
- });
26
-
27
- it("should call httpRequest with the expected endpoint, headers and body", async () => {
28
- httpRequestMock.mockResolvedValue({ ok: true, data: { status: "queued" } });
29
-
30
- const projectId = "CMAB";
31
- const versions = ["2.3.0", "2.2.0"];
32
- const opts = { rejectUnauthorized: true };
33
-
34
- const result = await triggerDirectusFlow(projectId, versions, opts);
35
-
36
- expect(result).toEqual({ ok: true, data: { status: "queued" } });
37
-
38
- expect(httpRequestMock).toHaveBeenCalledTimes(1);
39
-
40
- const expectedEndpoint = "https://directus.example.com/flows/trigger/flow-123";
41
- const expectedBody = JSON.stringify({ projectId, versions });
42
-
43
- expect(httpRequestMock).toHaveBeenCalledWith(
44
- expectedEndpoint,
45
- expect.objectContaining({
46
- method: "post",
47
- callee: "DIRECTUS",
48
- rejectUnauthorized: true,
49
- headers: expect.objectContaining({
50
- Authorization: "Bearer token-abc",
51
- "Content-Type": "application/json"
52
- }),
53
- data: expectedBody
54
- })
55
- );
56
- });
57
-
58
- it("should propagate errors from httpRequest", async () => {
59
- httpRequestMock.mockRejectedValue(new Error("network error"));
60
-
61
- await expect(triggerDirectusFlow("CMAB", ["1.0.0"])).rejects.toThrow("network error");
62
- });
63
- });
@@ -1,48 +0,0 @@
1
- import axiosRetry from "axios-retry";
2
-
3
- import { getConfig } from "../../get-config.js";
4
- import { httpRequest } from "../http/http-request.js";
5
-
6
- /**
7
- * Trigger a Directus Flow
8
- *
9
- * @param {string} projectId - The project identifier to send to the flow
10
- * @param {string[]} versions - The versions list to send to the flow
11
- * @param {object} [opts] - Additional request options (e.g., rejectUnauthorized)
12
- * @returns {Promise<unknown>} The parsed JSON response
13
- */
14
- export async function triggerDirectusFlow(projectId: string, versions: string[], opts: Record<string, unknown> = {}) {
15
- const { DIRECTUS_URL, DIRECTUS_FLOW_ID, DIRECTUS_ACCESS_TOKEN } = getConfig();
16
-
17
- const endpoint = `${DIRECTUS_URL}/flows/trigger/${DIRECTUS_FLOW_ID}`;
18
-
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
- } = {
28
- method: "post",
29
- callee: "DIRECTUS",
30
- headers: {
31
- Authorization: `Bearer ${DIRECTUS_ACCESS_TOKEN}`,
32
- "Content-Type": "application/json"
33
- },
34
- data: {
35
- projectId,
36
- versions
37
- },
38
- retries: 3,
39
- retryDelay: axiosRetry.exponentialDelay,
40
- ...opts
41
- };
42
-
43
- if (options.data && options.headers?.["Content-Type"] === "application/json") {
44
- options.data = JSON.stringify(options.data);
45
- }
46
-
47
- return httpRequest(endpoint, options);
48
- }
@@ -1,21 +0,0 @@
1
- import { HttpsProxyAgent } from "https-proxy-agent";
2
-
3
- import { getConfig } from "../../get-config.js";
4
-
5
- const { HTTPS_PROXY } = getConfig();
6
-
7
- interface HttpProxyOptions {
8
- callee?: string;
9
- rejectUnauthorized?: boolean;
10
- [key: string]: unknown;
11
- }
12
-
13
- export const getHttpProxy = (opts: HttpProxyOptions) => {
14
- if (HTTPS_PROXY) {
15
- console.debug({
16
- message: `Using proxy agent for ${opts.callee} requests`,
17
- value: HTTPS_PROXY
18
- });
19
- return new HttpsProxyAgent(HTTPS_PROXY, opts);
20
- }
21
- };
@@ -1,50 +0,0 @@
1
- import axios from "axios";
2
- import axiosRetry from "axios-retry";
3
-
4
- import { getHttpProxy } from "./http-proxy.js";
5
- import { httpRequest } from "./http-request.js";
6
-
7
- vi.mock("axios");
8
- vi.mock("axios-retry");
9
- vi.mock("./http-proxy.js");
10
-
11
- describe("httpRequest", () => {
12
- let mockInstance: ReturnType<typeof vi.fn>;
13
-
14
- beforeEach(() => {
15
- vi.clearAllMocks();
16
- mockInstance = vi.fn();
17
- vi.mocked(axios.create).mockReturnValue(mockInstance as unknown as ReturnType<typeof axios.create>);
18
- });
19
-
20
- it("should create an agent in production with proxy", async () => {
21
- mockInstance.mockResolvedValue({
22
- status: 200,
23
- data: { data: "test" }
24
- });
25
-
26
- const result = await httpRequest("http://example.com/test-endpoint", {
27
- callee: "test"
28
- });
29
-
30
- expect(getHttpProxy).toHaveBeenCalledWith({
31
- rejectUnauthorized: undefined,
32
- callee: "test"
33
- });
34
- expect(axios.create).toHaveBeenCalled();
35
- expect(axiosRetry).toHaveBeenCalled();
36
- expect(result).toEqual({ data: "test" });
37
- });
38
-
39
- it("should throw an error if the response is not ok", async () => {
40
- const axiosError = Object.assign(new Error("Request failed"), {
41
- response: {
42
- status: 500,
43
- data: { error: "Internal server error" }
44
- }
45
- });
46
- mockInstance.mockRejectedValue(axiosError);
47
-
48
- await expect(httpRequest("http://example.com/test-endpoint", { callee: "test" })).rejects.toThrow("HTTP error! status: 500");
49
- });
50
- });
@@ -1,74 +0,0 @@
1
- import axios from "axios";
2
- import axiosRetry from "axios-retry";
3
-
4
- import { getHttpProxy } from "./http-proxy.js";
5
-
6
- /**
7
- * @typedef {Object} RetryOptions
8
- * @property {number} [retries=3] - Number of retry attempts
9
- * @property {number} [retryDelay=1000] - Delay between retries in ms
10
- * @property {boolean} [retryOnNetworkError=true] - Retry on network errors
11
- * @property {boolean} [retryOnIdempotentRequests=true] - Retry on 5xx for idempotent requests
12
- */
13
-
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
- }
25
-
26
- export async function httpRequest(endpoint: string, options: HttpRequestOptions = {}) {
27
- const { callee, headers, method = "get", params = {}, rejectUnauthorized, ...rest } = options;
28
- const httpsAgent = getHttpProxy({
29
- rejectUnauthorized,
30
- callee
31
- });
32
-
33
- const instance = axios.create();
34
-
35
- axiosRetry(instance, options as Parameters<typeof axiosRetry>[1]);
36
-
37
- try {
38
- const response = await instance({
39
- url: endpoint,
40
- method,
41
- params,
42
- headers: {
43
- ...headers,
44
- "Content-Type": "application/json"
45
- },
46
- httpsAgent,
47
- ...rest
48
- });
49
-
50
- console.info({
51
- message: `Successfully retrieved data from ${callee}`,
52
- url: endpoint,
53
- method: method.toUpperCase(),
54
- status: response.status
55
- });
56
-
57
- return response.data;
58
- } catch (error) {
59
- const axiosError = error as { response?: { status: number; data: unknown } };
60
- const status = axiosError.response?.status;
61
- const responseData = axiosError.response?.data;
62
-
63
- console.error({
64
- ...options,
65
- message: `Fail to retrieved data from ${callee}`,
66
- url: endpoint,
67
- method: method.toUpperCase(),
68
- status,
69
- response: responseData
70
- });
71
-
72
- throw new Error(`HTTP error! status: ${status}`);
73
- }
74
- }
@@ -1,40 +0,0 @@
1
- import semver from "semver";
2
-
3
- import { getJiraReleases } from "./jira-releases.js";
4
-
5
- /**
6
- * Returns all releases under the tag version for the given project and component.
7
- * @param projectId {string}
8
- * @param component {string}
9
- * @param tagVersion {string}
10
- */
11
- export async function getSortedReleases(projectId: string, component: string, tagVersion: string) {
12
- const releases = await getJiraReleases(projectId);
13
-
14
- const promises = releases
15
- .filter((release) => {
16
- release.version = release.name
17
- .replace(component + "-", "")
18
- .replace("version-", "")
19
- .replace("v", "");
20
- try {
21
- return semver.lte(release.version, tagVersion);
22
- } catch {
23
- return false;
24
- }
25
- })
26
- .sort((ra, rb) => {
27
- return semver.rcompare(ra.version!, rb.version!);
28
- });
29
-
30
- const [current, ...others] = await Promise.all(promises);
31
-
32
- return [
33
- current,
34
- ...others.filter((release) => {
35
- return !release?.released;
36
- })
37
- ]
38
- .filter(Boolean)
39
- .reverse();
40
- }