@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,135 +1,133 @@
1
- import { beforeEach, describe, expect, it, jest } from '@jest/globals'
1
+ vi.mock("axios", () => {
2
+ return { default: vi.fn() };
3
+ });
4
+ vi.mock("execa", () => {
5
+ const execaMock = vi.fn();
6
+ execaMock.sync = vi.fn();
7
+ return { default: execaMock };
8
+ });
9
+ const { default: execa } = await import("execa");
10
+ const { default: axios } = await import("axios");
11
+ const { docker } = await import("./docker.js");
12
+ const { Cli } = await import("./cli.js");
2
13
 
3
- jest.unstable_mockModule('axios', () => {
4
- return { default: jest.fn() }
5
- })
6
- jest.unstable_mockModule('execa', () => {
7
- const execaMock = jest.fn()
8
- execaMock.sync = jest.fn()
9
- return { default: execaMock }
10
- })
11
- const { default: execa } = await import('execa')
12
- const { default: axios } = await import('axios')
13
- const { docker } = await import('./docker.js')
14
- const { Cli } = await import('./cli.js')
15
-
16
- execa.mockReturnValue({})
14
+ execa.mockReturnValue({});
17
15
 
18
16
  execa.sync.mockImplementation((...args) => {
19
17
  return {
20
- stdout: `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
21
- }
22
- })
18
+ stdout: `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
19
+ };
20
+ });
23
21
 
24
- describe('DockerCli', () => {
22
+ describe("DockerCli", () => {
25
23
  beforeEach(() => {
26
- jest.spyOn(Cli, 'getRaw').mockImplementation((...args) => {
27
- return `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
28
- })
29
- })
30
- describe('tag', () => {
31
- it('should run tag cmd', () => {
32
- const result = docker.tag('tag-arg', 'image')
24
+ vi.spyOn(Cli, "getRaw").mockImplementation((...args) => {
25
+ return `CMD: ${[].concat(...args.filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
26
+ });
27
+ });
28
+ describe("tag", () => {
29
+ it("should run tag cmd", () => {
30
+ const result = docker.tag("tag-arg", "image");
33
31
 
34
- expect(result).toEqual('CMD: docker tag tag-arg image')
35
- expect(Cli.getRaw).toHaveBeenCalledWith('docker', ['tag', 'tag-arg', 'image'], {
32
+ expect(result).toEqual("CMD: docker tag tag-arg image");
33
+ expect(Cli.getRaw).toHaveBeenCalledWith("docker", ["tag", "tag-arg", "image"], {
36
34
  cwd: process.cwd()
37
- })
38
- })
39
- })
40
- describe('login', () => {
41
- it('should run login cmd', () => {
42
- const result = docker.login('login-arg')
35
+ });
36
+ });
37
+ });
38
+ describe("login", () => {
39
+ it("should run login cmd", () => {
40
+ const result = docker.login("login-arg");
43
41
 
44
- expect(result.stdout).toEqual('CMD: docker login login-arg')
45
- expect(execa.sync).toHaveBeenCalledWith('docker', ['login', 'login-arg'], {
42
+ expect(result.stdout).toEqual("CMD: docker login login-arg");
43
+ expect(execa.sync).toHaveBeenCalledWith("docker", ["login", "login-arg"], {
46
44
  cwd: process.cwd(),
47
- stdio: 'inherit'
48
- })
49
- })
50
- })
51
- describe('push', () => {
52
- it('should run push cmd', async () => {
53
- await docker.push('push-arg')
45
+ stdio: "inherit"
46
+ });
47
+ });
48
+ });
49
+ describe("push", () => {
50
+ it("should run push cmd", async () => {
51
+ await docker.push("push-arg");
54
52
 
55
- expect(execa).toHaveBeenCalledWith('docker', ['push', 'push-arg'], {
53
+ expect(execa).toHaveBeenCalledWith("docker", ["push", "push-arg"], {
56
54
  cwd: process.cwd(),
57
- stdio: 'inherit'
58
- })
59
- })
60
- })
61
- describe('getToken', () => {
55
+ stdio: "inherit"
56
+ });
57
+ });
58
+ });
59
+ describe("getToken", () => {
62
60
  beforeEach(() => {
63
- axios.mockReturnValue({ data: { token: 'token' } })
64
- })
65
- it('should get token', async () => {
66
- const token = await docker.getToken('username', 'password')
61
+ axios.mockReturnValue({ data: { token: "token" } });
62
+ });
63
+ it("should get token", async () => {
64
+ const token = await docker.getToken("username", "password");
67
65
 
68
66
  expect(axios).toHaveBeenCalledWith({
69
- method: 'POST',
70
- url: 'https://hub.docker.com/v2/users/login/',
67
+ method: "POST",
68
+ url: "https://hub.docker.com/v2/users/login/",
71
69
  headers: {
72
- Accept: 'application/json',
73
- 'Content-Type': 'application/json'
70
+ Accept: "application/json",
71
+ "Content-Type": "application/json"
74
72
  },
75
73
  data: {
76
- password: 'password',
77
- username: 'username'
74
+ password: "password",
75
+ username: "username"
78
76
  }
79
- })
80
- expect(token).toEqual('token')
81
- })
82
- })
83
- describe('getTags', () => {
77
+ });
78
+ expect(token).toEqual("token");
79
+ });
80
+ });
81
+ describe("getTags", () => {
84
82
  beforeEach(() => {
85
83
  axios.mockReturnValue({
86
84
  data: {
87
85
  results: [
88
86
  {
89
- name: 'branch-1',
90
- last_updated: new Date('2020-06-01')
87
+ name: "branch-1",
88
+ last_updated: new Date("2020-06-01")
91
89
  }
92
90
  ]
93
91
  }
94
- })
95
- })
96
- it('should get token', async () => {
92
+ });
93
+ });
94
+ it("should get token", async () => {
97
95
  const tags = await docker.getTags({
98
- token: 'token',
99
- repository: 'owner'
100
- })
96
+ token: "token",
97
+ repository: "owner"
98
+ });
101
99
 
