Skip to content

Commit 77e1b8e

Browse files
committed
✨ refactor(feature): 调整 gituser api
1 parent c152143 commit 77e1b8e

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

api-model/api-gituser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
setGitUserName,
33
setGitUserEmail,
4-
checkGitUserInfo,
4+
checkGitUserName,
5+
checkGitUserEmail,
56
} from "../src/index";
67

78
(async () => {
@@ -10,5 +11,6 @@ import {
1011
1112
"^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$"
1213
);
13-
await checkGitUserInfo("[\\s\\S]*", "^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$");
14+
await checkGitUserName("[\\s\\S]*");
15+
await checkGitUserEmail("^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$");
1416
})();

scripts/lint-script.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { eslintFix } from "@/command/eslint-fix";
2-
import { checkGitUserInfo } from "@/command/git-user";
2+
import { checkGitUserEmail } from "@/command/git-user";
33
import { prettierFormat } from "@/command/prettier-format";
44
import { execCommand } from "@/helper";
55

66
async function lint() {
7-
await checkGitUserInfo("[\\s\\S]*", "^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$");
7+
await checkGitUserEmail("^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$");
88
await prettierFormat(["./src/", "./scripts/"]);
99
await execCommand("git", ["add", "."]);
1010
await eslintFix(["./src/", "./scripts/"]);

src/command/git-user.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,31 @@ export async function setGitUserEmail(email: string, ruleEmail: string) {
5151
}
5252
}
5353

54-
export async function checkGitUserInfo(ruleName: string, ruleEmail: string) {
54+
export async function checkGitUserName(ruleName: string) {
5555
if (ACTIVATION) {
5656
loggerInfo(
5757
`checkGitUserInfo 参数信息: \n ${JSON.stringify({
5858
ruleName,
59-
ruleEmail,
6059
})}`,
6160
);
6261
}
6362
const nameRegExp = new RegExp(ruleName!);
64-
const emailRegExp = new RegExp(ruleEmail!, "i");
6563
const username = await execCommand("git", ["config", "user.name"]);
6664
if (!nameRegExp.test(username)) {
6765
printError(`${username} 不符合 ${ruleName} 规范`);
6866
process.exit(1);
6967
}
68+
}
69+
70+
export async function checkGitUserEmail(ruleEmail: string) {
71+
if (ACTIVATION) {
72+
loggerInfo(
73+
`checkGitUserInfo 参数信息: \n ${JSON.stringify({
74+
ruleEmail,
75+
})}`,
76+
);
77+
}
78+
const emailRegExp = new RegExp(ruleEmail!, "i");
7079
const useremail = await execCommand("git", ["config", "user.email"]);
7180
if (!emailRegExp.test(useremail)) {
7281
printError(`${useremail} 不符合 ${ruleEmail} 规范`);
@@ -95,10 +104,10 @@ export default function gitUserInstaller(cli: CAC) {
95104
},
96105
)
97106
.action(async (options) => {
98-
console.log(options);
99107
const { name, email, ruleName, ruleEmail } = options;
100108
if (!name && !email) {
101-
await checkGitUserInfo(ruleName, ruleEmail);
109+
await checkGitUserName(ruleName);
110+
await checkGitUserEmail(ruleEmail);
102111
}
103112
if (name) {
104113
await setGitUserName(name, ruleName);

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import lighthouseInstaller, { lighthouse } from "@/command/lighthouse";
2121
import gitUserInstaller, {
2222
setGitUserName,
2323
setGitUserEmail,
24-
checkGitUserInfo,
24+
checkGitUserName,
25+
checkGitUserEmail,
2526
} from "@/command/git-user";
2627
import quantityInstaller, { quantity } from "@/command/quantity";
2728
import { defineConfig } from "@/helper";
@@ -41,7 +42,8 @@ export {
4142
lighthouse,
4243
setGitUserName,
4344
setGitUserEmail,
44-
checkGitUserInfo,
45+
checkGitUserName,
46+
checkGitUserEmail,
4547
quantity,
4648
};
4749

0 commit comments

Comments
 (0)