@cmflow/cli 1.1.0 → 1.1.1-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 (124) hide show
  1. package/.prettierignore +5 -0
  2. package/.prettierrc +10 -0
  3. package/README.md +106 -32
  4. package/bin/cm-changelog.js +20 -12
  5. package/bin/cm-clean.js +4 -7
  6. package/bin/cm-config.js +8 -8
  7. package/bin/cm-deploy.js +4 -8
  8. package/bin/cm-fetch.js +7 -7
  9. package/bin/cm-finish.js +9 -9
  10. package/bin/cm-merge.js +7 -7
  11. package/bin/cm-publish.js +10 -10
  12. package/bin/cm-push.js +10 -10
  13. package/bin/cm-rebase.js +10 -10
  14. package/bin/cm-republish.js +7 -7
  15. package/bin/cm-start.js +10 -10
  16. package/bin/cm.js +20 -20
  17. package/bin/cmrelease.js +2 -2
  18. package/eslint.config.mjs +67 -0
  19. package/package.json +27 -21
  20. package/release.config.mjs +49 -19
  21. package/src/commands/changelog.js +23 -23
  22. package/src/commands/clean.js +13 -13
  23. package/src/commands/config.js +8 -8
  24. package/src/commands/deploy.js +15 -20
  25. package/src/commands/fetch.js +7 -10
  26. package/src/commands/finish.js +18 -19
  27. package/src/commands/index.js +10 -11
  28. package/src/commands/merge.js +30 -14
  29. package/src/commands/prompts/branches.js +20 -20
  30. package/src/commands/push.js +11 -14
  31. package/src/commands/rebase.js +17 -19
  32. package/src/commands/release.js +10 -11
  33. package/src/commands/republish.js +11 -14
  34. package/src/commands/start.js +52 -48
  35. package/src/commands/tasks/merge-branch.js +41 -37
  36. package/src/commands/tasks/push-branch.js +5 -11
  37. package/src/commands/tasks/rebase-all-branches.js +19 -24
  38. package/src/commands/tasks/refresh-repository.js +26 -24
  39. package/src/commands/tasks/run-test.js +11 -17
  40. package/src/commands/tasks/update-branch.js +33 -30
  41. package/src/commands/tasks/update-dependencies.js +38 -32
  42. package/src/commands/utils/check-install.js +16 -15
  43. package/src/common/cli/cli.js +55 -57
  44. package/src/common/cli/docker.js +31 -28
  45. package/src/common/cli/docker.test.js +94 -96
  46. package/src/common/cli/git.js +59 -68
  47. package/src/common/cli/git.test.js +187 -189
  48. package/src/common/cli/lerna.js +12 -12
  49. package/src/common/cli/lerna.test.js +38 -40
  50. package/src/common/cli/npm.js +17 -17
  51. package/src/common/cli/npm.test.js +38 -40
  52. package/src/common/cli/yarn.js +17 -17
  53. package/src/common/cli/yarn.test.js +40 -40
  54. package/src/common/configure-git-workspace.js +11 -17
  55. package/src/common/get-config.js +63 -119
  56. package/src/common/get-package-json.js +4 -4
  57. package/src/common/get-release-config.js +4 -5
  58. package/src/common/index.js +10 -10
  59. package/src/common/run-command.js +26 -28
  60. package/src/common/run-command.test.js +35 -39
  61. package/src/index.js +10 -1
  62. package/src/semantic/core/analyze-commits.js +17 -0
  63. package/src/semantic/core/fail.js +29 -0
  64. package/src/semantic/core/generate-notes.js +11 -0
  65. package/src/semantic/core/prepare/bump-version.js +38 -0
  66. package/src/semantic/core/prepare/post.js +38 -0
  67. package/src/semantic/core/prepare/run.js +22 -0
  68. package/src/semantic/core/publish.js +9 -0
  69. package/src/semantic/core/success.js +37 -0
  70. package/src/semantic/core/verify-conditions.js +32 -0
  71. package/src/semantic/core/verify-release.js +9 -0
  72. package/src/semantic/define-config.js +68 -0
  73. package/src/semantic/docker/publish.js +5 -0
  74. package/src/semantic/docker/success.js +9 -0
  75. package/src/semantic/utils/bump-packages-version.js +52 -0
  76. package/src/semantic/utils/bump-packages-version.test.js +75 -0
  77. package/src/semantic/utils/calculate-snapshot-version.js +15 -0
  78. package/src/semantic/utils/calculate-snapshot-version.test.js +67 -0
  79. package/src/semantic/utils/display-package-info.js +11 -0
  80. package/src/semantic/utils/display-release-info.js +12 -0
  81. package/src/semantic/utils/docker-clean-tags.js +51 -0
  82. package/src/semantic/utils/docker-clean-tags.test.js +61 -0
  83. package/src/semantic/utils/docker-publish.js +23 -0
  84. package/src/semantic/utils/docker-publish.test.js +44 -0
  85. package/src/semantic/utils/log-section.js +5 -0
  86. package/src/semantic/utils/release-rules.js +5 -0
  87. package/src/semantic/utils/transform-writer.js +75 -0
  88. package/src/workflow/index.js +22 -22
  89. package/tsconfig.json +54 -0
  90. package/vitest.config.mts +10 -0
  91. package/bin/cm-publish-pages.js +0 -12
  92. package/semantic.js +0 -1
  93. package/src/commands/publish-pages.js +0 -29
  94. package/src/common/cli/heroku.js +0 -21
  95. package/src/common/cli/heroku.test.js +0 -62
  96. package/src/main.js +0 -10
  97. package/src/semantic-release/actions/analyze-commits.js +0 -14
  98. package/src/semantic-release/actions/fail.js +0 -16
  99. package/src/semantic-release/actions/generate-notes.js +0 -12
  100. package/src/semantic-release/actions/index.js +0 -8
  101. package/src/semantic-release/actions/prepare.js +0 -114
  102. package/src/semantic-release/actions/publish.js +0 -17
  103. package/src/semantic-release/actions/success.js +0 -32
  104. package/src/semantic-release/actions/verify-conditions.js +0 -30
  105. package/src/semantic-release/actions/verify-release.js +0 -9
  106. package/src/semantic-release/get-semantic-config.js +0 -115
  107. package/src/semantic-release/utils/bump-packages-version.js +0 -51
  108. package/src/semantic-release/utils/bump-packages-version.test.js +0 -78
  109. package/src/semantic-release/utils/calculate-snapshot-version.js +0 -10
  110. package/src/semantic-release/utils/calculate-snapshot-version.test.js +0 -69
  111. package/src/semantic-release/utils/display-package-info.js +0 -11
  112. package/src/semantic-release/utils/display-release-info.js +0 -12
  113. package/src/semantic-release/utils/docker-clean-tags.js +0 -45
  114. package/src/semantic-release/utils/docker-clean-tags.test.js +0 -63
  115. package/src/semantic-release/utils/docker-publish.js +0 -47
  116. package/src/semantic-release/utils/docker-publish.test.js +0 -67
  117. package/src/semantic-release/utils/ghpages-publish.js +0 -16
  118. package/src/semantic-release/utils/log-section.js +0 -5
  119. /package/src/{semantic-release → semantic}/utils/__mock__/test1/package.json +0 -0
  120. /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/a/package.json +0 -0
  121. /package/src/{semantic-release → semantic}/utils/__mock__/test1/packages/b/package.json +0 -0
  122. /package/src/{semantic-release → semantic}/utils/__mock__/test2/package.json +0 -0
  123. /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/a/package.json +0 -0
  124. /package/src/{semantic-release → semantic}/utils/__mock__/test2/packages/b/package.json +0 -0
