@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
@@ -0,0 +1,67 @@
1
+ import chalk from "chalk";
2
+ import figures from "figures";
3
+ import inquirer from "inquirer";
4
+ import { Listr, type ListrTask } from "listr2";
5
+
6
+ import type { CmContext, CommandConstructor } from "./types.js";
7
+ import { getConfig } from "./get-config.js";
8
+ import { getReleaseConfig } from "./get-release-config.js";
9
+
10
+ function createTasksRunner(tasks: ListrTask[], ctx: CmContext): Promise<void> {
11
+ return new Listr(tasks, {
12
+ concurrent: false,
13
+ renderer: !ctx.verbose ? "default" : "verbose"
14
+ }).run(ctx);
15
+ }
16
+
17
+ export async function runCommand(
18
+ klass: CommandConstructor,
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ opts: Record<string, any>
21
+ ): Promise<void> {
22
+ try {
23
+ const config = getConfig();
24
+
25
+ let context = {
26
+ ...getReleaseConfig(),
27
+ ...config,
28
+ branch: { name: config.BRANCH_NAME as string },
29
+ config,
30
+ logger: console,
31
+ verbose: opts.verbose as number | undefined
32
+ } as unknown as CmContext;
33
+
34
+ const command = new klass();
35
+
36
+ if (command.mapContext) {
37
+ context = command.mapContext(opts as Record<string, unknown>, context);
38
+ }
39
+
40
+ if (command.prompt) {
41
+ context = {
42
+ ...context,
43
+ ...((await (inquirer as unknown as { prompt: (q: unknown) => Promise<Record<string, unknown>> }).prompt(
44
+ command.prompt(context)
45
+ )) as Record<string, unknown>)
46
+ };
47
+ }
48
+
49
+ command.verifyConditions?.(context);
50
+
51
+ const tasks = command.getTasks(context);
52
+
53
+ await createTasksRunner(tasks, context);
54
+
55
+ command.success?.(context);
56
+ } catch (er) {
57
+ console.error(chalk.red(figures.cross + " " + String(er)));
58
+ if (opts.verbose) {
59
+ console.error(String((er as Error).stack ?? "").replace(String(er), ""));
60
+ }
61
+ process.exit(-1);
62
+ }
63
+ }
64
+
65
+ process.on("unhandledRejection", () => {
66
+ // avoid extra promise rejection when using toObservable
67
+ });
@@ -0,0 +1,26 @@
1
+ import type { ListrTask } from "listr2";
2
+ import type { BaseContext, LastRelease, NextRelease } from "semantic-release";
3
+ import type { getConfig } from "./get-config";
4
+
5
+ export type CmContext<Extended = any> = BaseContext & {
6
+ config: ReturnType<typeof getConfig>;
7
+ branch: { name: string; type?: string };
8
+ nextRelease?: Partial<NextRelease>;
9
+ lastRelease?: Partial<LastRelease>;
10
+ verbose?: number;
11
+ output?: string[];
12
+ } & Extended;
13
+
14
+ export type SemanticContext = CmContext;
15
+
16
+ export interface ICommand {
17
+ mapContext?(opts: Record<string, unknown>, context: CmContext): CmContext;
18
+ prompt?(context: CmContext): Array<Record<string, unknown>>;
19
+ verifyConditions?(context: CmContext): void;
20
+ getTasks(context: CmContext): ListrTask[];
21
+ success?(context: CmContext): void;
22
+ }
23
+
24
+ export type CommandConstructor = new () => ICommand;
25
+
26
+ export type { ListrTask };
@@ -0,0 +1,4 @@
1
+ // Minimal @semantic-release/commit-analyzer type declarations
2
+ declare module "@semantic-release/commit-analyzer" {
3
+ export function analyzeCommits(pluginConfig: unknown, context: unknown): Promise<string | null>;
4
+ }
@@ -1,4 +1,8 @@
1
- import * as commands from "./commands/index.js";
1
+ import * as commands from "./commands";
2
+
3
+ declare global {
4
+ const __VERSION__: string;
5
+ }
2
6
 
3
7
  export * from "./commands/release.js";
