@cmflow/cli 3.3.0 → 3.4.0-alpha.3

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 (165) hide show
  1. package/README.md +102 -298
  2. package/dist/bin/cm.mjs +83622 -0
  3. package/dist/bin/cmrelease.mjs +75079 -0
  4. package/dist/cli-truncate-Bi2MjGwF.mjs +323 -0
  5. package/dist/cli-truncate-DMcpM5Q7.mjs +2 -0
  6. package/dist/cli-truncate-DMcpM5Q7.mjs.map +1 -0
  7. package/dist/cli-truncate-DsW0mgI_.mjs +323 -0
  8. package/dist/common-BdfXquG0.mjs +61 -0
  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 +2 -0
  23. package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -0
  24. package/dist/get-east-asian-width-wiVWCFXf.mjs +682 -0
  25. package/dist/log-update-CLbF3iV6.mjs +6 -0
  26. package/dist/log-update-CLbF3iV6.mjs.map +1 -0
  27. package/dist/log-update-CTXRtajW.mjs +668 -0
  28. package/dist/log-update-Dy1vPMGY.mjs +668 -0
  29. package/dist/npm-VM_GgazT.mjs +2 -0
  30. package/dist/npm-VM_GgazT.mjs.map +1 -0
  31. package/dist/rolldown-runtime-B4iAMlE-.mjs +35 -0
  32. package/dist/semver-DFjVbN1S.mjs +2 -0
  33. package/dist/semver-DFjVbN1S.mjs.map +1 -0
  34. package/dist/source-CwLcYLzI.mjs +7 -0
  35. package/dist/source-CwLcYLzI.mjs.map +1 -0
  36. package/dist/wrap-ansi-9ugahFCy.mjs +9 -0
  37. package/dist/wrap-ansi-9ugahFCy.mjs.map +1 -0
  38. package/dist/wrap-ansi-BRr0GA6g.mjs +330 -0
  39. package/dist/wrap-ansi-Cupoo4Yg.mjs +330 -0
  40. package/dist/wrap-ansi-dwgEjNWf.mjs +2 -0
  41. package/dist/write-package-cxki9d3K.mjs +8 -0
  42. package/dist/write-package-cxki9d3K.mjs.map +1 -0
  43. package/dist/write-packages-CxCAl_AG.mjs +10 -0
  44. package/dist/write-packages-CxCAl_AG.mjs.map +1 -0
  45. package/package.json +40 -63
  46. package/tsdown.config.ts +54 -0
  47. package/.oxfmtrc.json +0 -11
  48. package/.yarn/install-state.gz +0 -0
  49. package/.yarn/releases/yarn-4.7.0.cjs +0 -935
  50. package/.yarnrc.yml +0 -3
  51. package/bin/checkfeatures.js +0 -13
  52. package/bin/cm-clean.js +0 -8
  53. package/bin/cm-config.js +0 -15
  54. package/bin/cm-deploy.js +0 -8
  55. package/bin/cm-expedit.js +0 -19
  56. package/bin/cm-fetch.js +0 -12
  57. package/bin/cm-finish.js +0 -14
  58. package/bin/cm-jira-releases.js +0 -16
  59. package/bin/cm-merge.js +0 -12
  60. package/bin/cm-publish.js +0 -15
  61. package/bin/cm-push.js +0 -15
  62. package/bin/cm-rebase.js +0 -15
  63. package/bin/cm-republish.js +0 -12
  64. package/bin/cm-start.js +0 -21
  65. package/bin/cm.js +0 -27
  66. package/bin/cmpull.js +0 -22
  67. package/bin/cmrelease.js +0 -5
  68. package/mise.toml +0 -2
  69. package/oxlint.json +0 -25
  70. package/release.config.mjs +0 -39
  71. package/src/commands/checkfeatures.js +0 -20
  72. package/src/commands/clean.js +0 -29
  73. package/src/commands/config.js +0 -23
  74. package/src/commands/deploy.js +0 -34
  75. package/src/commands/fetch.js +0 -18
  76. package/src/commands/finish.js +0 -43
  77. package/src/commands/index.js +0 -12
  78. package/src/commands/jira-releases.js +0 -62
  79. package/src/commands/merge.js +0 -41
  80. package/src/commands/prompts/branches.js +0 -38
  81. package/src/commands/pull.js +0 -30
  82. package/src/commands/push.js +0 -23
  83. package/src/commands/rebase.js +0 -35
  84. package/src/commands/release.js +0 -21
  85. package/src/commands/republish.js +0 -21
  86. package/src/commands/start.js +0 -109
  87. package/src/commands/tasks/merge-branch.js +0 -65
  88. package/src/commands/tasks/push-branch.js +0 -10
  89. package/src/commands/tasks/rebase-all-branches.js +0 -29
  90. package/src/commands/tasks/refresh-repository.js +0 -34
  91. package/src/commands/tasks/run-test.js +0 -21
  92. package/src/commands/tasks/update-branch.js +0 -43
  93. package/src/commands/tasks/update-dependencies.js +0 -42
  94. package/src/commands/utils/check-install.js +0 -31
  95. package/src/common/back/directus/directus-flow.js +0 -40
  96. package/src/common/back/directus/directus-flow.test.js +0 -62
  97. package/src/common/back/http/http-proxy.js +0 -15
  98. package/src/common/back/http/http-request.js +0 -77
  99. package/src/common/back/http/http-request.spec.js +0 -49
  100. package/src/common/back/jira/get-sorted-releases.js +0 -40
  101. package/src/common/back/jira/interfaces/JiraIIssue.d.ts +0 -100
  102. package/src/common/back/jira/jira-releases.js +0 -36
  103. package/src/common/back/jira/jira-request.js +0 -21
  104. package/src/common/back/jira/jira-request.spec.js +0 -59
  105. package/src/common/back/jira/jira-search.js +0 -17
  106. package/src/common/back/jira/jira-search.spec.js +0 -44
  107. package/src/common/cli/bun.js +0 -33
  108. package/src/common/cli/bun.test.js +0 -51
  109. package/src/common/cli/cli.js +0 -110
  110. package/src/common/cli/docker.js +0 -66
  111. package/src/common/cli/docker.test.js +0 -133
  112. package/src/common/cli/git.js +0 -121
  113. package/src/common/cli/git.test.js +0 -207
  114. package/src/common/cli/lerna.js +0 -25
  115. package/src/common/cli/lerna.test.js +0 -51
  116. package/src/common/cli/npm.js +0 -33
  117. package/src/common/cli/npm.test.js +0 -51
  118. package/src/common/cli/pnpm.js +0 -34
  119. package/src/common/cli/pnpm.test.js +0 -51
  120. package/src/common/cli/yarn.js +0 -33
  121. package/src/common/cli/yarn.test.js +0 -53
  122. package/src/common/configure-git-workspace.js +0 -26
  123. package/src/common/get-config.js +0 -157
  124. package/src/common/get-package-json.js +0 -14
  125. package/src/common/get-package-manager.js +0 -12
  126. package/src/common/get-release-config.js +0 -8
  127. package/src/common/index.js +0 -13
  128. package/src/common/run-command.js +0 -64
  129. package/src/common/run-command.test.js +0 -65
  130. package/src/index.js +0 -10
  131. package/src/semantic/core/analyze-commits.js +0 -17
  132. package/src/semantic/core/conditional.js +0 -55
  133. package/src/semantic/core/exit.js +0 -14
  134. package/src/semantic/core/prepare/bump-version.js +0 -38
  135. package/src/semantic/core/prepare/commit.js +0 -29
  136. package/src/semantic/core/prepare/release-info.js +0 -5
  137. package/src/semantic/core/run.js +0 -22
  138. package/src/semantic/core/sync-repository.js +0 -52
  139. package/src/semantic/core/verify-conditions.js +0 -40
  140. package/src/semantic/core/verify-release.js +0 -9
  141. package/src/semantic/define-config.js +0 -42
  142. package/src/semantic/docker/publish.js +0 -5
  143. package/src/semantic/docker/success.js +0 -9
  144. package/src/semantic/utils/__mock__/test1/package.json +0 -7
  145. package/src/semantic/utils/__mock__/test1/packages/a/package.json +0 -9
  146. package/src/semantic/utils/__mock__/test1/packages/b/package.json +0 -7
  147. package/src/semantic/utils/__mock__/test2/package.json +0 -4
  148. package/src/semantic/utils/__mock__/test2/packages/a/package.json +0 -7
  149. package/src/semantic/utils/__mock__/test2/packages/b/package.json +0 -5
  150. package/src/semantic/utils/bump-packages-version.js +0 -52
  151. package/src/semantic/utils/bump-packages-version.test.js +0 -75
  152. package/src/semantic/utils/calculate-snapshot-version.js +0 -15
  153. package/src/semantic/utils/calculate-snapshot-version.test.js +0 -67
  154. package/src/semantic/utils/display-package-info.js +0 -11
  155. package/src/semantic/utils/display-release-info.js +0 -12
  156. package/src/semantic/utils/docker-clean-tags.js +0 -51
  157. package/src/semantic/utils/docker-clean-tags.test.js +0 -61
  158. package/src/semantic/utils/docker-publish.js +0 -23
  159. package/src/semantic/utils/docker-publish.test.js +0 -44
  160. package/src/semantic/utils/log-section.js +0 -5
  161. package/src/semantic/utils/release-rules.js +0 -15
  162. package/src/semantic/utils/transform-writer.js +0 -77
  163. package/src/workflow/index.js +0 -42
  164. package/tsconfig.json +0 -37
  165. package/vitest.config.mts +0 -10