@@ -1,178 +1,122 @@
1
- import hasYarn from 'has-yarn'
2
- import get from 'lodash/get.js'
3
- import { git } from './cli/git.js'
4
- import { getPackageJson } from './get-package-json.js'
5
- import fs from 'fs'
6
- import { join } from 'path'
1
+ import fs from "node:fs";
2
+ import { join } from "node:path";
7
3
 
8
- const toBool = (value) => {
9
- if (value === 'false') return false
10
- if (value === '0') return false
4
+ import hasYarn from "has-yarn";
5
+ import get from "lodash/get.js";
11
6
 
12
- return !!value
13
- }
7
+ import { git } from "./cli/git.js";
8
+ import { getPackageJson } from "./get-package-json.js";
14
9
 
15
- export function getCI () {
16
- const { env } = process
17
- const {
18
- GIT_USER_NAME,
19
- GIT_USER_EMAIL
20
- } = env
10
+ export function getCI() {
11
+ const { env } = process;
12
+ const { GIT_USER_NAME, GIT_USER_EMAIL } = env;
21
13
  if (env.CI) {
22
14
  if (env.GITLAB_CI) {
23
- const {
24
- CI_BUILD_ID,
25
- CI_JOB_ID,
26
- CI_COMMIT_SHA,
27
- CI_COMMIT_BRANCH
28
- } = env
15
+ const { CI_BUILD_ID, CI_JOB_ID, CI_COMMIT_SHA, CI_COMMIT_BRANCH } = env;
29
16
 
30
17
  return {
31
- CI_NAME: 'GitLab CI',
32
- USER: GIT_USER_NAME || 'GitLab CI',
33
- EMAIL: GIT_USER_EMAIL || 'gitlab@gitlab.com',
18
+ CI_NAME: "GitLab CI",
19
+ USER: GIT_USER_NAME || "GitLab CI",
20
+ EMAIL: GIT_USER_EMAIL || "gitlab@gitlab.com",
34
21
  BUILD_NUMBER: CI_BUILD_ID || CI_JOB_ID,
35
- CI_ORIGIN: 'origin-git',
22
+ CI_ORIGIN: "origin-git",
36
23
  REF_COMMIT: CI_COMMIT_SHA,
37
24
  IS_PULL_REQUEST: false,
38
25
  BRANCH_NAME: CI_COMMIT_BRANCH
39
- }
26
+ };
40
27
  }
41
28
 
42
29
  if (env.CIRCLECI) {
43
- const {
44
- CIRCLE_BUILD_NUM,
45
- CIRCLE_SHA1,
46
- CIRCLE_PULL_REQUEST,
47
- CIRCLE_BRANCH
48
- } = env
30
+ const { CIRCLE_BUILD_NUM, CIRCLE_SHA1, CIRCLE_PULL_REQUEST, CIRCLE_BRANCH } = env;
49
31
  return {
50
- CI_NAME: 'Circle CI',
51
- USER: GIT_USER_NAME || 'Circle CI',
52
- EMAIL: GIT_USER_EMAIL || 'circle@circleci.com',
32
+ CI_NAME: "Circle CI",
33
+ USER: GIT_USER_NAME || "Circle CI",
34
+ EMAIL: GIT_USER_EMAIL || "circle@circleci.com",
53
35
  BUILD_NUMBER: CIRCLE_BUILD_NUM,
54
- CI_ORIGIN: 'origin-git',
36
+ CI_ORIGIN: "origin-git",
55
37
  REF_COMMIT: CIRCLE_SHA1,
56
- IS_PULL_REQUEST: CIRCLE_PULL_REQUEST && CIRCLE_PULL_REQUEST !== 'false',
38
+ IS_PULL_REQUEST: CIRCLE_PULL_REQUEST && CIRCLE_PULL_REQUEST !== "false",
57
39
  BRANCH_NAME: CIRCLE_BRANCH
58
- }
40
+ };
59
41
  }
60
42
 
61
43
  if (env.GITHUB_ACTION) {
62
- const {
63
- GITHUB_ACTION,
64
- GITHUB_SHA,
65
- GITHUB_REF,
66
- GITHUB_ACTOR
67
- } = env
44
+ const { GITHUB_ACTION, GITHUB_SHA, GITHUB_REF, GITHUB_ACTOR } = env;
68
45
  return {
69
- CI_NAME: 'Github CI',
70
- USER: GIT_USER_NAME || GITHUB_ACTOR || 'Github CI',
71
- EMAIL: GIT_USER_EMAIL || 'action@github.com',
46
+ CI_NAME: "Github CI",
47
+ USER: GIT_USER_NAME || GITHUB_ACTOR || "Github CI",
48
+ EMAIL: GIT_USER_EMAIL || "action@github.com",
72
49
  BUILD_NUMBER: GITHUB_ACTION,
73
- CI_ORIGIN: 'origin-git',
50
+ CI_ORIGIN: "origin-git",
74
51
  REF_COMMIT: GITHUB_SHA,
75
52
  IS_PULL_REQUEST: false,
76
- BRANCH_NAME: GITHUB_REF.replace('refs/heads/', '')
77
- }
53
+ BRANCH_NAME: GITHUB_REF.replace("refs/heads/", "")
54
+ };
78
55
  }