4
8
  export * from "./common/index.js";
@@ -1,17 +1,21 @@
1
1
  import * as commitAnalyzerPlugins from "@semantic-release/commit-analyzer";
2
+ import type { ReleaseType } from "semantic-release";
3
+ import type { SemanticContext } from "../../common/types.js";
2
4
 
3
5
  import { calculateSnapshotVersion } from "../utils/calculate-snapshot-version.js";
4
6
 
5
- export async function analyzeCommits(pluginConfig, context) {
7
+ export async function analyzeCommits(pluginConfig: Record<string, unknown>, context: SemanticContext) {
6
8
  if (context.branch && context.branch.type !== "prerelease") {
7
9
  return commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
8
10
  }
9
11
 
10
12
  const analyzedCommits = await commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
11
13
  context.nextRelease = context.nextRelease || {};
12
- context.nextRelease.type = analyzedCommits;
14
+ context.nextRelease.type = (analyzedCommits ?? undefined) as ReleaseType;
13
15
  context.nextRelease.version = calculateSnapshotVersion(context);
14
- context.lastRelease.version = null;
16
+ if (context.lastRelease) {
17
+ (context.lastRelease as { version: string | null }).version = null;
18
+ }
15
19
 
16
20
  return "patch";
17
21
  }
@@ -1,26 +1,33 @@
1
1
  import { getConfig } from "../../common/index.js";
2
+ import type { SemanticContext } from "../../common/types.js";
2
3
 
3
- export function prepare(pluginConfig, context) {
4
+ interface ConditionalPluginConfig {
5
+ when?: (context: SemanticContext) => boolean;
6
+ run?: string | string[];
7
+ [key: string]: unknown;
8
+ }
9
+
10
+ export function prepare(pluginConfig: ConditionalPluginConfig, context: SemanticContext) {
4
11
  return runAll("prepare", pluginConfig, context, context.branch?.type === "release");
5
12
  }
6
13
 
7
- export function success(pluginConfig, context) {
14
+ export function success(pluginConfig: ConditionalPluginConfig, context: SemanticContext) {
8
15
  return runAll("success", pluginConfig, context, context.branch?.type === "release");
9
16
  }
10
17
 
11
- export function publish(pluginConfig, context) {
18
+ export function publish(pluginConfig: ConditionalPluginConfig, context: SemanticContext) {
12
19
  return runAll("publish", pluginConfig, context, context.branch?.type === "release");
13
20
  }
14
21
 
15
- export function generateNotes(pluginConfig, context) {
22
+ export function generateNotes(pluginConfig: ConditionalPluginConfig, context: SemanticContext) {
16
23
  return runAll("generateNotes", pluginConfig, context, context.branch?.type === "release");
17
24
  }
18
25
 
19
- export function fail(pluginConfig, context) {
26
+ export function fail(pluginConfig: ConditionalPluginConfig, context: SemanticContext) {
20
27
  return runAll("fail", pluginConfig, context, context.branch?.type === "release");
21
28
  }
22
29
 
23
- async function runAll(step, pluginConfig, context, defaultCondition) {
30
+ async function runAll(step: string, pluginConfig: ConditionalPluginConfig, context: SemanticContext, defaultCondition: boolean) {
24
31
  context.config = getConfig();
25
32
 
26
33
  const condition = pluginConfig.when !== undefined ? pluginConfig.when(context) : defaultCondition;
@@ -31,15 +38,15 @@ async function runAll(step, pluginConfig, context, defaultCondition) {
31
38
  }
32
39
 
33
40
  if (pluginConfig.run) {
34
- const tasks = [].concat(pluginConfig.run);
41
+ const tasks: string[] = ([] as string[]).concat(pluginConfig.run as string);
35
42
 
36
43
  for (const task of tasks) {
37
44
  if (typeof task === "string") {
38
- const mod = await import(task);
45
+ const mod = (await import(task)) as Record<string, (config: unknown, ctx: unknown) => Promise<void>>;
39
46
  const taskFunction = mod[step];
40
47
 
41
48
  if (taskFunction) {
42
- context.logger.log(` Start conditional step "${step}" of plugin "${task}"`);
49
+ context.logger.info(` Start conditional step "${step}" of plugin "${task}"`);
43
50
 
44
51
  try {
45
52
  await taskFunction(pluginConfig, context);
@@ -1,8 +1,9 @@
1
1
  import { getConfig } from "../../common/index.js";
2
+ import type { SemanticContext } from "../../common/types.js";
2
3
 
3
- export default async function exit(pluginConfig, context) {
4
+ export default async function exit(pluginConfig: Record<string, unknown>, context: SemanticContext) {
4
5
  context.config = getConfig();
5
- const condition = pluginConfig.when !== undefined ? pluginConfig.when(context) : true;
6
+ const condition = pluginConfig.when !== undefined ? (pluginConfig.when as (ctx: SemanticContext) => boolean)(context) : true;
6
7
 
7
8
  if (condition) {
8
9
  // avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
@@ -1,36 +1,39 @@
1
1
  import { getConfig, getPackageManager, lerna } from "../../../common/index.js";
2
2
  import { bumpPackagesVersion } from "../../utils/bump-packages-version.js";
3
+ import type { SemanticContext } from "../../../common/types.js";
3
4
 
4
- export async function prepare(_, context) {
5
+ export async function prepare(_: unknown, context: SemanticContext) {
5
6
  context.config = getConfig();
6
7
  const {
7
8
  config: { PACKAGE_MANAGER, HAS_LERNA, BUMP_METHOD, WORKSPACES },
8
9
  logger
9
10
  } = context;
10
- const versionPackageManager = PACKAGE_MANAGER === "yarn" ? "npm" : PACKAGE_MANAGER;
11
+ const versionPackageManager = PACKAGE_MANAGER === "yarn" ? "npm" : (PACKAGE_MANAGER as string);
11
12
 
12
13
  logger.info(`Start bump version for all packages using method: ${BUMP_METHOD}`);
13
14
 
15
+ const version = context.nextRelease?.version ?? "";
16
+
14
17
  switch (BUMP_METHOD) {
15
18
  case "native":
16
19
  logger.info("Using package manager");
17
- getPackageManager(PACKAGE_MANAGER).newVersion(context.nextRelease.version);
20
+ getPackageManager(PACKAGE_MANAGER as string).newVersion(version);
18
21
  break;
19
22
  case "lerna":
20
23
  if (HAS_LERNA) {
21
- await lerna.newVersion(context.nextRelease.version);
24
+ await lerna.newVersion(version);
22
25
  }
23
26
  break;
24
27
  case "cmflow":
25
- await bumpPackagesVersion(context.nextRelease.version, WORKSPACES);
26
- await getPackageManager(PACKAGE_MANAGER).install();
28
+ await bumpPackagesVersion(version, WORKSPACES as string[]);
29
+ await getPackageManager(PACKAGE_MANAGER as string).install();
27
30
  break;
28
31
  case "native:lerna":
29
32
  default:
30
- getPackageManager(versionPackageManager).newVersion(context.nextRelease.version);
33
+ getPackageManager(versionPackageManager).newVersion(version);
31
34
 
32
35
  if (HAS_LERNA) {
33
- await lerna.newVersion(context.nextRelease.version);
36
+ await lerna.newVersion(version);
34
37
  }
35
38
  }
36
39
 
@@ -1,6 +1,7 @@
1
1
  import { configureGitWorkspace, getConfig, git } from "../../../common/index.js";
2
+ import type { SemanticContext } from "../../../common/types.js";
2
3
 
3
- export async function prepare(pluginConfig, context) {
4
+ export async function prepare(pluginConfig: Record<string, unknown>, context: SemanticContext) {
4
5
  context.config = getConfig();
5
6
 
6
7
  const {
@@ -18,7 +19,7 @@ export async function prepare(pluginConfig, context) {
18
19
  logger.info("Get commit stage status");
19
20
  git.status();
20
21
 
21
- const revisionMessage = `chore: ${CI_NAME} build ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`;
22
+ const revisionMessage = `chore: ${CI_NAME} build ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease?.gitTag} [ci skip]`;
22
23
 
23
24
  logger.info("Commit changes with revision message: ");
24
25
  logger.info(revisionMessage);
@@ -0,0 +1,6 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import type { SemanticContext } from "../../../common/types.js";
3
+
4
+ export function prepare(pluginConfig: { path: string }, context: SemanticContext) {
5
+ return writeFile(pluginConfig.path, context.branch.name, { encoding: "utf-8" });
6
+ }
@@ -1,18 +1,19 @@
1
1
  import { getConfig, getPackageManager } from "../../common/index.js";
2
+ import type { SemanticContext } from "../../common/types.js";
2
3
 
3
4
  /**
4
5
  * @param pluginConfig {{command: string}}
5
6
  * @param context
6
7
  * @return {Promise<void>}
7
8
  */
8
- export default async function runCommand(pluginConfig, context) {
9
+ export default async function runCommand(pluginConfig: { command: string }, context: SemanticContext) {
9
10
  context.config = getConfig();
10
11
  const {
11
12
  config: { PACKAGE_MANAGER },
12
13
  logger
13
14
  } = context;
14
15
 
15
- const pkgManager = getPackageManager(PACKAGE_MANAGER);
16
+ const pkgManager = getPackageManager(PACKAGE_MANAGER as string);
16
17
 
17
18
  logger.info(`Start ${pluginConfig.command} task`);
18
19
 
@@ -0,0 +1,55 @@
1
+ import { getConfig, git } from "../../common/index.js";
2
+ import type { SemanticContext } from "../../common/types.js";
3
+
4
+ export default async function syncRepository(pluginConfig: Record<string, unknown>, context: SemanticContext) {
5
+ context.config = getConfig();
6
+
7
+ const {
8
+ logger,
9
+ config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH }
10
+ } = context;
11
+
12
+ logger.info("Prepare release");
13
+
14
+ async function asyncCatchError(fn: () => unknown) {
15
+ try {
16
+ return await fn();
17
+ } catch (er) {
18
+ context.logger.error(String(er), (er as Error).stack);
19
+ }
20
+ }
21
+
22
+ await asyncCatchError(() => git.fetch());
23
+
24
+ const branchesOption = context.options?.branches;
25
+ const branchesArray = Array.isArray(branchesOption) ? branchesOption : branchesOption ? [branchesOption] : [];
26
+ const candidateBranches =
27
+ (pluginConfig.includes as string[] | undefined) ||
28
+ branchesArray.map((branch: string | { name?: string }) => {
29
+ return (branch as { name?: string }).name || (branch as string);
30
+ });
31
+
32
+ logger.info(`Candidate branches to sync: ${(candidateBranches as string[]).join(", ")}`);
33
+
34
+ if ((candidateBranches as string[]).includes(context.branch.name)) {
35
+ logger.info(`Push ${context.branch.name}`);
36
+
37
+ await asyncCatchError(() => {
38
+ logger.info(`git push --quiet --set-upstream ${ORIGIN} ${context.branch.name}`);
39
+
40
+ return git.push("--quiet", "--set-upstream", ORIGIN as string, context.branch.name);
41
+ });
42
+ } else {
43
+ logger.info(`Skip push for ${context.branch.name}`);
44
+ }
45
+
46
+ if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
47
+ logger.info(`Sync ${DEVELOP_BRANCH} with ${PRODUCTION_BRANCH}`);
48
+ logger.info(`git push -f ${ORIGIN} ${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`);
49
+
50
+ await asyncCatchError(async () => {
51
+ await git.push("-f", ORIGIN as string, `${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`);
52
+ logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`);
53
+ });
54
+ }
55
+ }
@@ -1,8 +1,9 @@
1
1
  import chalk from "chalk";
2
2
 
3
3
  import { getConfig, git } from "../../common/index.js";
4
+ import type { SemanticContext } from "../../common/types.js";
4
5
 
5
- export function verifyConditions(pluginConfig, context) {
6
+ export function verifyConditions(pluginConfig: Record<string, unknown>, context: SemanticContext) {
6
7
  if (pluginConfig.dryRun) {
7
8
  return;
8
9
  }
@@ -16,8 +17,8 @@ export function verifyConditions(pluginConfig, context) {
16
17
  if (USER && EMAIL) {
17
18
  context.logger.info("Configure git with username");
18
19
 
19
- git.config("--global", "user.name", USER);
20
- git.config("--global", "user.email", EMAIL);
20
+ git.config("--global", "user.name", USER as string);
21
+ git.config("--global", "user.email", EMAIL as string);
21
22
 
22
23
  context.logger.info("Configure git branch");
23
24
  context.logger.success("Workspace is correctly configured");
@@ -1,8 +1,9 @@
1
1
  import { getConfig } from "../../common/index.js";
2
2
  import { displayPackageInfo } from "../utils/display-package-info.js";
3
3
  import { displayReleaseInfo } from "../utils/display-release-info.js";
4
+ import type { SemanticContext } from "../../common/types.js";
4
5
 
5
- export function verifyRelease(pluginConfig, context) {
6
+ export function verifyRelease(pluginConfig: Record<string, unknown>, context: SemanticContext) {
6
7
  context.config = getConfig();
7
8
  displayPackageInfo(context);
8
9
  displayReleaseInfo(context);
@@ -0,0 +1,6 @@
1
+ import { dockerPublish } from "../utils/docker-publish.js";
2
+ import type { SemanticContext } from "../../common/types.js";
3
+
4
+ export async function publish(pluginConfig: Record<string, unknown>, context: SemanticContext) {
5
+ await dockerPublish(context);
6
+ }
@@ -1,6 +1,7 @@
1
+ import type { CmContext } from "../../common/types.js";
1
2
  import { dockerCleanTags } from "../utils/docker-clean-tags.js";
2
3
 
3
- export async function success(pluginConfig, context) {
4
+ export async function success(_: Record<string, unknown>, context: CmContext) {
4
5
  try {
5
6
  await dockerCleanTags(context);
6
7
  } catch (er) {
@@ -1 +1,7 @@
1
- {"name":"@package/root","version":"1.1.0","dependencies":{},"devDependencies":{},"peerDependencies":{}}
1
+ {
2
+ "name": "@package/root",
3
+ "version": "1.1.0",
4
+ "dependencies": {},
5
+ "devDependencies": {},
6
+ "peerDependencies": {}
7
+ }
@@ -1 +1,9 @@
1
- {"name":"@package/a","version":"1.1.0","dependencies":{"@package/b":"1.1.0"},"devDependencies":{},"peerDependencies":{}}
1
+ {
2
+ "name": "@package/a",
3
+ "version": "1.1.0",
4
+ "dependencies": {
5
+ "@package/b": "1.1.0"
6
+ },
7
+ "devDependencies": {},
8
+ "peerDependencies": {}
9
+ }
@@ -1 +1,7 @@
1
- {"name":"@package/b","version":"1.1.0","dependencies":{},"devDependencies":{},"peerDependencies":{}}
1
+ {
2
+ "name": "@package/b",
3
+ "version": "1.1.0",
4
+ "dependencies": {},
5
+ "devDependencies": {},
6
+ "peerDependencies": {}
7
+ }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  import fs from "fs-extra";
2
3
  import path from "path";
3
4
  import * as url from "url";
@@ -1,10 +1,10 @@
1
1
  import fs from "fs-extra";
2
- import globby from "globby";
2
+ import { globby } from "globby";
3
3
  import { dirname } from "path";
4
4
 
5
5
  const PACKAGE_JSON_PROPS = ["dependencies", "devDependencies", "peerDependencies"];
6
6
 
7
- export async function bumpPackagesVersion(version, workspaces, cwd = process.cwd()) {
7
+ export async function bumpPackagesVersion(version: string, workspaces: string[], cwd = process.cwd()) {
8
8
  const patterns = workspaces.map((path) => `${path}/package.json`).concat("package.json");
9
9
 
10
10
  const files = await globby(patterns, {
@@ -12,13 +12,13 @@ export async function bumpPackagesVersion(version, workspaces, cwd = process.cwd
12
12
  absolute: true
13
13
  });
14
14
 
15
- const names = new Set();
15
+ const names = new Set<string>();
16
16
 
17
17
  const packages = await Promise.all(
18
- files.map(async (file) => {
19
- const pkg = await fs.readJson(file);
18
+ files.map(async (file: string) => {
19
+ const pkg = (await fs.readJson(file)) as Record<string, unknown>;
20
20
 
21
- names.add(pkg.name);
21
+ names.add(pkg.name as string);
22
22
 
23
23
  return {
24
24
  file,
@@ -28,7 +28,7 @@ export async function bumpPackagesVersion(version, workspaces, cwd = process.cwd
28
28
  );
29
29
 
30
30
  return Promise.all(
31
- packages.map(({ pkg, file }) => {
31
+ packages.map(({ pkg, file }: { pkg: Record<string, unknown>; file: string }) => {
32
32
  pkg.version = version;
33
33
 
34
34
  PACKAGE_JSON_PROPS.forEach((key) => bumpDependencies(pkg, key, version, names));
@@ -39,13 +39,14 @@ export async function bumpPackagesVersion(version, workspaces, cwd = process.cwd
39
39
  );
40
40
  }
41
41
 
42
- function bumpDependencies(pkg, key, version, names) {
42
+ function bumpDependencies(pkg: Record<string, unknown>, key: string, version: string, names: Set<string>) {
43
43
  pkg[key] = pkg[key] || {};
44
44
 
45
- if (pkg[key]) {
45
+ const deps = pkg[key] as Record<string, string>;
46
+ if (deps) {
46
47
  names.forEach((name) => {
47
- if (pkg[key][name] && !pkg[key][name].startsWith("workspace:")) {
48
- pkg[key][name] = version;
48
+ if (deps[name] && !deps[name].startsWith("workspace:")) {
49
+ deps[name] = version;
49
50
  }
50
51
  });
51
52
  }
@@ -1,3 +1,7 @@
1
+ import { git, getConfig } from "../../common/index.js";
2
+ import type { CmContext } from "../../common/types";
3
+ import { calculateSnapshotVersion } from "./calculate-snapshot-version.js";
4
+
1
5
  vi.mock("../../common/index.js", () => {
2
6
  return {
3
7
  git: {
@@ -6,19 +10,17 @@ vi.mock("../../common/index.js", () => {
6
10
  getConfig: vi.fn()
7
11
  };
8
12
  });
9
- const { git, getConfig } = await import("../../common/index.js");
10
- const { calculateSnapshotVersion } = await import("./calculate-snapshot-version.js");
11
13
 
12
14
  describe("calculateSnapshotVersion", () => {
13
15
  beforeEach(() => {
14
- git.getCommitTag.mockReturnValue("13246u");
15
- getConfig.mockReturnValue({
16
+ vi.mocked(git.getCommitTag).mockReturnValue("13246u");
17
+ vi.mocked(getConfig).mockReturnValue({
16
18
  DEPLOY_ON_DOCKER: true,
17
19
  PRODUCTION_BRANCH: "production",
18
20
  DOCKER_REPOSITORY: "owner",
19
21
  DOCKER_HUB_ID: "login",
20
22
  DOCKER_HUB_PWD: "password"
21
- });
23
+ } as unknown as CmContext["config"]);
22
24
  });
23
25
  it("should return the snapshot version", () => {
24
26
  const context = {
@@ -26,7 +28,7 @@ describe("calculateSnapshotVersion", () => {
26
28
  lastRelease: {
27
29
  version: "1.0.0"
28
30
  }
29
- };
31
+ } as CmContext;
30
32
 
31
33
  const version = calculateSnapshotVersion(context);
32
34
  expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT);
@@ -42,7 +44,7 @@ describe("calculateSnapshotVersion", () => {
42
44
  config: {
43
45
  REF_COMMIT: "REF_COMMIT"
44
46
  }
45
- };
47
+ } as CmContext;
46
48
 
47
49
  const version = calculateSnapshotVersion(context);
48
50
  expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT);
@@ -58,7 +60,7 @@ describe("calculateSnapshotVersion", () => {
58
60
  config: {
59
61
  REF_COMMIT: "REF_COMMIT"
60
62
  }
61
- };
63
+ } as CmContext;
62
64
 
63
65
  const version = calculateSnapshotVersion(context);
64
66
  expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT);
@@ -0,0 +1,17 @@
1
+ import semver from "semver";
2
+
3
+ import { getConfig, git } from "../../common/index.js";
4
+ import type { SemanticContext } from "../../common/types.js";
5
+
6
+ export function calculateSnapshotVersion(context: SemanticContext) {
7
+ context.config = getConfig();
8
+ const {
9
+ nextRelease,
10
+ lastRelease,
11
+ config: { REF_COMMIT }
12
+ } = context;
13
+ const parsed = semver.parse(lastRelease?.version ?? "0.0.0");
14
+ const { major, minor, patch } = parsed ?? { major: 0, minor: 0, patch: 0 };
15
+
16
+ return `${semver.inc(`${major}.${minor}.${patch}`, nextRelease?.type ?? "patch") ?? "0.0.0"}-beta${git.getCommitTag(REF_COMMIT as string)}`;
17
+ }
@@ -0,0 +1,12 @@
1
+ import { logSection } from "./log-section.js";
2
+ import type { SemanticContext } from "../../common/types.js";
3
+
4
+ export function displayPackageInfo(context: SemanticContext) {
5
+ logSection("Package Info", context);
6
+ context.logger.info("Name : " + context.config.PROJECT_NAME);
7
+ context.logger.info("Version : " + context.lastRelease?.version);
8
+ context.logger.info("Repository : " + context.config.REPOSITORY_URL);
9
+ context.logger.info("Branch : " + context.branch.name);
10
+ context.logger.info("Tag : " + context.lastRelease?.gitTag);
11
+ context.logger.info("GitHead : " + context.lastRelease?.gitHead);
12
+ }
@@ -0,0 +1,13 @@
1
+ import { logSection } from "./log-section.js";
2
+ import type { SemanticContext } from "../../common/types.js";
3
+
4
+ export function displayReleaseInfo(context: SemanticContext) {
5
+ logSection("Release Info", context);
6
+ context.logger.info("Branch : " + context.branch.name);
7
+ context.logger.info("Build N° : " + context.config.BUILD_NUMBER);
8
+ context.logger.info("Version : " + context.nextRelease?.version);
9
+ context.logger.info("Tag : " + context.nextRelease?.gitTag);
10
+ context.logger.info("GitHead : " + context.nextRelease?.gitHead);
11
+ context.logger.info("Type : " + context.nextRelease?.type);
12
+ context.logger.info("Channel : " + context.nextRelease?.channel);
13
+ }
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  vi.mock("../../common", () => {
2
3
  return {
3
4
  docker: {
@@ -1,7 +1,14 @@
1
1
  import { docker } from "../../common/index.js";
2
+ import type { CmContext } from "../../common/types";
2
3
 
3
- function mapTags(tags) {
4
- tags = tags
4
+ interface DockerTag {
5
+ name: string;
6
+ last_updated: string | Date;
7
+ date?: number;
8
+ }
9
+
10
+ function mapTags(tags: DockerTag[]) {
11
+ const mapped = tags
5
12
  .map((tag) => {
6
13
  return {
7
14
  name: tag.name,
@@ -12,7 +19,7 @@ function mapTags(tags) {
12
19
 
13
20
  let tagFound = false;
14
21
 
15
- return tags.reduce((result, tag) => {
22
+ return mapped.reduce((result: typeof mapped, tag) => {
16
23
  if (tag.name.match(/\d+\.\d+\.\d+/)) {
17
24
  tagFound = true;
18
25
  } else if (tagFound) {
@@ -22,7 +29,7 @@ function mapTags(tags) {
22
29
  }, []);
23
30
  }
24
31
 
25
- export async function dockerCleanTags(context) {
32
+ export async function dockerCleanTags(context: CmContext) {
26
33
  const {
27
34
  logger,
28
35
  config: { DOCKER_HUB_ID, DOCKER_HUB_PWD, DOCKER_REPOSITORY }