102
100
  expect(tags).toEqual([
103
101
  {
104
- name: 'branch-1',
105
- last_updated: new Date('2020-06-01')
102
+ name: "branch-1",
103
+ last_updated: new Date("2020-06-01")
106
104
  }
107
- ])
105
+ ]);
108
106
  expect(axios).toHaveBeenCalledWith({
109
- method: 'GET',
110
- url: 'https://hub.docker.com/v2/repositories/owner/tags/?page=1&page_size=500',
107
+ method: "GET",
108
+ url: "https://hub.docker.com/v2/repositories/owner/tags/?page=1&page_size=500",
111
109
  headers: {
112
- Accept: 'application/json',
113
- Authorization: 'JWT token'
110
+ Accept: "application/json",
111
+ Authorization: "JWT token"
114
112
  }
115
- })
116
- })
117
- })
118
- describe('deleteTag', () => {
119
- it('should run delete Tag', async () => {
120
- await docker.deleteTag('my-tag', {
121
- token: 'token',
122
- repository: 'owner'
123
- })
113
+ });
114
+ });
115
+ });
116
+ describe("deleteTag", () => {
117
+ it("should run delete Tag", async () => {
118
+ await docker.deleteTag("my-tag", {
119
+ token: "token",
120
+ repository: "owner"
121
+ });
124
122
 
125
123
  expect(axios).toHaveBeenCalledWith({
126
124
  headers: {
127
- Accept: 'application/json',
128
- Authorization: 'JWT token'
125
+ Accept: "application/json",
126
+ Authorization: "JWT token"
129
127
  },
130
- method: 'DELETE',
131
- url: 'https://hub.docker.com/v2/repositories/owner/tags/my-tag/'
132
- })
133
- })
134
- })
135
- })
128
+ method: "DELETE",
129
+ url: "https://hub.docker.com/v2/repositories/owner/tags/my-tag/"
130
+ });
131
+ });
132
+ });
133
+ });
@@ -1,130 +1,121 @@
1
- import { Cli } from './cli.js'
1
+ import { Cli } from "./cli.js";
2
2
 