79
56
 
80
57
  return {
81
- NAME: 'Unsupported CI',
82
- BUILD_NUMBER: '',
83
- CI_ORIGIN: 'origin-git',
58
+ NAME: "Unsupported CI",
59
+ BUILD_NUMBER: "",
60
+ CI_ORIGIN: "origin-git",
84
61
  IS_PULL_REQUEST: false,
85
62
  BRANCH_NAME: git.getBranchName()
86
- }
63
+ };
87
64
  }
88
65
  // / local
89
66
  return {
90
- NAME: 'LOCAL',
91
- BUILD_NUMBER: '1',
92
- CI_ORIGIN: 'origin-git',
67
+ NAME: "LOCAL",
68
+ BUILD_NUMBER: "1",
69
+ CI_ORIGIN: "origin-git",
93
70
  BRANCH_NAME: git.getBranchName()
94
- }
71
+ };
95
72
  }
96
73
 
97
- export function getConfig () {
98
- const pkg = getPackageJson()
99
- const [owner, projectName] = pkg.name.replace(/^@/, '').split('/')
100
- const {
101
- PROJECT_NAME,
102
- DOCKER_HUB_ID,
103
- DOCKER_HUB_PWD,
104
- REF_COMMIT,
105
- GH_TOKEN,
106
- HEROKU_APP,
107
- SKIP_GITHUB_PUBLISH,
108
- GITHUB_PAGES_PATH,
109
- REPOSITORY_URL,
110
- GIT_USER_NAME,
111
- GIT_USER_EMAIL
112
- } = process.env
74
+ export function getConfig() {
75
+ const pkg = getPackageJson();
76
+ const [owner, projectName] = pkg.name.replace(/^@/, "").split("/");
77
+ const { PROJECT_NAME, DOCKER_HUB_ID, DOCKER_HUB_PWD, REF_COMMIT, GH_TOKEN, SCM_TOKEN, REPOSITORY_URL, GIT_USER_NAME, GIT_USER_EMAIL } =
78
+ process.env;
113
79
 
114
- const HAS_YARN = hasYarn()
115
- const E2E_CMD = pkg.scripts.test_e2e ? 'test_e2e' : pkg.scripts['test:e2e'] ? 'test:e2e' : undefined
116
- const IS_YARN_BERRY = HAS_YARN ? fs.existsSync(join(process.cwd(), '.yamlrc.yml')) : false
117
- let BUMP_METHOD = get(pkg, 'flow.bumpMethod', 'default')
80
+ const HAS_YARN = hasYarn();
81
+ const IS_YARN_BERRY = HAS_YARN ? fs.existsSync(join(process.cwd(), ".yamlrc.yml")) : false;
82
+ let BUMP_METHOD = get(pkg, "flow.bumpMethod", "default");
118
83
 
119
- if (IS_YARN_BERRY && ['native', 'default'].includes(BUMP_METHOD)) {
120
- BUMP_METHOD = 'cmflow'
84
+ if (IS_YARN_BERRY && ["native", "default"].includes(BUMP_METHOD)) {
85
+ BUMP_METHOD = "cmflow";
121
86
  }
122
87
 
123
88
  return {
89
+ pkg,
124
90
  PROJECT_NAME: PROJECT_NAME || projectName,
125
91
  HAS_YARN: hasYarn(),
126
92
  IS_YARN_BERRY,
127
93
  HAS_LERNA: pkg.dependencies.lerna || pkg.devDependencies.lerna,
128
- HAS_BUILD: pkg.scripts.build,
129
- HAS_E2E: !!E2E_CMD,
130
- E2E_CMD,
131
- HAS_BUILD_CHANGELOG: pkg.scripts.build_changelog,
132
- get DEPLOY_ON_DOCKER () {
133
- return toBool(process.env.DEPLOY_ON_DOCKER) && DOCKER_HUB_ID && DOCKER_HUB_PWD
134
- },
135
- get DEPLOY_ON_HEROKU () {
136
- return process.env.DEPLOY_ON_HEROKU ? toBool(process.env.DEPLOY_ON_HEROKU) && !!HEROKU_APP : !!HEROKU_APP
137
- },
138
- CI_SKIP: '[ci skip]',
139
- RELEASE_CANDIDATE_TAG: '[MEP]',
140
- ORIGIN: 'origin',
141
- get PRODUCTION_BRANCH () {
142
- return get(pkg, 'flow.branch.production') || process.env.PRODUCTION_BRANCH || 'production'
94
+ CI_SKIP: "[ci skip]",
95
+ RELEASE_CANDIDATE_TAG: "[MEP]",
96
+ ORIGIN: "origin",
97
+ get PRODUCTION_BRANCH() {
98
+ return get(pkg, "flow.branch.production") || process.env.PRODUCTION_BRANCH || "production";
143
99
  },
144
- get DEVELOP_BRANCH () {
145
- return get(pkg, 'flow.branch.develop') || process.env.DEVELOP_BRANCH || 'master'
100
+ get DEVELOP_BRANCH() {
101
+ return get(pkg, "flow.branch.develop") || process.env.DEVELOP_BRANCH || "master";
146
102
  },
147
- get OWNER () {
148
- return process.env.OWNER || owner
103
+ get OWNER() {
104
+ return process.env.OWNER || owner;
149
105
  },
150
- get DOCKER_REPOSITORY () {
151
- const {
152
- DOCKER_REPOSITORY,
153
- OWNER,
154
- PROJECT_NAME
155
- } = process.env
156
- return DOCKER_REPOSITORY || `${OWNER || owner}/${PROJECT_NAME || projectName}`
157
- },
158
- get SKIP_DEPLOY () {
159
- return toBool(process.env.SKIP_DEPLOY)
160
- },
161
- get SKIP_E2E () {
162
- return process.env.SKIP_E2E ? toBool(process.env.SKIP_E2E) : false
106
+ get DOCKER_REPOSITORY() {
107
+ const { DOCKER_REPOSITORY, OWNER, PROJECT_NAME } = process.env;
108
+ return DOCKER_REPOSITORY || `${OWNER || owner}/${PROJECT_NAME || projectName}`;
163
109
  },
164
110
  DOCKER_HUB_ID,
165
111
  DOCKER_HUB_PWD,
166
- HEROKU_APP,
167
112
  REF_COMMIT,
168
113
  GH_TOKEN,
169
- REPOSITORY_URL: get(pkg, 'repository.url', get(pkg, 'repository', REPOSITORY_URL)),
170
- SKIP_GITHUB_PUBLISH,
171
- GITHUB_PAGES_PATH,
114
+ SCM_TOKEN: GH_TOKEN || SCM_TOKEN,
115
+ REPOSITORY_URL: get(pkg, "repository.url", get(pkg, "repository", REPOSITORY_URL)),
172
116
  GIT_USER_NAME,
173
117
  GIT_USER_EMAIL,
174
118
  BUMP_METHOD,
175
119
  WORKSPACES: pkg.workspaces || [],
176
120
  ...getCI()
177
- }
121
+ };
178
122
  }
@@ -1,7 +1,7 @@
1
- import fs from 'fs'
1
+ import fs from "fs";
2
2
 
3
- export function getPackageJson () {
4
- const content = fs.readFileSync(`${process.cwd()}/package.json`, { encoding: 'utf8' })
3
+ export function getPackageJson() {
4
+ const content = fs.readFileSync(`${process.cwd()}/package.json`, { encoding: "utf8" });
5
5
 
6
- return JSON.parse(content)
6
+ return JSON.parse(content);
7
7
  }
@@ -1,9 +1,8 @@
1
- export async function getReleaseConfig () {
1
+ export async function getReleaseConfig() {
2
2
  try {
3
- return await import(`${process.cwd()}/release.config.mjs`)
3
+ return await import(`${process.cwd()}/release.config.mjs`);
4
4
  } catch (er) {
5
- // eslint-disable-next-line no-console
6
- console.log('Error while loading release.config.mjs', er)
7
- return {}
5
+ console.log("Error while loading release.config.mjs", er);
6
+ return {};
8
7
  }
9
8
  }
@@ -1,10 +1,10 @@
1
- export * from './cli/cli.js'
2
- export * from './cli/docker.js'
3
- export * from './cli/git.js'
4
- export * from './cli/lerna.js'
5
- export * from './cli/npm.js'
6
- export * from './cli/yarn.js'
7
- export * from './get-config.js'
8
- export * from './configure-git-workspace.js'
9
- export * from './get-package-json.js'
10
- export * from './run-command.js'
1
+ export * from "./cli/cli.js";
2
+ export * from "./cli/docker.js";
3
+ export * from "./cli/git.js";
4
+ export * from "./cli/lerna.js";
5
+ export * from "./cli/npm.js";
6
+ export * from "./cli/yarn.js";
7
+ export * from "./configure-git-workspace.js";
8
+ export * from "./get-config.js";
9
+ export * from "./get-package-json.js";
10
+ export * from "./run-command.js";
@@ -1,20 +1,21 @@
1
- import chalk from 'chalk'
2
- import figures from 'figures'
3
- import inquirer from 'inquirer'
4
- import Listr from 'listr'
5
- import { getReleaseConfig } from './get-release-config.js'
6
- import { getConfig } from './get-config.js'
1
+ import chalk from "chalk";
2
+ import figures from "figures";
3
+ import inquirer from "inquirer";
4
+ import Listr from "listr";
7
5
 
8
- function createTasksRunner (tasks, ctx) {
6
+ import { getConfig } from "./get-config.js";
7
+ import { getReleaseConfig } from "./get-release-config.js";
8
+
9
+ function createTasksRunner(tasks, ctx) {
9
10
  return new Listr(tasks, {
10
11
  concurrent: false,
11
- renderer: !ctx.verbose ? 'default' : 'verbose'
12
- }).run(ctx)
12
+ renderer: !ctx.verbose ? "default" : "verbose"
13
+ }).run(ctx);
13
14
  }
14
15
 
15
- export async function runCommand (klass, commander) {
16
+ export async function runCommand(klass, commander) {
16
17
  try {
17
- const config = getConfig()
18
+ const config = getConfig();
18
19
  let context = {
19
20
  ...getReleaseConfig(),
20
21
  ...config,
@@ -22,45 +23,42 @@ export async function runCommand (klass, commander) {
22
23
  config,
23
24
  logger: console,
24
25
  verbose: commander.verbose
25
- }
26
+ };
26
27
 
27
- // eslint-disable-next-line new-cap
28
- const command = new klass()
28
+ const command = new klass();
29
29
 
30
30
  // Map context from commander and current context
31
31
  if (command.mapContext) {
32
- context = command.mapContext(commander, context)
32
+ context = command.mapContext(commander, context);
33
33
  }
34
34
 
35
35
  // show prompts
36
36
  if (command.prompt) {
37
37
  context = {
38
38
  ...context,
39
- ...await inquirer.prompt(command.prompt(context))
40
- }
39
+ ...(await inquirer.prompt(command.prompt(context)))
40
+ };
41
41
  }
42
42
 
43
43
  // Verify conditions
44
- command.verifyConditions && command.verifyConditions(context)
44
+ command.verifyConditions && command.verifyConditions(context);
45
45
 
46
46
  // Get tasks
47
- const tasks = command.getTasks(context)
47
+ const tasks = command.getTasks(context);
48
48
 
49
49
  // Run tasks
50
- await createTasksRunner(tasks, context)
50
+ await createTasksRunner(tasks, context);
51
51
 
52
- command.success && command.success(context)
52
+ command.success && command.success(context);
53
53
  } catch (er) {
54
- // eslint-disable-next-line no-console
55
- console.error(chalk.red(figures.cross + ' ' + String(er)))
54
+ console.error(chalk.red(figures.cross + " " + String(er)));
56
55
  if (commander.verbose) {
57
- // eslint-disable-next-line no-console
58
- console.error(String(er.stack).replace(String(er), ''))
56
+ console.error(String(er.stack).replace(String(er), ""));
59
57
  }
60
- process.exit(-1)
58
+ process.exit(-1);
61
59
  }
62
60
  }
63
61
 
64
- process.on('unhandledRejection', (reason, p) => {
62
+ process.on("unhandledRejection", () => {
65
63
  // avoid extra promise rejection when using toObservable
66
- })
64
+ });
@@ -1,69 +1,65 @@
1
- import { beforeEach, describe, expect, it, jest } from '@jest/globals'
1
+ vi.mock("listr", () => {
2
+ return { default: vi.fn() };
3
+ });
2
4
 
3
- jest.unstable_mockModule('listr', () => {
4
- return { default: jest.fn() }
5
- })
6
- const { default: Listr } = await import('listr')
7
- const { runCommand } = await import('./run-command.js')
5
+ const { default: Listr } = await import("listr");
6
+ const { runCommand } = await import("./run-command.js");
8
7
 
9
- describe('runCommand', () => {
8
+ describe("runCommand", () => {
10
9
  beforeEach(() => {
11
10
  Listr.mockReturnValue({
12
- run () {
13
- }
14
- })
15
- })
16
- it('should call runCommand', async () => {
11
+ run() {}
12
+ });
13
+ });
14
+ it("should call runCommand", async () => {
17
15
  class Cmd {
18
- mapContext (ctx) {
16
+ mapContext(ctx) {
19
17
  return {
20
18
  ...ctx,
21
19
  test: true
22
- }
20
+ };
23
21
  }
24
22
 
25
- getTasks () {
26
- return []
23
+ getTasks() {
24
+ return [];
27
25
  }
28
26
  }
29
27
 
30
- jest.spyOn(Cmd.prototype, 'mapContext')
31
- jest.spyOn(Cmd.prototype, 'getTasks')
28
+ vi.spyOn(Cmd.prototype, "mapContext");
29
+ vi.spyOn(Cmd.prototype, "getTasks");
32
30
 
33
31
  await runCommand(Cmd, {
34
- prop: '1'
35
- })
32
+ prop: "1"
33
+ });
36
34
 
37
- expect(Cmd.prototype.mapContext).toHaveBeenCalledWith({ prop: '1' }, expect.any(Object))
35
+ expect(Cmd.prototype.mapContext).toHaveBeenCalledWith({ prop: "1" }, expect.any(Object));
38
36
  expect(Cmd.prototype.getTasks).toHaveBeenCalledWith({
39
- prop: '1',
37
+ prop: "1",
40
38
  test: true
41
- })
42
- })
43
- it('should call runCommand and catch error', async () => {
39
+ });
40
+ });
41
+ it("should call runCommand and catch error", async () => {
44
42
  class Cmd {
45
- mapContext (ctx) {
43
+ mapContext(ctx) {
46
44
  return {
47
45
  ...ctx,
48
46
  test: true
49
- }
47
+ };
50
48
  }
51
49
 
52
- getTasks () {
53
- throw new Error('Error')
50
+ getTasks() {
51
+ throw new Error("Error");
54
52
  }
55
53
  }
56
54
 
57
- jest.spyOn(console, 'error').mockReturnValue(undefined)
58
- jest.spyOn(process, 'exit').mockImplementation(() => {
59
- })
55
+ vi.spyOn(console, "error").mockReturnValue(undefined);
56
+ vi.spyOn(process, "exit").mockImplementation(() => {});
60
57
 
61
58
  await runCommand(Cmd, {
62
- prop: '1'
63
- })
59
+ prop: "1"
60
+ });
64
61
 
65
- // eslint-disable-next-line no-console
66
- expect(console.error).toHaveBeenCalled()
67
- expect(process.exit).toHaveBeenCalledWith(-1)
68
- })
69
- })
62
+ expect(console.error).toHaveBeenCalled();
63
+ expect(process.exit).toHaveBeenCalledWith(-1);
64
+ });
65
+ });
package/src/index.js CHANGED
@@ -1 +1,10 @@
1
- export * from './main.js'
1
+ import * as commands from "./commands/index.js";
2
+
3
+ export * from "./commands/release.js";
4
+ export * from "./common/index.js";
5
+ export * from "./semantic/define-config.js";
6
+ export * from "./semantic/utils/release-rules.js";
7
+ export * from "./semantic/utils/transform-writer.js";
8
+ export * from "./workflow/index.js";
9
+
10
+ export { commands };
@@ -0,0 +1,17 @@
1
+ import * as commitAnalyzerPlugins from "@semantic-release/commit-analyzer";
2
+
3
+ import { calculateSnapshotVersion } from "../utils/calculate-snapshot-version.js";
4
+
5
+ export async function analyzeCommits(pluginConfig, context) {
6
+ if (context.branch && context.branch.type !== "prerelease") {
7
+ return commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
8
+ }
9
+
10
+ const analyzedCommits = await commitAnalyzerPlugins.analyzeCommits(pluginConfig, context);
11
+ context.nextRelease = context.nextRelease || {};
12
+ context.nextRelease.type = analyzedCommits;
13
+ context.nextRelease.version = calculateSnapshotVersion(context);
14
+ context.lastRelease.version = null;
15
+
16
+ return "patch";
17
+ }
@@ -0,0 +1,29 @@
1
+ import { git } from "../../common/index.js";
2
+
3
+ /**
4
+ * Remove the tag from the git repository if the release is not a prerelease.
5
+ *
6
+ * Add runAfter property with the semantic-release plugin name to run after the fail task.
7
+ *
8
+ * @param pluginConfig {{runAfter: string}}
9
+ * @param context
10
+ * @return {Promise<void>}
11
+ */
12
+ export async function fail(pluginConfig, context) {
13
+ if (context.branch && context.branch.type !== "prerelease") {
14
+ const {
15
+ tagFormat,
16
+ config: { ORIGIN }
17
+ } = context;
18
+
19
+ try {
20
+ await git.push("--delete", ORIGIN, tagFormat.replace("${version}", context.nextRelease.version));
21
+ } catch {}
22
+
23
+ if (pluginConfig.runAfter) {
24
+ const { fail } = await import(pluginConfig.runAfter);
25
+
26
+ await fail(pluginConfig, context);
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,11 @@
1
+ import * as releaseNotesPlugins from "@semantic-release/release-notes-generator";
2
+
3
+ import { getConfig } from "../../common/index.js";
4
+
5
+ export async function generateNotes(pluginConfig, context) {
6
+ context.config = getConfig();
7
+
8
+ if (context.branch.type === "release") {
9
+ return releaseNotesPlugins.generateNotes(pluginConfig, context);
10
+ }
11
+ }
@@ -0,0 +1,38 @@
1
+ import { getConfig, lerna, npm, yarn } from "../../../common/index.js";
2
+ import { bumpPackagesVersion } from "../../utils/bump-packages-version.js";
3
+
4
+ export async function prepare(pluginConfig, context) {
5
+ context.config = getConfig();
6
+ const {
7
+ config: { HAS_YARN, HAS_LERNA, BUMP_METHOD, WORKSPACES },
8
+ logger
9
+ } = context;
10
+ const pkgManager = HAS_YARN ? yarn : npm;
11
+
12
+ logger.info(`Start bump version for all packages using method: ${BUMP_METHOD}`);
13
+
14
+ switch (BUMP_METHOD) {
15
+ case "native":
16
+ logger.info("Using package manager");
17
+ npm.newVersion(context.nextRelease.version);
18
+ break;
19
+ case "lerna":
20
+ if (HAS_LERNA) {
21
+ await lerna.newVersion(context.nextRelease.version);
22
+ }
23
+ break;
24
+ case "cmflow":
25
+ await bumpPackagesVersion(context.nextRelease.version, WORKSPACES);
26
+ await pkgManager.install();
27
+ break;
28
+ case "native:lerna":
29
+ default:
30
+ npm.newVersion(context.nextRelease.version);
31
+
32
+ if (HAS_LERNA) {
33
+ await lerna.newVersion(context.nextRelease.version);
34
+ }
35
+ }
36
+
37
+ logger.info("Bump version finished with success...");
38
+ }
@@ -0,0 +1,38 @@
1
+ import { configureGitWorkspace, getConfig, git } from "../../../common/index.js";
2
+
3
+ export async function prepare(pluginConfig, context) {
4
+ context.config = getConfig();
5
+ const { branch } = context;
6
+
7
+ if (branch.type === "release") {
8
+ context.config = getConfig();
9
+
10
+ const {
11
+ logger,
12
+ config: { CI_NAME, BUILD_NUMBER }
13
+ } = context;
14
+
15
+ logger.info("Prepare release");
16
+
17
+ configureGitWorkspace(context);
18
+
19
+ logger.info("Adding files to commit");
20
+ git.add("-A").sync();
21
+
22
+ logger.info("Get commit stage status");
23
+ git.status();
24
+
25
+ const revisionMessage = `${CI_NAME} build: ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`;
26
+
27
+ logger.info("Commit changes with revision message: ");
28
+ logger.info(revisionMessage);
29
+
30
+ git.commit("-m", revisionMessage).sync();
31
+
32
+ logger.success("Change committed");
33
+ return;
34
+ }
35
+
36
+ // avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
37
+ process.exit(0);
38
+ }
@@ -0,0 +1,22 @@
1
+ import { getConfig, npm, yarn } from "../../../common/index.js";
2
+
3
+ /**
4
+ * @param pluginConfig {{command: string}}
5
+ * @param context
6
+ * @return {Promise<void>}
7
+ */
8
+ export async function prepare(pluginConfig, context) {
9
+ context.config = getConfig();
10
+ const {
11
+ config: { HAS_YARN },
12
+ logger
13
+ } = context;
14
+
15
+ const pkgManager = HAS_YARN ? yarn : npm;
16
+
17
+ logger.info(`Start ${pluginConfig.command} task`);
18
+
19
+ await pkgManager.run(pluginConfig.command);
20
+
21
+ logger.info(`${pluginConfig.command} task finished with success...`);
22
+ }