Skip to content

Commit 3ad8a93

Browse files
committed
✨ refactor(feature): 同步commit命令三种模式体验
1 parent d80364c commit 3ad8a93

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ codeg commit
6767
import { gitCommit } from "code-genius";
6868

6969
(async () => {
70-
await gitCommit("fix(feat): 修复xx功能的xxBug");
70+
await gitCommit("fix", "feat", "修复xx功能的xxBug");
7171
})();
7272
```
7373

api-model/api-commit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { gitCommit } from "code-genius";
1+
import { gitCommit } from "../dist/index.mjs";
22

33
(async () => {
4-
await gitCommit("fix(feat): 修复xx功能的xxBug");
4+
await gitCommit("fix", "feat", "修复xx功能的xxBug");
55
})();

src/command/git-commit.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,25 @@ const generateEnquirer = async (): Promise<
7272
};
7373
};
7474

75-
export const gitCommit = async (content: string) => {
75+
export const gitCommit = async (
76+
type: string,
77+
scope: string,
78+
description: string,
79+
) => {
7680
if (ACTIVATION) {
77-
loggerInfo(`gitCommit 参数信息: \n${JSON.stringify(content)}`);
81+
loggerInfo(
82+
`gitCommit 参数信息: \n${JSON.stringify({
83+
type,
84+
scope,
85+
description,
86+
})}`,
87+
);
7888
}
79-
await execCommand("git", ["commit", "-m", content], { stdio: "inherit" });
89+
await execCommand(
90+
"git",
91+
["commit", "-m", `${type}(${scope}): ${description}`],
92+
{ stdio: "inherit" },
93+
);
8094
};
8195

8296
export default function gitCommitInstaller(cli: CAC) {
@@ -90,14 +104,12 @@ export default function gitCommitInstaller(cli: CAC) {
90104
.option("-d, --description <description>", "填写修改描述")
91105
.action(async (options) => {
92106
const { type, scope, description } = options;
93-
let content = "";
94107
if (!type || !scope || !description) {
95108
const result = await generateEnquirer();
96-
content = `${result.type}(${result.scope}): ${result.description}`;
109+
await gitCommit(result.type, result.scope, result.description);
97110
} else {
98-
content = `${type}(${scope}): ${description}`;
111+
await gitCommit(type, scope, description);
99112
}
100-
await gitCommit(content);
101113
});
102114
},
103115
};

0 commit comments

Comments
 (0)