3
3
  class GitCli extends Cli {
4
- constructor () {
5
- super('git')
4
+ constructor() {
5
+ super("git");
6
6
  }
7
7
 
8
- init (...args) {
9
- return this.run('init', ...args)
8
+ init(...args) {
9
+ return this.run("init", ...args);
10
10
  }
11
11
 
12
- add (...args) {
13
- return this.run('add', ...args)
12
+ add(...args) {
13
+ return this.run("add", ...args);
14
14
  }
15
15
 
16
- status (...args) {
17
- return this.sync('status', ...args)
16
+ status(...args) {
17
+ return this.sync("status", ...args);
18
18
  }
19
19
 
20
- branch (...args) {
21
- return this.run('branch', ...args)
20
+ branch(...args) {
21
+ return this.run("branch", ...args);
22
22
  }
23
23
 
24
- clean (...args) {
25
- return this.run('clean', ...args)
24
+ clean(...args) {
25
+ return this.run("clean", ...args);
26
26
  }
27
27
 
28
- config (...args) {
29
- return this.run('config', ...args).get()
28
+ config(...args) {
29
+ return this.run("config", ...args).get();
30
30
  }
31
31
 
32
- checkout (...args) {
33
- return this.run('checkout', ...args)
32
+ checkout(...args) {
33
+ return this.run("checkout", ...args);
34
34
  }
35
35
 
36
- commit (...args) {
37
- return this.run('commit', ...args)
36
+ commit(...args) {
37
+ return this.run("commit", ...args);
38
38
  }
39
39
 
40
- fetch (...args) {
41
- return this.run('fetch', ...args)
40
+ fetch(...args) {
41
+ return this.run("fetch", ...args);
42
42
  }
43
43
 
44
- prune (...args) {
45
- return this.run('prune', ...args)
44
+ prune(...args) {
45
+ return this.run("prune", ...args);
46
46
  }
47
47
 
48
- merge (...args) {
49
- return this.sync('merge', ...args)
48
+ merge(...args) {
49
+ return this.sync("merge", ...args);
50
50
  }
51
51
 
52
- reset (...args) {
53
- return this.sync('reset', ...args)
52
+ reset(...args) {
53
+ return this.sync("reset", ...args);
54
54
  }
55
55
 
56
- remote (...args) {
57
- return this.run('remote', ...args)
56
+ remote(...args) {
57
+ return this.run("remote", ...args);
58
58
  }
59
59
 
60
- rebase (...args) {
61
- return this.run('rebase', ...args)
60
+ rebase(...args) {
61
+ return this.run("rebase", ...args);
62
62
  }
63
63
 
64
- getCommitTag (ref = 'HEAD') {
65
- return this.get('rev-parse', '--short', ref)
64
+ getCommitTag(ref = "HEAD") {
65
+ return this.get("rev-parse", "--short", ref);
66
66
  }
67
67
 
68
- getBranchName (ref = 'HEAD') {
69
- return this.get('rev-parse', '--abbrev-ref', ref)
68
+ getBranchName(ref = "HEAD") {
69
+ return this.get("rev-parse", "--abbrev-ref", ref);
70
70
  }
71
71
 
72
- getLastCommitMsg () {
73
- return this.get('log', '-1', '--pretty=%B')
72
+ getLastCommitMsg() {
73
+ return this.get("log", "-1", "--pretty=%B");
74
74
  }
75
75
 
76
- push (...args) {
77
- return this.run('push', ...args)
76
+ push(...args) {
77
+ return this.run("push", ...args);
78
78
  }
79
79
 
80
- branchExists (branch, origin = 'origin') {
81
- return (
82
- this.branch('-a')
83
- .getRaw()
84
- .trim()
85
- .includes(`remotes/${origin}/${branch}`)
86
- )
80
+ branchExists(branch, origin = "origin") {
81
+ return this.branch("-a").getRaw().trim().includes(`remotes/${origin}/${branch}`);
87
82
  }
88
83
 
89
- checkBranchRemoteStatus (branch, origin = 'origin') {
90
- return this.run('cherry', branch, `${origin}/${branch}`).get()
84
+ checkBranchRemoteStatus(branch, origin = "origin") {
85
+ return this.run("cherry", branch, `${origin}/${branch}`).get();
91
86
  }
92
87
 
93
- branches (...args) {
88
+ branches(...args) {
94
89
  return this.branch(...args)
95
90
  .get()
96
- .split('\n')
97
- .map(branch => branch.trim().replace('* ', ''))
98
- .filter(branch => !!branch)
99
- .filter(branch => !String(branch).includes('/HEAD'))
91
+ .split("\n")
92
+ .map((branch) => branch.trim().replace("* ", ""))
93
+ .filter((branch) => !!branch)
94
+ .filter((branch) => !String(branch).includes("/HEAD"));
100
95
  }
101
96
 
102
- show (branch) {
103
- return this.run('show', '--format="%ci|%cr|%an"', branch, '--')
104
- .getRaw()
105
- .split('\n')[0]
106
- .trim()
97
+ show(branch) {
98
+ return this.run("show", '--format="%ci|%cr|%an"', branch, "--").getRaw().split("\n")[0].trim();
107
99
  }
108
100
 
109
- branchesInfos (...args) {
110
- return this
111
- .branches(...args)
112
- .map(branch => {
101
+ branchesInfos(...args) {
102
+ return this.branches(...args)
103
+ .map((branch) => {
113
104
  try {
114
- const [date, creation, author] = this.show(branch).split('|')
105
+ const [date, creation, author] = this.show(branch).split("|");
115
106
  return {
116
107
  branch,
117
108
  date,
118
109
  creation,
119
110
  author
120
- }
121
- } catch (er) {
122
- return undefined
111
+ };
112
+ } catch {
113
+ return undefined;
123
114
  }
124
115
  })
125
116
  .filter((b) => !!b)
126
- .sort((info1, info2) => info1.date < info2.date)
117
+ .sort((info1, info2) => info1.date < info2.date);
127
118
  }
128
119
  }
129
120
 
130
- export const git = new GitCli()
121
+ export const git = new GitCli();