@cmflow/cli 1.1.0 → 2.0.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 (124) hide show
  1. package/.prettierignore +5 -0
  2. package/.prettierrc +10 -0
  3. package/README.md +130 -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 +36 -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/conditional.js +25 -0
  64. package/src/semantic/core/fail.js +21 -0
  65. package/src/semantic/core/generate-notes.js +11 -0
  66. package/src/semantic/core/prepare/bump-version.js +38 -0
  67. package/src/semantic/core/prepare/post.js +38 -0
  68. package/src/semantic/core/prepare/run.js +22 -0
  69. package/src/semantic/core/success.js +33 -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 +15 -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,62 +0,0 @@
1
- import { beforeEach, describe, expect, it, jest } from '@jest/globals'
2
-
3
- jest.unstable_mockModule('execa', () => {
4
- const execaMock = jest.fn()
5
- execaMock.sync = jest.fn()
6
- return { default: execaMock }
7
- })
8
- const { default: execa } = await import('execa')
9
-
10
- const { Cli } = await import('./cli.js')
11
- const { heroku } = await import('./heroku.js')
12
-
13
- execa.sync.mockImplementation((...args) => {
14
- return {
15
- stdout: `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
16
- }
17
- })
18
-
19
- execa.mockReturnValue({})
20
-
21
- describe('HerokuCli', () => {
22
- beforeEach(() => {
23
- jest.spyOn(Cli, 'getRaw').mockImplementation((...args) => {
24
- return `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
25
- })
26
- })
27
- describe('containerLogin', () => {
28
- it('should run cmd', () => {
29
- const result = heroku.containerLogin('arg').sync()
30
-
31
- expect(result.stdout).toEqual('CMD: heroku container:login arg')
32
- expect(execa.sync).toHaveBeenCalledWith('heroku', ['container:login', 'arg'], {
33
- cwd: process.cwd(),
34
- stdio: 'inherit'
35
- })
36
- })
37
- })
38
-
39
- describe('containerPush', () => {
40
- it('should run cmd', () => {
41
- const result = heroku.containerPush('arg').sync()
42
-
43
- expect(result.stdout).toEqual('CMD: heroku container:push arg')
44
- expect(execa.sync).toHaveBeenCalledWith('heroku', ['container:push', 'arg'], {
45
- cwd: process.cwd(),
46
- stdio: 'inherit'
47
- })
48
- })
49
- })
50
-
51
- describe('containerRelease', () => {
52
- it('should run cmd', () => {
53
- const result = heroku.containerRelease('arg').sync()
54
-
55
- expect(result.stdout).toEqual('CMD: heroku container:release arg')
56
- expect(execa.sync).toHaveBeenCalledWith('heroku', ['container:release', 'arg'], {
57
- cwd: process.cwd(),
58
- stdio: 'inherit'
59
- })
60
- })
61
- })
62
- })
package/src/main.js DELETED
@@ -1,10 +0,0 @@
1
- import * as commands from './commands/index.js'
2
-
3
- export * from './workflow/index.js'
4
- export * from './common/index.js'
5
- export * from './commands/release.js'
6
- export * from './semantic-release/get-semantic-config.js'
7
-
8
- export {
9
- commands
10
- }
@@ -1,14 +0,0 @@
1
- import * as commitAnalyzerPlugins from '@semantic-release/commit-analyzer'
2
- import { calculateSnapshotVersion } from '../utils/calculate-snapshot-version.js'
3
-
4
- export async function analyzeCommits (pluginConfig, context) {
5
- if (context.branch && context.branch.type !== 'prerelease') {
6
- return commitAnalyzerPlugins.analyzeCommits(pluginConfig, context)
7
- }
8
- const analyzedCommits = await commitAnalyzerPlugins.analyzeCommits(pluginConfig, context)
9
- context.nextRelease = context.nextRelease || {}
10
- context.nextRelease.type = analyzedCommits
11
- context.nextRelease.version = calculateSnapshotVersion(context)
12
- context.lastRelease.version = null
13
- return 'patch'
14
- }
@@ -1,16 +0,0 @@
1
- import * as githubPlugins from '@semantic-release/github'
2
- import { git } from '../../common/index.js'
3
-
4
- export async function fail (pluginConfig, context) {
5
- if (context.branch && context.branch.type !== 'prerelease') {
6
- const { tagFormat, config: { ORIGIN } } = context
7
-
8
- try {
9
- // eslint-disable-next-line no-template-curly-in-string
10
- await git.push('--delete', ORIGIN, tagFormat.replace('${version}', context.nextRelease.version))
11
- } catch (er) {
12
- }
13
-
14
- await githubPlugins.fail(pluginConfig, context)
15
- }
16
- }
@@ -1,12 +0,0 @@
1
- import * as releaseNotesPlugins from '@semantic-release/release-notes-generator'
2
- import { getConfig, npm, yarn } from '../../common/index.js'
3
-
4
- export async function generateNotes (pluginConfig, context) {
5
- context.config = getConfig()
6
- if (context.branch.type === 'release' && !context.config.SKIP_GITHUB_PUBLISH) {
7
- if (context.config.HAS_BUILD_CHANGELOG) {
8
- await (context.config.HAS_YARN ? yarn : npm).run('build_changelog')
9
- }
10
- return releaseNotesPlugins.generateNotes(pluginConfig, context)
11
- }
12
- }
@@ -1,8 +0,0 @@
1
- export * from './verify-conditions.js'
2
- export * from './analyze-commits.js'
3
- export * from './verify-release.js'
4
- export * from './generate-notes.js'
5
- export * from './prepare.js'
6
- export * from './publish.js'
7
- export * from './success.js'
8
- export * from './fail.js'
@@ -1,114 +0,0 @@
1
- import { dockerPublish } from '../utils/docker-publish.js'
2
- import { configureGitWorkspace, getConfig, git, lerna, npm, yarn } from '../../common/index.js'
3
- import { bumpPackagesVersion } from '../utils/bump-packages-version.js'
4
-
5
- async function gitPrepareRelease (pluginConfig, context) {
6
- context.config = getConfig()
7
- const {
8
- logger,
9
- config: {
10
- CI_NAME,
11
- BUILD_NUMBER
12
- }
13
- } = context
14
-
15
- logger.info('Adding files to commit')
16
- git.add('-A').sync()
17
-
18
- logger.info('Get commit stage status')
19
- git.status()
20
-
21
- const revisionMessage = `${CI_NAME} build: ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`
22
-
23
- logger.info('Commit changes with revision message: ')
24
- logger.info(revisionMessage)
25
-
26
- git.commit('-m', revisionMessage).sync()
27
-
28
- logger.success('Change committed')
29
- }
30
-
31
- export async function prepare (pluginConfig, context) {
32
- context.config = getConfig()
33
- const {
34
- branch,
35
- config: {
36
- RELEASE_CANDIDATE_TAG,
37
- HAS_BUILD,
38
- HAS_E2E,
39
- E2E_CMD,
40
- SKIP_DEPLOY,
41
- SKIP_E2E,
42
- SKIP_GITHUB_PUBLISH,
43
- HAS_YARN,
44
- HAS_LERNA,
45
- BUMP_METHOD,
46
- WORKSPACES
47
- },
48
- logger
49
- } = context
50
- const pkgManager = HAS_YARN ? yarn : npm
51
-
52
- logger.info(`Start bump version for all packages using method: ${BUMP_METHOD}`)
53
-
54
- switch (BUMP_METHOD) {
55
- case 'native':
56
- logger.info('Using package manager')
57
- npm.newVersion(context.nextRelease.version)
58
- break
59
- case 'lerna':
60
- if (HAS_LERNA) {
61
- await lerna.newVersion(context.nextRelease.version)
62
- }
63
- break
64
- case 'cmflow':
65
- await bumpPackagesVersion(context.nextRelease.version, WORKSPACES)
66
- await pkgManager.install()
67
- break
68
- case 'native:lerna':
69
- default:
70
- npm.newVersion(context.nextRelease.version)
71
-
72
- if (HAS_LERNA) {
73
- await lerna.newVersion(context.nextRelease.version)
74
- }
75
- }
76
-
77
- logger.info('Bump version finished with success...')
78
-
79
- if (HAS_BUILD && !SKIP_DEPLOY) {
80
- logger.info('Start build task')
81
- await pkgManager.run('build')
82
- logger.info('Build task finished with success...')
83
- } else {
84
- logger.info('Skipping build task')
85
- }
86
-
87
- if (HAS_E2E && !SKIP_DEPLOY && !SKIP_E2E) {
88
- logger.info('Start test_e2e task')
89
- await pkgManager.run(E2E_CMD || 'test_e2e')
90
- logger.info('test_e2e task finished with success...')
91
- } else {
92
- logger.info('Skipping test_e2e task')
93
- }
94
-
95
- if (!SKIP_GITHUB_PUBLISH) {
96
- if (branch.type === 'release') {
97
- logger.info('Prepare release')
98
- configureGitWorkspace(context)
99
- return gitPrepareRelease(pluginConfig, context)
100
- }
101
-
102
- const lastCommitMessage = git.getLastCommitMsg()
103
- logger.info('Last commit message:', lastCommitMessage)
104
- if (lastCommitMessage.includes(RELEASE_CANDIDATE_TAG)) {
105
- process.exit(0)
106
- }
107
- }
108
-
109
- if (!SKIP_DEPLOY) {
110
- await dockerPublish(context)
111
- }
112
- // avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
113
- process.exit(0)
114
- }
@@ -1,17 +0,0 @@
1
- import * as githubPlugins from '@semantic-release/github'
2
- import { dockerPublish } from '../utils/docker-publish.js'
3
- import { ghPagesPublish } from '../utils/ghpages-publish.js'
4
-
5
- export async function publish (pluginConfig, context) {
6
- const { branch, env: { SKIP_GITHUB_PUBLISH, GITHUB_PAGES_PATH } } = context
7
-
8
- if (!SKIP_GITHUB_PUBLISH && branch.type === 'release') {
9
- await githubPlugins.publish(pluginConfig, context)
10
- }
11
-
12
- if (GITHUB_PAGES_PATH && branch.type === 'release') {
13
- await ghPagesPublish(context)
14
- }
15
-
16
- await dockerPublish(context)
17
- }
@@ -1,32 +0,0 @@
1
- import * as githubPlugins from '@semantic-release/github'
2
- import { dockerCleanTags } from '../utils/docker-clean-tags.js'
3
- import { getConfig } from '../../common/get-config.js'
4
- import { git } from '../../common/index.js'
5
-
6
- async function githubSuccess (pluginConfig, context) {
7
- const { logger, config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH } } = context
8
- await git.push('--quiet', '--set-upstream', ORIGIN, PRODUCTION_BRANCH)
9
-
10
- if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
11
- logger.start(`Reset HEAD of ${ORIGIN}/${DEVELOP_BRANCH} branch to HEAD of ${ORIGIN}/${PRODUCTION_BRANCH} `)
12
- await git.push('-f', ORIGIN, `refs/remotes/${ORIGIN}/${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`)
13
- logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`)
14
- }
15
-
16
- await githubPlugins.success(pluginConfig, context)
17
- }
18
-
19
- export async function success (pluginConfig, context) {
20
- context.config = getConfig()
21
- const { branch, config: { SKIP_GITHUB_PUBLISH } } = context
22
-
23
- if (branch.type !== 'prerelease' && !SKIP_GITHUB_PUBLISH) {
24
- await githubSuccess(pluginConfig, context)
25
- }
26
-
27
- try {
28
- await dockerCleanTags(context)
29
- } catch (er) {
30
- context.logger.warn(er)
31
- }
32
- }
@@ -1,30 +0,0 @@
1
- import chalk from 'chalk'
2
- import * as githubPlugins from '@semantic-release/github'
3
- import { getConfig, git } from '../../common/index.js'
4
-
5
- export function verifyConditions (pluginConfig, context) {
6
- context.config = getConfig()
7
- if (pluginConfig.dryRun) {
8
- return
9
- }
10
-
11
- const { branch, config: { USER, EMAIL, ORIGIN } } = context
12
-
13
- if (USER && EMAIL) {
14
- context.logger.info('Configure git with username')
15
-
16
- git.config('--global', 'user.name', USER)
17
- git.config('--global', 'user.email', EMAIL)
18
-
19
- context.logger.info('Configure git branch')
20
- context.logger.success('Workspace is correctly configured')
21
- } else {
22
- context.logger.error(chalk.red('Ignore git configuration (Empty GIT_USER_EMAIL or/and GIT_USER_NAME variables)'))
23
- process.exit(1)
24
- }
25
- git.fetch().sync()
26
- git.checkout(branch.name).sync()
27
- git.branch(`--set-upstream-to=${ORIGIN}/${branch.name}`, branch.name).sync()
28
-
29
- return githubPlugins.verifyConditions(pluginConfig, context)
30
- }
@@ -1,9 +0,0 @@
1
- import { displayPackageInfo } from '../utils/display-package-info.js'
2
- import { displayReleaseInfo } from '../utils/display-release-info.js'
3
- import { getConfig } from '../../common/index.js'
4
-
5
- export function verifyRelease (pluginConfig, context) {
6
- context.config = getConfig()
7
- displayPackageInfo(context)
8
- displayReleaseInfo(context)
9
- }
@@ -1,115 +0,0 @@
1
- import { getConfig } from '../common/get-config.js'
2
- import { WORKFLOW_CONFIGURATION } from '../workflow/index.js'
3
-
4
- const releaseRules = WORKFLOW_CONFIGURATION.map(({ label, ...props }) => props)
5
- const commitTypeMapping = WORKFLOW_CONFIGURATION.reduce((obj, { type, label }) => {
6
- return {
7
- ...obj,
8
- [type]: label
9
- }
10
- }, {})
11
-
12
- const transformCommitType = commit => {
13
- if (commitTypeMapping[commit.type]) {
14
- return commitTypeMapping[commit.type]
15
- }
16
-
17
- return commitTypeMapping.default
18
- }
19
-
20
- const transform = (commit, context) => {
21
- const issues = []
22
-
23
- commit.notes.forEach(note => {
24
- note.title = 'BREAKING CHANGES'
25
- })
26
-
27
- commit.type = transformCommitType(commit)
28
-
29
- if (commit.message && commit.message.match(/^[\w-]+$/i)) {
30
- return
31
- }
32
-
33
- if (commit.subject) {
34
- commit.subject = commit.subject.replace('[MEP]', '')
35
- }
36
-
37
- if (commit.scope === '*') {
38
- commit.scope = ''
39
- }
40
-
41
- if (typeof commit.hash === 'string') {
42
- commit.shortHash = commit.hash.substring(0, 7)
43
- }
44
-
45
- if (typeof commit.subject === 'string') {
46
- let url = context.repository
47
- ? `${context.host}/${context.owner}/${context.repository}`
48
- : context.repoUrl
49
- if (url) {
50
- url = `${url}/issues/`
51
- // Issue URLs.
52
- commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
53
- issues.push(issue)
54
- return `[#${issue}](${url}${issue})`
55
- })
56
- }
57
- if (context.host) {
58
- // User URLs.
59
- commit.subject = commit.subject.replace(
60
- /\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g,
61
- (_, username) => {
62
- if (username.includes('/')) {
63
- return `@${username}`
64
- }
65
-
66
- return `[@${username}](${context.host}/${username})`
67
- }
68
- )
69
- }
70
- }
71
-
72
- // remove references that already appear in the subject
73
- commit.references = commit.references.filter(reference => {
74
- if (issues.indexOf(reference.issue) === -1) {
75
- return true
76
- }
77
-
78
- return false
79
- })
80
-
81
- return commit
82
- }
83
-
84
- export function getSemanticConfig () {
85
- const config = getConfig()
86
-
87
- return {
88
- noCi: config.PRODUCTION_BRANCH !== config.BRANCH_NAME,
89
- branches: [
90
- {
91
- name: config.PRODUCTION_BRANCH,
92
- channel: 'release'
93
- },
94
- // Use this hack to always run semantic-release (as prerelease for feature/fix branch)
95
- {
96
- name: config.BRANCH_NAME,
97
- channel: 'prerelease',
98
- prerelease: true
99
- }
100
- ],
101
- verifyConditions: ['@cmflow/cli/semantic'],
102
- analyzeCommits: ['@cmflow/cli/semantic'],
103
- verifyRelease: ['@cmflow/cli/semantic'],
104
- generateNotes: ['@cmflow/cli/semantic'],
105
- prepare: ['@cmflow/cli/semantic'],
106
- publish: ['@cmflow/cli/semantic'],
107
- success: ['@cmflow/cli/semantic'],
108
- fail: ['@cmflow/cli/semantic'],
109
- releaseRules,
110
- parserOpts: {
111
- noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES']
112
- },
113
- writerOpts: { transform }
114
- }
115
- }
@@ -1,51 +0,0 @@
1
- import globby from 'globby'
2
- import fs from 'fs-extra'
3
- import { dirname } from 'path'
4
-
5
- const PACKAGE_JSON_PROPS = ['dependencies', 'devDependencies', 'peerDependencies']
6
-
7
- export async function bumpPackagesVersion (version, workspaces, cwd = process.cwd()) {
8
- const patterns = workspaces.map((path) => `${path}/package.json`).concat('package.json')
9
-
10
- const files = await globby(patterns, {
11
- cwd,
12
- absolute: true
13
- })
14
-
15
- const names = new Set()
16
-
17
- const packages = await Promise.all(files.map(async (file) => {
18
- const pkg = await fs.readJson(file)
19
-
20
- names.add(pkg.name)
21
-
22
- return {
23
- file,
24
- pkg
25
- }
26
- }))
27
-
28
- return Promise.all(packages.map(({
29
- pkg,
30
- file
31
- }) => {
32
- pkg.version = version
33
-
34
- PACKAGE_JSON_PROPS.forEach((key) => bumpDependencies(pkg, key, version, names))
35
-
36
- fs.ensureDirSync(dirname(file))
37
- return fs.writeFile(file, JSON.stringify(pkg, null, 2), { encoding: 'utf8' })
38
- }))
39
- }
40
-
41
- function bumpDependencies (pkg, key, version, names) {
42
- pkg[key] = pkg[key] || {}
43
-
44
- if (pkg[key]) {
45
- names.forEach((name) => {
46
- if (pkg[key][name] && !pkg[key][name].startsWith('workspace:')) {
47
- pkg[key][name] = version
48
- }
49
- })
50
- }
51
- }
@@ -1,78 +0,0 @@
1
- import { bumpPackagesVersion } from './bump-packages-version.js'
2
- import path from 'path'
3
- import fs from 'fs-extra'
4
- import { jest, describe, it, beforeEach, expect } from '@jest/globals'
5
- import * as url from 'url'
6
- const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
7
-
8
- describe('bumpPackagesVersion()', () => {
9
- beforeEach(() => {
10
- jest.resetAllMocks()
11
- jest.spyOn(fs, 'writeFile').mockResolvedValue()
12
- jest.spyOn(fs, 'ensureDirSync').mockResolvedValue()
13
- })
14
-
15
- it('should upgrade dependencies (package manager: npm/yarn)', async () => {
16
- await bumpPackagesVersion('1.1.0', [
17
- 'packages/*'
18
- ], path.join(__dirname, '__mock__/test1'))
19
-
20
- const calls = fs.writeFile.mock.calls.sort(([a], [b]) => a > b ? -1 : 1)
21
-
22
- expect(JSON.parse(calls[0][1])).toEqual({
23
- version: '1.1.0',
24
- name: '@package/b',
25
- dependencies: {},
26
- devDependencies: {},
27
- peerDependencies: {}
28
- })
29
-
30
- expect(JSON.parse(calls[1][1])).toEqual({
31
- name: '@package/a',
32
- version: '1.1.0',
33
- dependencies: { '@package/b': '1.1.0' },
34
- devDependencies: {},
35
- peerDependencies: {}
36
- })
37
-
38
- expect(JSON.parse(calls[2][1])).toEqual({
39
- name: '@package/root',
40
- version: '1.1.0',
41
- dependencies: {},
42
- devDependencies: {},
43
- peerDependencies: {}
44
- })
45
- })
46
- it('should upgrade dependencies (package manager: yarn berry)', async () => {
47
- await bumpPackagesVersion('1.1.0', [
48
- 'packages/*'
49
- ], path.join(__dirname, '__mock__/test2'))
50
- const calls = fs.writeFile.mock.calls.sort(([a], [b]) => a > b ? -1 : 1)
51
-
52
- expect(JSON.parse(calls[0][1])).toEqual({
53
- dependencies: {},
54
- devDependencies: {},
55
- name: '@package/b',
56
- peerDependencies: {},
57
- version: '1.1.0'
58
- })
59
-
60
- expect(JSON.parse(calls[1][1])).toEqual({
61
- dependencies: {
62
- '@package/b': 'workspace:*'
63
- },
64
- devDependencies: {},
65
- name: '@package/a',
66
- peerDependencies: {},
67
- version: '1.1.0'
68
- })
69
-
70
- expect(JSON.parse(calls[2][1])).toEqual({
71
- dependencies: {},
72
- devDependencies: {},
73
- name: '@package/root',
74
- peerDependencies: {},
75
- version: '1.1.0'
76
- })
77
- })
78
- })
@@ -1,10 +0,0 @@
1
- import semver from 'semver'
2
- import { getConfig, git } from '../../common/index.js'
3
-
4
- export function calculateSnapshotVersion (context) {
5
- context.config = getConfig()
6
- const { nextRelease: { type }, lastRelease, config: { REF_COMMIT } } = context
7
- const { major, minor, patch } = semver.parse(lastRelease.version)
8
-
9
- return `${semver.inc(`${major}.${minor}.${patch}`, type)}-beta${git.getCommitTag(REF_COMMIT)}`
10
- }
@@ -1,69 +0,0 @@
1
- import { beforeEach, describe, expect, it, jest } from '@jest/globals'
2
-
3
- jest.unstable_mockModule('../../common/index.js', () => {
4
- return {
5
- git: {
6
- getCommitTag: jest.fn()
7
- },
8
- getConfig: jest.fn()
9
- }
10
- })
11
- const { git, getConfig } = await import('../../common/index.js')
12
- const { calculateSnapshotVersion } = await import('./calculate-snapshot-version.js')
13
-
14
- describe('calculateSnapshotVersion', () => {
15
- beforeEach(() => {
16
- git.getCommitTag.mockReturnValue('13246u')
17
- getConfig.mockReturnValue({
18
- DEPLOY_ON_DOCKER: true,
19
- PRODUCTION_BRANCH: 'production',
20
- DOCKER_REPOSITORY: 'owner',
21
- DOCKER_HUB_ID: 'login',
22
- DOCKER_HUB_PWD: 'password'
23
- })
24
- })
25
- it('should return the snapshot version', () => {
26
- const context = {
27
- nextRelease: { type: 'patch' },
28
- lastRelease: {
29
- version: '1.0.0'
30
- }
31
- }
32
-
33
- const version = calculateSnapshotVersion(context)
34
- expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT)
35
- expect(version).toEqual('1.0.1-beta13246u')
36
- })
37
-
38
- it('should return the snapshot version', () => {
39
- const context = {
40
- nextRelease: { type: 'minor' },
41
- lastRelease: {
42
- version: '1.0.0'
43
- },
44
- config: {
45
- REF_COMMIT: 'REF_COMMIT'
46
- }
47
- }
48
-
49
- const version = calculateSnapshotVersion(context)
50
- expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT)
51
- expect(version).toEqual('1.1.0-beta13246u')
52
- })
53
-
54
- it('should return the snapshot version', () => {
55
- const context = {
56
- nextRelease: { type: 'major' },
57
- lastRelease: {
58
- version: '1.0.0'
59
- },
60
- config: {
61
- REF_COMMIT: 'REF_COMMIT'
62
- }
63
- }
64
-
65
- const version = calculateSnapshotVersion(context)
66
- expect(git.getCommitTag).toHaveBeenCalledWith(context.config.REF_COMMIT)
67
- expect(version).toEqual('2.0.0-beta13246u')
68
- })
69
- })
@@ -1,11 +0,0 @@
1
- import { logSection } from './log-section.js'
2
-
3
- export function displayPackageInfo (context) {
4
- logSection('Package Info', context)
5
- context.logger.info('Name : ' + context.config.PROJECT_NAME)
6
- context.logger.info('Version : ' + context.lastRelease.version)
7
- context.logger.info('Repository : ' + context.config.REPOSITORY_URL)
8
- context.logger.info('Branch : ' + context.branch.name)
9
- context.logger.info('Tag : ' + context.lastRelease.gitTag)
10
- context.logger.info('GitHead : ' + context.lastRelease.gitHead)
11
- }