@cmflow/cli 3.4.0-alpha.1 → 3.4.0-alpha.5

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 (209) hide show
  1. package/README.md +110 -294
  2. package/dist/bin/cm.mjs +9985 -1348
  3. package/dist/bin/cmrelease.mjs +3875 -1193
  4. package/dist/{cli-truncate-CXNquMRK.mjs → cli-truncate-Bi2MjGwF.mjs} +177 -6
  5. package/dist/cli-truncate-DMcpM5Q7.mjs +2 -0
  6. package/dist/cli-truncate-DMcpM5Q7.mjs.map +1 -0
  7. package/dist/{cli-truncate-BmHD4ngn.mjs → cli-truncate-DsW0mgI_.mjs} +177 -6
  8. package/dist/{common-CwPbT3So.mjs → common-BdfXquG0.mjs} +31 -36
  9. package/dist/common-BdfXquG0.mjs.map +1 -0
  10. package/dist/compile-packages-BB08_q2B.mjs +2 -0
  11. package/dist/compile-packages-BB08_q2B.mjs.map +1 -0
  12. package/dist/docker-Cc30aRzl.mjs +34 -0
  13. package/dist/docker-Cc30aRzl.mjs.map +1 -0
  14. package/dist/docker-clean-tags-EvFdWykP.mjs +2 -0
  15. package/dist/docker-clean-tags-EvFdWykP.mjs.map +1 -0
  16. package/dist/docker-publish-CG0aN9se.mjs +2 -0
  17. package/dist/docker-publish-CG0aN9se.mjs.map +1 -0
  18. package/dist/find-packages-611B-66T.mjs +42 -0
  19. package/dist/find-packages-611B-66T.mjs.map +1 -0
  20. package/dist/get-config-8ivgd1KC.mjs +9 -0
  21. package/dist/get-config-8ivgd1KC.mjs.map +1 -0
  22. package/dist/get-east-asian-width-Tfn8qoqd.mjs.map +1 -1
  23. package/dist/{get-east-asian-width-eFfEkHwo.mjs → get-east-asian-width-wiVWCFXf.mjs} +4 -4
  24. package/dist/log-update-CLbF3iV6.mjs +6 -0
  25. package/dist/log-update-CLbF3iV6.mjs.map +1 -0
  26. package/dist/{log-update-B2GqeeDd.mjs → log-update-CTXRtajW.mjs} +185 -14
  27. package/dist/{log-update-BldA9lkm.mjs → log-update-Dy1vPMGY.mjs} +185 -14
  28. package/dist/npm-VM_GgazT.mjs +2 -0
  29. package/dist/npm-VM_GgazT.mjs.map +1 -0
  30. package/dist/{semver-D8gwMSFO.mjs → semver-DFjVbN1S.mjs} +2 -2
  31. package/dist/semver-DFjVbN1S.mjs.map +1 -0
  32. package/dist/source-CwLcYLzI.mjs +7 -0
  33. package/dist/source-CwLcYLzI.mjs.map +1 -0
  34. package/dist/{wrap-ansi-DsMb4WnZ.mjs → wrap-ansi-9ugahFCy.mjs} +2 -2
  35. package/dist/wrap-ansi-9ugahFCy.mjs.map +1 -0
  36. package/dist/{wrap-ansi-CWIezXNl.mjs → wrap-ansi-BRr0GA6g.mjs} +5 -5
  37. package/dist/{wrap-ansi-T0rz0Urp.mjs → wrap-ansi-Cupoo4Yg.mjs} +5 -5
  38. package/dist/wrap-ansi-dwgEjNWf.mjs +2 -0
  39. package/dist/write-package-cxki9d3K.mjs +8 -0
  40. package/dist/write-package-cxki9d3K.mjs.map +1 -0
  41. package/dist/write-packages-CxCAl_AG.mjs +10 -0
  42. package/dist/write-packages-CxCAl_AG.mjs.map +1 -0
  43. package/package.json +9 -41
  44. package/.oxfmtrc.json +0 -11
  45. package/.yarn/install-state.gz +0 -0
  46. package/.yarn/releases/yarn-4.18.0.cjs +0 -1000
  47. package/.yarnrc.yml +0 -10
  48. package/bin/cm-checkfeatures.ts +0 -10
  49. package/bin/cm-clean.ts +0 -10
  50. package/bin/cm-config.ts +0 -10
  51. package/bin/cm-deploy.ts +0 -10
  52. package/bin/cm-expedit.ts +0 -19
  53. package/bin/cm-fetch.ts +0 -10
  54. package/bin/cm-finish.ts +0 -10
  55. package/bin/cm-jira-releases.ts +0 -10
  56. package/bin/cm-merge.ts +0 -10
  57. package/bin/cm-publish.ts +0 -10
  58. package/bin/cm-pull.ts +0 -8
  59. package/bin/cm-push.ts +0 -10
  60. package/bin/cm-rebase.ts +0 -10
  61. package/bin/cm-release.ts +0 -5
  62. package/bin/cm-republish.ts +0 -10
  63. package/bin/cm-start.ts +0 -10
  64. package/bin/cm.ts +0 -40
  65. package/dist/cli-truncate-DbOyuy2e.mjs +0 -2
  66. package/dist/cli-truncate-DbOyuy2e.mjs.map +0 -1
  67. package/dist/common-CwPbT3So.mjs.map +0 -1
  68. package/dist/docker-clean-tags-Cd-E8IqJ.mjs +0 -2
  69. package/dist/docker-clean-tags-Cd-E8IqJ.mjs.map +0 -1
  70. package/dist/docker-publish-B0E0qYYB.mjs +0 -2
  71. package/dist/docker-publish-B0E0qYYB.mjs.map +0 -1
  72. package/dist/get-config-DoOyLztI.mjs +0 -41
  73. package/dist/get-config-DoOyLztI.mjs.map +0 -1
  74. package/dist/log-update-By8Z-mak.mjs +0 -6
  75. package/dist/log-update-By8Z-mak.mjs.map +0 -1
  76. package/dist/semver-D8gwMSFO.mjs.map +0 -1
  77. package/dist/src/index.mjs +0 -18
  78. package/dist/src/index.mjs.map +0 -1
  79. package/dist/src/semantic/core/analyze-commits.mjs +0 -2
  80. package/dist/src/semantic/core/analyze-commits.mjs.map +0 -1
  81. package/dist/src/semantic/core/conditional.mjs +0 -2
  82. package/dist/src/semantic/core/conditional.mjs.map +0 -1
  83. package/dist/src/semantic/core/exit.mjs +0 -2
  84. package/dist/src/semantic/core/exit.mjs.map +0 -1
  85. package/dist/src/semantic/core/prepare/bump-version.mjs +0 -48
  86. package/dist/src/semantic/core/prepare/bump-version.mjs.map +0 -1
  87. package/dist/src/semantic/core/prepare/commit.mjs +0 -2
  88. package/dist/src/semantic/core/prepare/commit.mjs.map +0 -1
  89. package/dist/src/semantic/core/prepare/release-info.mjs +0 -2
  90. package/dist/src/semantic/core/prepare/release-info.mjs.map +0 -1
  91. package/dist/src/semantic/core/run.mjs +0 -2
  92. package/dist/src/semantic/core/run.mjs.map +0 -1
  93. package/dist/src/semantic/core/sync-repository.mjs +0 -2
  94. package/dist/src/semantic/core/sync-repository.mjs.map +0 -1
  95. package/dist/src/semantic/core/verify-conditions.mjs +0 -2
  96. package/dist/src/semantic/core/verify-conditions.mjs.map +0 -1
  97. package/dist/src/semantic/core/verify-release.mjs +0 -2
  98. package/dist/src/semantic/core/verify-release.mjs.map +0 -1
  99. package/dist/src/semantic/docker/publish.mjs +0 -2
  100. package/dist/src/semantic/docker/publish.mjs.map +0 -1
  101. package/dist/src/semantic/docker/success.mjs +0 -2
  102. package/dist/src/semantic/docker/success.mjs.map +0 -1
  103. package/dist/strip-ansi-Aeu5cmZe.mjs +0 -174
  104. package/dist/strip-ansi-Cl0pRo-s.mjs +0 -2
  105. package/dist/strip-ansi-Cl0pRo-s.mjs.map +0 -1
  106. package/dist/wrap-ansi-BeIjar2W.mjs +0 -2
  107. package/dist/wrap-ansi-DsMb4WnZ.mjs.map +0 -1
  108. package/mise.toml +0 -2
  109. package/oxlint.json +0 -25
  110. package/release.config.mjs +0 -39
  111. package/src/commands/checkfeatures.ts +0 -39
  112. package/src/commands/clean.ts +0 -36
  113. package/src/commands/config.ts +0 -31
  114. package/src/commands/deploy.ts +0 -39
  115. package/src/commands/fetch.ts +0 -30
  116. package/src/commands/finish.ts +0 -50
  117. package/src/commands/index.ts +0 -13
  118. package/src/commands/jira-releases.ts +0 -97
  119. package/src/commands/merge.ts +0 -58
  120. package/src/commands/prompts/branches.ts +0 -46
  121. package/src/commands/pull.ts +0 -44
  122. package/src/commands/push.ts +0 -48
  123. package/src/commands/rebase.ts +0 -56
  124. package/src/commands/release.ts +0 -21
  125. package/src/commands/republish.ts +0 -34
  126. package/src/commands/start.ts +0 -123
  127. package/src/commands/tasks/merge-branch.ts +0 -80
  128. package/src/commands/tasks/push-branch.ts +0 -19
  129. package/src/commands/tasks/rebase-all-branches.ts +0 -37
  130. package/src/commands/tasks/refresh-repository.ts +0 -38
  131. package/src/commands/tasks/run-test.ts +0 -28
  132. package/src/commands/tasks/update-branch.ts +0 -49
  133. package/src/commands/tasks/update-dependencies.ts +0 -43
  134. package/src/commands/utils/check-install.ts +0 -31
  135. package/src/common/back/directus/directus-flow.test.ts +0 -63
  136. package/src/common/back/directus/directus-flow.ts +0 -48
  137. package/src/common/back/http/http-proxy.ts +0 -21
  138. package/src/common/back/http/http-request.spec.ts +0 -50
  139. package/src/common/back/http/http-request.ts +0 -74
  140. package/src/common/back/jira/get-sorted-releases.ts +0 -40
  141. package/src/common/back/jira/interfaces/JiraIIssue.d.ts +0 -100
  142. package/src/common/back/jira/jira-releases.ts +0 -47
  143. package/src/common/back/jira/jira-request.spec.ts +0 -59
  144. package/src/common/back/jira/jira-request.ts +0 -29
  145. package/src/common/back/jira/jira-search.spec.ts +0 -44
  146. package/src/common/back/jira/jira-search.ts +0 -17
  147. package/src/common/cli/bun.test.ts +0 -58
  148. package/src/common/cli/bun.ts +0 -33
  149. package/src/common/cli/cli.ts +0 -127
  150. package/src/common/cli/docker.test.ts +0 -141
  151. package/src/common/cli/docker.ts +0 -66
  152. package/src/common/cli/git.test.ts +0 -215
  153. package/src/common/cli/git.ts +0 -121
  154. package/src/common/cli/lerna.test.ts +0 -58
  155. package/src/common/cli/lerna.ts +0 -25
  156. package/src/common/cli/npm.test.ts +0 -58
  157. package/src/common/cli/npm.ts +0 -33
  158. package/src/common/cli/pnpm.test.ts +0 -58
  159. package/src/common/cli/pnpm.ts +0 -34
  160. package/src/common/cli/yarn.test.ts +0 -58
  161. package/src/common/cli/yarn.ts +0 -33
  162. package/src/common/configure-git-workspace.ts +0 -39
  163. package/src/common/get-config.ts +0 -159
  164. package/src/common/get-package-json.ts +0 -15
  165. package/src/common/get-package-manager.ts +0 -13
  166. package/src/common/get-release-config.ts +0 -9
  167. package/src/common/index.ts +0 -14
  168. package/src/common/run-command.test.ts +0 -66
  169. package/src/common/run-command.ts +0 -67
  170. package/src/common/types.ts +0 -26
  171. package/src/common/vendor.d.ts +0 -4
  172. package/src/index.ts +0 -14
  173. package/src/semantic/core/analyze-commits.ts +0 -21
  174. package/src/semantic/core/conditional.ts +0 -62
  175. package/src/semantic/core/exit.ts +0 -15
  176. package/src/semantic/core/prepare/bump-version.ts +0 -41
  177. package/src/semantic/core/prepare/commit.ts +0 -30
  178. package/src/semantic/core/prepare/release-info.ts +0 -6
  179. package/src/semantic/core/run.ts +0 -23
  180. package/src/semantic/core/sync-repository.ts +0 -55
  181. package/src/semantic/core/verify-conditions.ts +0 -41
  182. package/src/semantic/core/verify-release.ts +0 -10
  183. package/src/semantic/define-config.ts +0 -42
  184. package/src/semantic/docker/publish.ts +0 -6
  185. package/src/semantic/docker/success.ts +0 -10
  186. package/src/semantic/utils/__mock__/test1/package.json +0 -7
  187. package/src/semantic/utils/__mock__/test1/packages/a/package.json +0 -9
  188. package/src/semantic/utils/__mock__/test1/packages/b/package.json +0 -7
  189. package/src/semantic/utils/__mock__/test2/package.json +0 -4
  190. package/src/semantic/utils/__mock__/test2/packages/a/package.json +0 -7
  191. package/src/semantic/utils/__mock__/test2/packages/b/package.json +0 -5
  192. package/src/semantic/utils/bump-packages-version.test.ts +0 -76
  193. package/src/semantic/utils/bump-packages-version.ts +0 -53
  194. package/src/semantic/utils/calculate-snapshot-version.test.ts +0 -69
  195. package/src/semantic/utils/calculate-snapshot-version.ts +0 -17
  196. package/src/semantic/utils/display-package-info.ts +0 -12
  197. package/src/semantic/utils/display-release-info.ts +0 -13
  198. package/src/semantic/utils/docker-clean-tags.test.ts +0 -62
  199. package/src/semantic/utils/docker-clean-tags.ts +0 -58
  200. package/src/semantic/utils/docker-publish.test.ts +0 -45
  201. package/src/semantic/utils/docker-publish.ts +0 -24
  202. package/src/semantic/utils/log-section.ts +0 -9
  203. package/src/semantic/utils/release-rules.ts +0 -15
  204. package/src/semantic/utils/transform-writer.ts +0 -101
  205. package/src/workflow/index.ts +0 -42
  206. package/tsconfig.build.json +0 -29
  207. package/tsconfig.json +0 -30
  208. package/tsdown.config.ts +0 -63
  209. package/vitest.config.mts +0 -9