@@ -1,38 +0,0 @@
1
- import inquirer from "inquirer";
2
-
3
- import { git } from "../../common/index.js";
4
-
5
- function toRemote(branch, origin) {
6
- branch = branch.replace(`${origin}/`);
7
- return `${origin}/${branch}`;
8
- }
9
-
10
- export function branches({ fromBranch, origin, PRODUCTION_BRANCH, DEVELOP_BRANCH, message = "Start your branch from:" }) {
11
- const currentBranch = git.getBranchName();
12
- const originDevelop = `${origin}/${DEVELOP_BRANCH}`;
13
- const originProduction = `${origin}/${PRODUCTION_BRANCH}`;
14
-
15
- let startFromBranches = [originProduction];
16
-
17
- if (startFromBranches.indexOf(toRemote(currentBranch, origin)) === -1 && git.branchExists(currentBranch, origin)) {
18
- startFromBranches = startFromBranches.concat(toRemote(currentBranch, origin));
19
- }
20
-
21
- const remoteBranches = git
22
- .branchesInfos("-r")
23
- .map((info) => info.branch)
24
- .filter((name) => !startFromBranches.includes(name) && ![originDevelop, originProduction].includes(name));
25
-
26
- if (remoteBranches.length) {
27
- startFromBranches = startFromBranches.concat(new inquirer.Separator(), remoteBranches);
28
- }
29
-
30
- return {
31
- type: "list",
32
- name: "fromBranch",
33
- message,
34
- default: startFromBranches.indexOf(fromBranch || originProduction),
35
- choices: startFromBranches,
36
- when: !fromBranch || currentBranch !== DEVELOP_BRANCH
37
- };
38
- }
@@ -1,30 +0,0 @@
1
- import { git } from "../common/index.js";
2
-
3
- export class Pull {
4
- mapContext(options, context) {
5
- return { ...context, targetBranch: options.branch };
6
- }
7
-
8
- getTasks(context) {
9
- const { targetBranch } = context;
10
-
11
- return [
12
- {
13
- title: "Git fetch",
14
- task: () => git.fetch("--all", "--prune", "--tags")
15
- },
16
- {
17
- title: `Delete local branch ${targetBranch}`,
18
- task: () => git.branch("-D", targetBranch).catch(() => {})
19
- },
20
- {
21
- title: `Checkout origin/${targetBranch}`,
22
- task: () => git.checkout(`origin/${targetBranch}`, "--track")
23
- }
24
- ];
25
- }
26
-
27
- success(context) {
28
- console.log(`BRANCH ${context.targetBranch} RETRIEVE DONE`);
29
- }
30
- }
@@ -1,23 +0,0 @@
1
- import chalk from "chalk";
2
- import figures from "figures";
3
-
4
- import { Rebase } from "./rebase.js";
5
- import { pushBranch } from "./tasks/push-branch.js";
6
-
7
- export class Push extends Rebase {
8
- mapContext(commander, context) {
9
- return {
10
- ...super.mapContext(commander, context),
11
- force: !!commander.force,
12
- checkStatus: true
13
- };
14
- }
15
-
16
- getTasks(context) {
17
- return [...super.getTasks(context), pushBranch(context)];
18
- }
19
-
20
- success(context) {
21
- console.log(chalk.green(figures.tick), "Branch", chalk.green(context.featureBranch), "rebased and pushed.");
22
- }
23
- }
@@ -1,35 +0,0 @@
1
- import chalk from "chalk";
2
- import figures from "figures";
3
-
4
- import { git } from "../common/cli/git.js";
5
- import { Fetch } from "./fetch.js";
6
- import { runTest } from "./tasks/run-test.js";
7
- import { updateBranch } from "./tasks/update-branch.js";
8
- import { updateDependencies } from "./tasks/update-dependencies.js";
9
-
10
- export class Rebase extends Fetch {
11
- mapContext(commander, context) {
12
- return {
13
- ...context,
14
- origin: context.ORIGIN,
15
- featureBranch: git.getBranchName(),
16
- fromBranch: context.PRODUCTION_BRANCH,
17
- checkStatus: commander.force === undefined ? true : !!commander.force,
18
- rebase: true,
19
- skipTest: !commander.cucumber && !commander.unitTest,
20
- skipUnit: !commander.unitTest,
21
- skipE2E: context.HAS_E2E ? !commander.cucumber : true
22
- };
23
- }
24
-
25
- getTasks(context) {
26
- return [...super.getTasks(context), updateBranch(context), updateDependencies(context), ...runTest(context)];
27
- }
28
-
29
- success(context) {
30
- console.log(
31
- chalk.green(figures.tick),
32
- `Branch ${chalk.green(context.featureBranch)} rebased from ${chalk.green(context.fromBranch)} HEAD`
33
- );
34
- }
35
- }
@@ -1,21 +0,0 @@
1
- import semantic_release from "semantic-release";
2
-
3
- delete process.env.CIRCLE_PR_NUMBER;
4
- delete process.env.CIRCLE_PULL_REQUEST;
5
- delete process.env.CI_PULL_REQUEST;
6
-
7
- export function release(options = {}) {
8
- semantic_release({
9
- dryRun: process.argv.includes("--dry-run"),
10
- ci: false,
11
- noCi: true,
12
- ...options
13
- })
14
- .then(() => {
15
- process.exitCode = 0;
16
- })
17
- .catch((err) => {
18
- console.log("Error while releasing", err);
19
- process.exitCode = 1;
20
- });
21
- }
@@ -1,21 +0,0 @@
1
- import chalk from "chalk";
2
- import figures from "figures";
3
-
4
- import { Fetch } from "./fetch.js";
5
- import { rebaseAllBranches } from "./tasks/rebase-all-branches.js";
6
-
7
- export class Republish extends Fetch {
8
- mapContext(commander, context) {
9
- return {
10
- ...super.mapContext(commander, context)
11
- };
12
- }
13
-
14
- getTasks(context) {
15
- return [...super.getTasks(context), rebaseAllBranches(context)];
16
- }
17
-
18
- success() {
19
- console.log(chalk.green(figures.tick), "All branches rebased and pushed.");
20
- }
21
- }
@@ -1,109 +0,0 @@
1
- import chalk from "chalk";
2
- import figures from "figures";
3
-
4
- import { git } from "../common/cli/git.js";
5
- import { WORKFLOW_CONFIGURATION } from "../workflow/index.js";
6
- import { Fetch } from "./fetch.js";
7
- import { branches } from "./prompts/branches.js";
8
- import { updateDependencies } from "./tasks/update-dependencies.js";
9
-
10
- function sanitize(name) {
11
- return name
12
- .replace(/[/\\_|. ]/gi, "-")
13
- .split("-")
14
- .filter(Boolean)
15
- .join("-");
16
- }
17
-
18
- export class Start extends Fetch {
19
- mapContext(options, context) {
20
- options.branchName = options.branchName || "";
21
- const type = WORKFLOW_CONFIGURATION.map(({ type }) => type).find((t) => options.branchName.startsWith(`${t}-`));
22
-
23
- if (!options.branchName && options.jiraId) {
24
- options.branchName = options.jiraId;
25
- }
26
-
27
- if (options.branchName.startsWith("CMAB-")) {
28
- const [, key, ...rest] = options.branchName.split("-");
29
- options.jiraId = `CMAB-${key}`;
30
- options.branchName = rest.join("-");
31
- }
32
-
33
- return {
34
- ...context,
35
- origin: context.ORIGIN,
36
- jiraId: options.jiraId,
37
- branchName: options.branchName,
38
- type
39
- };
40
- }
41
-
42
- prompt(context) {
43
- return [
44
- {
45
- type: "input",
46
- name: "jiraId",
47
- message: "What is the Jira ID ? (leave blank to skip)",
48
- default: context.jiraId,
49
- when: !context.jiraId
50
- },
51
- {
52
- type: "list",
53
- name: "type",
54
- message: "Choose the type of your branch:",
55
- choices: ["fix", "feat", "chore", "docs", "tech"],
56
- default: context.type,
57
- when: !context.type && !context.jiraId
58
- },
59
- {
60
- type: "input",
61
- name: "branchName",
62
- message: "What is the branch name ?",
63
- validate(branch) {
64
- if (!branch.length) {
65
- return "Branch name is required";
66
- }
67
-
68
- if (git.branchExists(branch, context.origin)) {
69
- return `${branch} already exists`;
70
- }
71
-
72
- return true;
73
- },
74
-
75
- when: !context.branchName
76
- },
77
-
78
- branches(context)
79
- ];
80
- }
81
-
82
- getTasks(context) {
83
- context.branchName = sanitize(context.branchName);
84
-
85
- context.featureBranch = context.jiraId
86
- ? `${context.jiraId}-${context.branchName}`
87
- : context.branchName.includes(context.type + "-")
88
- ? context.branchName
89
- : `${context.type}-${context.branchName}`;
90
-
91
- context.fromBranch = context.fromBranch || context.PRODUCTION_BRANCH;
92
-
93
- return [
94
- ...super.getTasks(context),
95
- {
96
- title: `Create branch from ${chalk.green(context.fromBranch)}`,
97
- task: () => git.checkout("--no-track", "-b", context.featureBranch, context.fromBranch).toObservable()
98
- },
99
- updateDependencies(context)
100
- ];
101
- }
102
-
103
- success(context) {
104
- console.log(
105
- chalk.green(figures.tick),
106
- `New branch ${chalk.green(context.featureBranch)} created from ${chalk.green(context.fromBranch)} HEAD`
107
- );
108
- }
109
- }
@@ -1,65 +0,0 @@
1
- import { git } from "../../common/index.js";
2
-
3
- function setGHToken(context) {
4
- const {
5
- logger,
6
- config: { SCM_TOKEN, REPOSITORY_URL, ORIGIN }
7
- } = context;
8
-
9
- if (SCM_TOKEN) {
10
- const repository = REPOSITORY_URL.replace("https://", "");
11
-
12
- logger.info(`Configure remote repository ${repository}`);
13
- git.remote("remove", ORIGIN).sync();
14
- git.remote("add", ORIGIN, `https://${SCM_TOKEN}@${repository}`).sync();
15
- }
16
- }
17
-
18
- async function gitMep(context) {
19
- const {
20
- logger,
21
- branch,
22
- config: { PRODUCTION_BRANCH, ORIGIN }
23
- } = context;
24
-
25
- logger.info(`Branch ${branch.name} is candidate to MEP`);
26
-
27
- git.reset("--hard");
28
- git.clean("-f", "-d").sync();
29
-
30
- logger.info("Checkout production branch");
31
-
32
- git.config("--replace-all", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*");
33
- git.fetch().sync();
34
- git.fetch("--tags").sync();
35
- git.checkout("-qf", PRODUCTION_BRANCH).sync();
36
-
37
- logger.info(`Current branch: ${PRODUCTION_BRANCH}`);
38
-
39
- const building = git.getLastCommitMsg();
40
- logger.info("Last commit message on production", building);
41
-
42
- logger.info(`Merge ${branch.name} into ${PRODUCTION_BRANCH} branch`);
43
- git.merge("--no-ff", "-m", `${branch.name}`, branch.name);
44
- logger.info(`${branch.name} merged into ${PRODUCTION_BRANCH} branch`);
45
-
46
- setGHToken(context);
47
-
48
- logger.info(`Push ${PRODUCTION_BRANCH} branch`);
49
- await git.push(ORIGIN, PRODUCTION_BRANCH);
50
- logger.info(`${PRODUCTION_BRANCH} branch pushed`);
51
-
52
- logger.info(`Remove ${ORIGIN}/${branch.name} branch`);
53
- await git.push(ORIGIN, ":" + branch.name);
54
- logger.info(`${ORIGIN}/${branch.name} branch correctly removed`);
55
- }
56
-
57
- export function mergeBranch(context) {
58
- const { BRANCH_NAME, PRODUCTION_BRANCH } = context;
59
- return {
60
- title: `Merge ${BRANCH_NAME} into ${PRODUCTION_BRANCH}`,
61
- task: async () => {
62
- await gitMep(context);
63
- }
64
- };
65
- }
@@ -1,10 +0,0 @@
1
- import { git } from "../../common/cli/git.js";
2
-
3
- export function pushBranch({ origin = "origin", featureBranch, upstream = true, noVerify = true }) {
4
- return {
5
- title: `Push ${featureBranch}`,
6
- task: () => {
7
- return git.push(...[upstream ? "-u" : "", "-f", origin, featureBranch, noVerify ? "--no-verify" : ""].filter(Boolean)).toObservable();
8
- }
9
- };
10
- }
@@ -1,29 +0,0 @@
1
- import { git } from "../../common/cli/git.js";
2
-
3
- export function rebaseAllBranches(context) {
4
- const { origin = "origin", upstream = true, noVerify = true } = context;
5
- return {
6
- title: "Rebase all branches",
7
- task: async () => {
8
- const remoteBranches = git
9
- .branches("-r")
10
- .filter((b) => !new RegExp(`${context.PRODUCTION_BRANCH}|${context.DEVELOP_BRANCH}`).test(b));
11
- for (const remoteBranch of remoteBranches) {
12
- const branch = remoteBranch.split("/")[1];
13
- try {
14
- await git.branch("-D", branch);
15
- } catch {}
16
- try {
17
- await git.checkout("--track", remoteBranch);
18
- await git.rebase(`${origin}/${context.PRODUCTION_BRANCH}`);
19
- await git.push(...[upstream ? "-u" : "", "-f", origin, branch, noVerify ? "--no-verify" : ""].filter(Boolean));
20
- } catch {
21
- try {
22
- await git.rebase("--abort");
23
- await git.reset("--hard");
24
- } catch {}
25
- }
26
- }
27
- }
28
- };
29
- }
@@ -1,34 +0,0 @@
1
- import Listr from "listr";
2
- import { catchError, EMPTY } from "rxjs";
3
-
4
- import { git } from "../../common/index.js";
5
-
6
- function pipe(observable, output) {
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
- export function refreshRepository(context) {
22
- const { output = [] } = context;
23
-
24
- return {
25
- title: "Refresh local repository",
26
- task: () =>
27
- new Listr([
28
- {
29
- title: "Git fetch",
30
- task: () => pipe(git.fetch("--prune").toObservable(), output)
31
- }
32
- ])
33
- };
34
- }
@@ -1,21 +0,0 @@
1
- import { getPackageManager, git } from "../../common/index.js";
2
-
3
- export const runTest = ({ E2E_CMD, PACKAGE_MANAGER, skipTest, skipUnit, skipE2E }) => {
4
- return [
5
- {
6
- title: "Unit test",
7
- skip: () => skipTest || skipUnit,
8
- task: () => getPackageManager(PACKAGE_MANAGER).run("test")
9
- },
10
- {
11
- title: "E2E test",
12
- skip: () => skipTest || skipE2E,
13
- task: () => getPackageManager(PACKAGE_MANAGER).run(E2E_CMD || "test_e2e")
14
- },
15
- {
16
- title: "Reset changes",
17
- skip: () => skipTest,
18
- task: () => git.reset("--hard") // reset files updated unit test
19
- }
20
- ];
21
- };
@@ -1,43 +0,0 @@
1
- import chalk from "chalk";
2
- import Listr from "listr";
3
-
4
- import { git } from "../../common/cli/git.js";
5
-
6
- async function checkBranchRemoteStatus({ featureBranch, origin, force }) {
7
- const isBranchExists = git.branchExists(featureBranch, origin);
8
-
9
- if (isBranchExists && !force) {
10
- const result = git.checkBranchRemoteStatus(featureBranch);
11
-
12
- if (result) {
13
- throw new Error("Remote branch changed, check diff before continue");
14
- }
15
- }
16
- }
17
-
18
- export const updateBranch = ({ origin, featureBranch, fromBranch, force, checkStatus = true, rebase = true }) => {
19
- return {
20
- title: "Rebase branch",
21
- task: () =>
22
- new Listr(
23
- [
24
- {
25
- title: "Check status",
26
- enabled: () => checkStatus,
27
- task: () =>
28
- checkBranchRemoteStatus({
29
- force,
30
- featureBranch,
31
- origin
32
- })
33
- },
34
- {
35
- title: `Rebase from ${origin}/${chalk.green(fromBranch)}`,
36
- enabled: () => rebase,
37
- task: () => git.rebase(`${origin}/${fromBranch}`).toObservable()
38
- }
39
- ],
40
- { concurrent: false }
41
- )
42
- };
43
- };
@@ -1,42 +0,0 @@
1
- import Listr from "listr";
2
- import { catchError } from "rxjs";
3
-
4
- import { getPackageManager } from "../../common/index.js";
5
- import { refreshMetadata, shouldReinstall } from "../utils/check-install.js";
6
-
7
- export const updateDependencies = ({ PACKAGE_MANAGER }) => {
8
- const reinstall = shouldReinstall();
9
-
10
- return {
11
- title: "Install",
12
- enabled: () => reinstall,
13
- task: () =>
14
- new Listr(
15
- [
16
- {
17
- title: `Restore dependencies using ${PACKAGE_MANAGER.toUpperCase()}`,
18
- task: () =>
19
- getPackageManager(PACKAGE_MANAGER)
20
- .restore()
21
- .toObservable()
22
- .pipe(
23
- catchError((error) => {
24
- if (PACKAGE_MANAGER === "yarn") {
25
- if (error.stderr.startsWith("error Your lockfile needs to be updated")) {
26
- throw new Error("yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.");
27
- }
28
- }
29
-
30
- throw error;
31
- })
32
- )
33
- },
34
- {
35
- title: "Refresh metadata",
36
- task: () => refreshMetadata()
37
- }
38
- ],
39
- { concurrency: false }
40
- )
41
- };
42
- };
@@ -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,40 +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, versions, opts = {}) {
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: "post",
21
- callee: "DIRECTUS",
22
- headers: {
23
- Authorization: `Bearer ${DIRECTUS_ACCESS_TOKEN}`,
24
- "Content-Type": "application/json"
25
- },
26
- data: {
27
- projectId,
28
- versions
29
- },
30
- retries: 3,
31
- retryDelay: axiosRetry.exponentialDelay,
32
- ...opts
33
- };
34
-
35
- if (options.data && options.headers?.["Content-Type"] === "application/json") {
36
- options.data = JSON.stringify(options.data);
37
- }
38
-
39
- return httpRequest(endpoint, options);
40
- }
@@ -1,62 +0,0 @@
1
- // Use vi.hoisted to create mock references that are available to mock factories
2
- const httpRequestMock = vi.hoisted(() => vi.fn());
3
-
4
- // Mock get-config to provide DIRECTUS_* env values
5
- vi.mock("../../get-config.js", () => ({
6
- getConfig: () => ({
7
- DIRECTUS_URL: "https://directus.example.com",
8
- DIRECTUS_FLOW_ID: "flow-123",
9
- DIRECTUS_ACCESS_TOKEN: "token-abc"
10
- })
11
- }));
12
-
13
- // Spy/mock for httpRequest
14
- vi.mock("../http/http-request.js", () => ({
15
- httpRequest: httpRequestMock
16
- }));
17
-
18
- // Now import the SUT after mocks are in place
19
- import { triggerDirectusFlow } from "./directus-flow.js";
20
-
21
- describe("triggerDirectusFlow", () => {
22
- beforeEach(() => {
23
- httpRequestMock.mockReset();
24
- });
25
-
26
- it("should call httpRequest with the expected endpoint, headers and body", async () => {
27
- httpRequestMock.mockResolvedValue({ ok: true, data: { status: "queued" } });
28
-
29
- const projectId = "CMAB";
30
- const versions = ["2.3.0", "2.2.0"];
31
- const opts = { rejectUnauthorized: true };
32
-
33
- const result = await triggerDirectusFlow(projectId, versions, opts);
34
-
35
- expect(result).toEqual({ ok: true, data: { status: "queued" } });
36
-
37
- expect(httpRequestMock).toHaveBeenCalledTimes(1);
38
-
39
- const expectedEndpoint = "https://directus.example.com/flows/trigger/flow-123";
40
- const expectedBody = JSON.stringify({ projectId, versions });
41
-
42
- expect(httpRequestMock).toHaveBeenCalledWith(
43
- expectedEndpoint,
44
- expect.objectContaining({
45
- method: "post",
46
- callee: "DIRECTUS",
47
- rejectUnauthorized: true,
48
- headers: expect.objectContaining({
49
- Authorization: "Bearer token-abc",
50
- "Content-Type": "application/json"
51
- }),
52
- data: expectedBody
53
- })
54
- );
55
- });
56
-
57
- it("should propagate errors from httpRequest", async () => {
58
- httpRequestMock.mockRejectedValue(new Error("network error"));
59
-
60
- await expect(triggerDirectusFlow("CMAB", ["1.0.0"])).rejects.toThrow("network error");
61
- });
62
- });
@@ -1,15 +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
- export const getHttpProxy = (opts) => {
8
- if (HTTPS_PROXY) {
9
- console.debug({
10
- message: `Using proxy agent for ${opts.callee} requests`,
11
- value: HTTPS_PROXY
12
- });
13
- return new HttpsProxyAgent(HTTPS_PROXY, opts);
14
- }
15
- };