@@ -1,100 +0,0 @@
1
- import type { ADFDocument } from "./ADFDocument.js";
2
- import type { JiraChangelog } from "./JiraChangelogIssueResponse.js";
3
-
4
- export interface JiraStatus {
5
- id: string;
6
- name: string;
7
- }
8
-
9
- export interface JiraUser {
10
- accountId?: string;
11
- displayName?: string;
12
- emailAddress?: string;
13
- }
14
-
15
- export interface CreateJiraComment {
16
- body: ADFDocument;
17
- author: JiraUser;
18
- notifyUsers?: boolean;
19
- }
20
-
21
- export interface JiraComment extends CreateJiraComment {
22
- id: string;
23
- body: ADFDocument;
24
- author: JiraUser;
25
- created: string;
26
- updated?: string;
27
- }
28
-
29
- interface JiraAttachment {
30
- id: string;
31
- filename: string;
32
- content: string; // URL de téléchargement
33
- size: number;
34
- mimeType?: string;
35
- created: string;
36
- author: JiraUser;
37
- }
38
-
39
- interface JiraIssueLink {
40
- id: string;
41
- type: {
42
- id: string;
43
- name: string; // Ex: "relates to", "blocks"
44
- inward: string; // Ex: "is blocked by"
45
- outward: string; // Ex: "blocks"
46
- };
47
- inwardIssue?: Partial<JiraIssue>; // Issue liée en amont
48
- outwardIssue?: Partial<JiraIssue>; // Issue liée en aval
49
- }
50
-
51
- export interface CreateJiraFieldsIssue {
52
- summary: string; // Titre de l'issue
53
- description?: ADFDocument; // Description détaillée
54
- labels?: string[]; // Liste des labels
55
- issuetype: {
56
- name: string; // Type d'issue (ex: "Bug", "Task")
57
- };
58
- project: {
59
- key: string;
60
- };
61
- assignee?: Partial<JiraUser>; // Utilisateur assigné
62
- reporter?: Partial<JiraUser>; // Créateur de l'issue
63
- status?: Omit<JiraStatus, "name">;
64
- components?: { name: string }[];
65
-
66
- [customFieldId: `customfield_${string}`]: unknown; // Autres champs personnalisés
67
- }
68
-
69
- export interface CreateJiraIssue {
70
- fields: CreateJiraFieldsIssue;
71
- }
72
-
73
- export interface JiraIssue {
74
- id: string; // ID unique de l'issue
75
- key: string; // Clé de l'issue (ex: "PROJ-123")
76
- self: string; // URL de l'issue
77
-
78
- fields: CreateJiraFieldsIssue & {
79
- issuetype: {
80
- id: string;
81
- name: string; // Type d'issue (ex: "Bug", "Task")
82
- };
83
- project: {
84
- id: string;
85
- key: string;
86
- name: string;
87
- };
88
- comment?: {
89
- comments: JiraComment[];
90
- total: number;
91
- };
92
- status: JiraStatus;
93
- attachment?: JiraAttachment[]; // Liste des pièces jointes
94
- issuelinks?: JiraIssueLink[]; // Relations avec d'autres issues
95
- created: string; // Date de création
96
- updated: string; // Dernière mise à jour
97
- };
98
- }
99
-
100
- export type JiraIssueWithChangelog = JiraIssue & { changelog: JiraChangelog };
@@ -1,47 +0,0 @@
1
- import { jiraRequest } from "./jira-request.js";
2
-
3
- interface JiraRelease {
4
- id: string;
5
- name: string;
6
- description?: string;
7
- archived?: boolean;
8
- released?: boolean;
9
- projectId?: string;
10
- releaseDate?: string;
11
- version?: string;
12
- }
13
-
14
- export async function getJiraReleases(projectId: string): Promise<JiraRelease[]> {
15
- const endpoint = `/rest/api/3/project/${projectId}/versions?expand`;
16
- const response = await jiraRequest(endpoint);
17
-
18
- if (!response || !Array.isArray(response)) {
19
- return [];
20
- }
21
-
22
- return response as JiraRelease[];
23
- }
24
-
25
- export async function updateJiraRelease(release: JiraRelease) {
26
- const endpoint = `/rest/api/3/version/${release.id}`;
27
- try {
28
- await jiraRequest(endpoint, {
29
- method: "put",
30
- headers: {
31
- "Content-Type": "application/json",
32
- Accept: "application/json"
33
- },
34
- data: {
35
- id: release.id,
36
- description: release.description,
37
- name: release.name,
38
- archived: release.archived,
39
- released: release.released,
40
- projectId: release.projectId,
41
- releaseDate: release.releaseDate
42
- }
43
- });
44
- } catch (er) {
45
- console.log(`Error while updating jira release ${release.id}`, er);
46
- }
47
- }
@@ -1,59 +0,0 @@
1
- import { httpRequest } from "../http/http-request.js";
2
- import { jiraRequest } from "./jira-request.js";
3
-
4
- vi.mock("../http/http-request.js");
5
- vi.mock("axios-retry");
6
-
7
- describe("jiraRequest", () => {
8
- beforeEach(() => {
9
- vi.clearAllMocks();
10
- });
11
-
12
- it("should make a GET request to the JIRA API", async () => {
13
- const mockResponse = { data: "test" };
14
- vi.mocked(httpRequest).mockResolvedValue(mockResponse);
15
-
16
- const result = await jiraRequest("/test-endpoint");
17
-
18
- expect(httpRequest).toHaveBeenCalledWith(
19
- expect.stringContaining("/test-endpoint"),
20
- expect.objectContaining({
21
- headers: expect.objectContaining({
22
- Authorization: expect.stringContaining("Basic ")
23
- })
24
- })
25
- );
26
- expect(result).toEqual(mockResponse);
27
- });
28
-
29
- it("should make a POST request to the JIRA API", async () => {
30
- const mockResponse = { data: "test" };
31
- vi.mocked(httpRequest).mockResolvedValue(mockResponse);
32
-
33
- const result = await jiraRequest("/test-endpoint", {
34
- method: "post",
35
- params: { key: "value" },
36
- headers: { "Content-Type": "application/json" },
37
- data: { key: "value" }
38
- });
39
-
40
- expect(httpRequest).toHaveBeenCalledWith(expect.stringContaining("/test-endpoint"), {
41
- callee: "JIRA",
42
- method: "post",
43
- params: { key: "value" },
44
- data: { key: "value" },
45
- headers: expect.objectContaining({
46
- Authorization: expect.stringContaining("Basic ")
47
- }),
48
- retries: 3,
49
- retryDelay: expect.any(Function)
50
- });
51
- expect(result).toEqual(mockResponse);
52
- });
53
-
54
- it("should throw an error if the httpRequest fails", async () => {
55
- vi.mocked(httpRequest).mockRejectedValue(new Error("Request failed"));
56
-
57
- await expect(jiraRequest("test-endpoint")).rejects.toThrow("Request failed");
58
- });
59
- });
@@ -1,29 +0,0 @@
1
- import axiosRetry from "axios-retry";
2
-
3
- import { getConfig } from "../../get-config.js";
4
- import { httpRequest } from "../http/http-request.js";
5
-
6
- interface JiraRequestOptions {
7
- method?: string;
8
- headers?: Record<string, string>;
9
- data?: unknown;
10
- params?: Record<string, string>;
11
- [key: string]: unknown;
12
- }
13
-
14
- export async function jiraRequest(endpoint: string, opts: JiraRequestOptions = {}) {
15
- const { JIRA_API, JIRA_TOKEN, JIRA_EMAIL } = getConfig();
16
- const jiraUrl = `${JIRA_API}${endpoint}`;
17
- const auth = Buffer.from(`${JIRA_EMAIL}:${JIRA_TOKEN}`).toString("base64");
18
-
19
- return httpRequest(jiraUrl, {
20
- ...opts,
21
- callee: "JIRA",
22
- headers: {
23
- ...opts.headers,
24
- Authorization: `Basic ${auth}`
25
- },
26
- retries: 3,
27
- retryDelay: axiosRetry.exponentialDelay
28
- });
29
- }
@@ -1,44 +0,0 @@
1
- import { jiraRequest } from "./jira-request.js";
2
- import { jiraSearch } from "./jira-search.js";
3
-
4
- vi.mock("./jira-request.js");
5
- vi.mock("axios-retry");
6
-
7
- describe("jiraSearch", () => {
8
- beforeEach(() => {
9
- vi.clearAllMocks();
10
- });
11
-
12
- it("should call jiraRequest with the correct JQL", async () => {
13
- const mockResponse = { issues: [] };
14
- vi.mocked(jiraRequest).mockResolvedValue(mockResponse);
15
-
16
- const jql = "project = TEST";
17
- const result = await jiraSearch(jql);
18
-
19
- expect(jiraRequest).toHaveBeenCalledWith("/rest/api/3/search/jql", {
20
- params: {
21
- jql
22
- }
23
- });
24
- expect(result).toEqual(mockResponse);
25
- });
26
-
27
- it("should call jiraRequest with the correct JQL and expend option", async () => {
28
- const mockResponse = { issues: [] };
29
- vi.mocked(jiraRequest).mockResolvedValue(mockResponse);
30
-
31
- const jql = "project = TEST";
32
- const result = await jiraSearch(jql, {
33
- expand: "changelog"
34
- });
35
-
36
- expect(jiraRequest).toHaveBeenCalledWith("/rest/api/3/search/jql", {
37
- params: {
38
- expand: "changelog",
39
- jql
40
- }
41
- });
42
- expect(result).toEqual(mockResponse);
43
- });
44
- });
@@ -1,17 +0,0 @@
1
- import { jiraRequest } from "./jira-request.js";
2
-
3
- /**
4
- * Search JIRA issues using JQL (JIRA Query Language).
5
- * @template Expand
6
- * @param jql {string} JIRA Query Language
7
- * @param opts {object} Options
8
- * @returns {Promise<{issues: (import("./interfaces/JiraIIssue.d.ts").JiraIssue & Expand)[], total: number, maxResults: number}>}
9
- */
10
- export function jiraSearch(jql: string, opts?: Record<string, unknown>) {
11
- return jiraRequest("/rest/api/3/search/jql", {
12
- params: {
13
- ...(opts as Record<string, string>),
14
- jql
15
- }
16
- });
17
- }
@@ -1,58 +0,0 @@
1
- import execa from "execa";
2
- import { bun } from "./bun.js";
3
- import { Cli } from "./cli.js";
4
-
5
- vi.mock("execa", () => {
6
- const sync = vi.fn();
7
- const execaMock = Object.assign(vi.fn(), { sync });
8
- return { default: execaMock };
9
- });
10
-
11
- type ExecaMock = {
12
- sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
13
- mockReturnValue(v: unknown): void;
14
- };
15
-
16
- const execaMock = execa as unknown as ExecaMock;
17
-
18
- execaMock.sync.mockImplementation((...args) => {
19
- return {
20
- stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
21
- };
22
- });
23
- execaMock.mockReturnValue({});
24
-
25
- describe("BunCli", () => {
26
- beforeEach(() => {
27
- vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
28
- return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
29
- });
30
- });
31
- describe("newVersion", () => {
32
- it("should run newVersion cmd", () => {
33
- const result = bun.newVersion("1.0.0");
34
-
35
- expect(result.stdout).toEqual("CMD: bun pm version --no-git-tag-version 1.0.0");
36
- });
37
- });
38
- describe("run", () => {
39
- it('should run "run" cmd', async () => {
40
- await bun.run("run-arg");
41
-
42
- expect(execa).toHaveBeenCalledWith("bun", ["run", "run-arg"], {
43
- cwd: process.cwd(),
44
- stdio: "inherit"
45
- });
46
- });
47
- });
48
- describe("install", () => {
49
- it('should run "install" cmd', async () => {
50
- await bun.install("install-arg");
51
-
52
- expect(execa).toHaveBeenCalledWith("bun", ["install", "install-arg"], {
53
- cwd: process.cwd(),
54
- stdio: "inherit"
55
- });
56
- });
57
- });
58
- });
@@ -1,33 +0,0 @@
1
- import { Cli } from "./cli.js";
2
-
3
- class BunCli extends Cli {
4
- constructor() {
5
- super("bun");
6
- }
7
-
8
- newVersion(version: string) {
9
- return this.pm("version", "--no-git-tag-version", version);
10
- }
11
-
12
- pm(...args: string[]) {
13
- return this.sync("pm", ...args);
14
- }
15
-
16
- run(...args: string[]) {
17
- return super.run("run", ...args);
18
- }
19
-
20
- install(...args: string[]) {
21
- return super.run("install", ...args);
22
- }
23
-
24
- /**
25
- * Reinstall dependencies without bun.lock mutation
26
- * @returns {Promise<unknown>}
27
- */
28
- restore() {
29
- return super.run("install", "--frozen-lockfile");
30
- }
31
- }
32
-
33
- export const bun = new BunCli();
@@ -1,127 +0,0 @@
1
- import "any-observable/register/rxjs-all.js";
2
-
3
- import { spawnSync, type SpawnSyncOptions } from "child_process";
4
- import execa from "execa";
5
- import { filter, fromEvent, map, merge, takeUntil } from "rxjs";
6
- import type { Observable } from "rxjs";
7
-
8
- type RunOptions = Record<string, unknown>;
9
-
10
- export interface CliResult extends Promise<unknown> {
11
- toObservable(opt?: RunOptions): Observable<string>;
12
- toStream(opt?: RunOptions): execa.ExecaChildProcess<string>;
13
- cwd(cwd: string): CliResult;
14
- sync(opt?: RunOptions): execa.ExecaSyncReturnValue<string>;
15
- getRaw(opt?: RunOptions): string;
16
- get(opt?: RunOptions): string;
17
- }
18
-
19
- export class Cli {
20
- cmd: string;
21
-
22
- constructor(cmd: string) {
23
- this.cmd = cmd;
24
- }
25
-
26
- sync(...args: string[]): execa.ExecaSyncReturnValue<string> {
27
- return (Cli.run(this.cmd, args) as CliResult).sync();
28
- }
29
-
30
- run(...args: string[]): CliResult {
31
- return Cli.run(this.cmd, args);
32
- }
33
-
34
- get(...args: string[]): string {
35
- return (Cli.run(this.cmd, args) as CliResult).get();
36
- }
37
-
38
- static run(cmd: string, args: string[] = [], options: RunOptions = {}): CliResult {
39
- const run = (opt: RunOptions = {}) => {
40
- return execa(cmd, args, {
41
- cwd: process.cwd(),
42
- ...opt,
43
- ...options
44
- } as execa.Options);
45
- };
46
-
47
- let isPromise = true;
48
-
49
- const promise = new Promise<void>((resolve, reject) => {
50
- setTimeout(async () => {
51
- if (isPromise) {
52
- try {
53
- const result = await run({
54
- stdio: "inherit"
55
- });
56
-
57
- resolve(result as unknown as void);
58
- } catch (err) {
59
- reject(err);
60
- }
61
- } else {
62
- resolve();
63
- }
64
- }, 10);
65
- });
66
-
67
- const cliResult = promise as unknown as CliResult;
68
-
69
- cliResult.toObservable = (opt?: RunOptions): Observable<string> => {
70
- isPromise = false;
71
- const cp = run(opt);
72
- const end$ = fromEvent(cp, "close");
73
- const stdout$ = fromEvent(cp.stdout!, "data").pipe(
74
- takeUntil(end$),
75
- map((data) => (data as Buffer).toString())
76
- );
77
- const stderr$ = fromEvent(cp.stderr!, "data").pipe(
78
- takeUntil(end$),
79
- map((data) => (data as Buffer).toString())
80
- );
81
-
82
- return merge(stdout$, stderr$).pipe(filter(Boolean));
83
- };
84
-
85
- cliResult.toStream = (opt?: RunOptions) => {
86
- isPromise = false;
87
-
88
- return run(opt);
89
- };
90
-
91
- cliResult.cwd = (cwd: string) => {
92
- options.cwd = cwd;
93
- return cliResult;
94
- };
95
-
96
- cliResult.sync = (opt?: RunOptions) => {
97
- isPromise = false;
98
- return execa.sync(cmd, args, {
99
- cwd: process.cwd(),
100
- stdio: "inherit",
101
- ...options,
102
- ...opt
103
- } as execa.SyncOptions);
104
- };
105
-
106
- cliResult.getRaw = (opt?: RunOptions): string => {
107
- isPromise = false;
108
- return Cli.getRaw(cmd, args, {
109
- cwd: process.cwd(),
110
- ...options,
111
- ...opt
112
- });
113
- };
114
-
115
- cliResult.get = cliResult.getRaw;
116
-
117
- return cliResult;
118
- }
119
-
120
- static getRaw(cmd: string, args: string[], options?: RunOptions): string {
121
- return (spawnSync(cmd, args, options as SpawnSyncOptions).output as (Buffer | null)[])
122
- .filter((o): o is Buffer => o !== null)
123
- .map((o) => o.toString())
124
- .join("\n")
125
- .trim();
126
- }
127
- }
@@ -1,141 +0,0 @@
1
- import execa from "execa";
2
- import axios from "axios";
3
- import { docker } from "./docker.js";
4
- import { Cli } from "./cli.js";
5
-
6
- vi.mock("axios", () => {
7
- return { default: vi.fn() };
8
- });
9
- vi.mock("execa", () => {
10
- const sync = vi.fn();
11
- const execaMock = Object.assign(vi.fn(), { sync });
12
- return { default: execaMock };
13
- });
14
-
15
- type ExecaMock = {
16
- sync: { mockImplementation(fn: (...args: unknown[]) => unknown): void };
17
- mockReturnValue(v: unknown): void;
18
- };
19
-
20
- const execaMock = execa as unknown as ExecaMock;
21
-
22
- execaMock.mockReturnValue({});
23
-
24
- execaMock.sync.mockImplementation((...args) => {
25
- return {
26
- stdout: `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`
27
- };
28
- });
29
-
30
- describe("DockerCli", () => {
31
- beforeEach(() => {
32
- vi.spyOn(Cli, "getRaw").mockImplementation((...args: unknown[]) => {
33
- return `CMD: ${([] as unknown[]).concat(...(args as (string | string[])[]).filter((arg) => typeof arg === "string" || Array.isArray(arg))).join(" ")}`;
34
- });
35
- });
36
- describe("tag", () => {
37
- it("should run tag cmd", () => {
38
- const result = docker.tag("tag-arg", "image");
39
-
40
- expect(result).toEqual("CMD: docker tag tag-arg image");
41
- expect(Cli.getRaw).toHaveBeenCalledWith("docker", ["tag", "tag-arg", "image"], {
42
- cwd: process.cwd()
43
- });
44
- });
45
- });
46
- describe("login", () => {
47
- it("should run login cmd", () => {
48
- const result = docker.login("login-arg");
49
-
50
- expect(result.stdout).toEqual("CMD: docker login login-arg");
51
- expect(execa.sync).toHaveBeenCalledWith("docker", ["login", "login-arg"], {
52
- cwd: process.cwd(),
53
- stdio: "inherit"
54
- });
55
- });
56
- });
57
- describe("push", () => {
58
- it("should run push cmd", async () => {
59
- await docker.push("push-arg");
60
-
61
- expect(execa).toHaveBeenCalledWith("docker", ["push", "push-arg"], {
62
- cwd: process.cwd(),
63
- stdio: "inherit"
64
- });
65
- });
66
- });
67
- describe("getToken", () => {
68
- beforeEach(() => {
69
- vi.mocked(axios).mockReturnValue({ data: { token: "token" } } as unknown as ReturnType<typeof axios>);
70
- });
71
- it("should get token", async () => {
72
- const token = await docker.getToken("username", "password");
73
-
74
- expect(axios).toHaveBeenCalledWith({
75
- method: "POST",
76
- url: "https://hub.docker.com/v2/users/login/",
77
- headers: {
78
- Accept: "application/json",
79
- "Content-Type": "application/json"
80
- },
81
- data: {
82
- password: "password",
83
- username: "username"
84
- }
85
- });
86
- expect(token).toEqual("token");
87
- });
88
- });
89
- describe("getTags", () => {
90
- beforeEach(() => {
91
- vi.mocked(axios).mockReturnValue({
92
- data: {
93
- results: [
94
- {
95
- name: "branch-1",
96
- last_updated: new Date("2020-06-01")
97
- }
98
- ]
99
- }
100
- } as unknown as ReturnType<typeof axios>);
101
- });
102
- it("should get token", async () => {
103
- const tags = await docker.getTags({
104
- token: "token",
105
- repository: "owner"
106
- });
107
-
108
- expect(tags).toEqual([
109
- {
110
- name: "branch-1",
111
- last_updated: new Date("2020-06-01")
112
- }
113
- ]);
114
- expect(axios).toHaveBeenCalledWith({
115
- method: "GET",
116
- url: "https://hub.docker.com/v2/repositories/owner/tags/?page=1&page_size=500",
117
- headers: {
118
- Accept: "application/json",
119
- Authorization: "JWT token"
120
- }
121
- });
122
- });
123
- });
124
- describe("deleteTag", () => {
125
- it("should run delete Tag", async () => {
126
- await docker.deleteTag("my-tag", {
127
- token: "token",
128
- repository: "owner"
129
- });
130
-
131
- expect(axios).toHaveBeenCalledWith({
132
- headers: {
133
- Accept: "application/json",
134
- Authorization: "JWT token"
135
- },
136
- method: "DELETE",
137
- url: "https://hub.docker.com/v2/repositories/owner/tags/my-tag/"
138
- });
139
- });
140
- });
141
- });