Skip to content

Commit 08474c3

Browse files
committed
🎉 feat(app): 更新
1 parent 11762e5 commit 08474c3

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/common.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface BuiltInGitUserOptions {
2+
name?: string;
3+
email?: string;
4+
ruleName?: string;
5+
ruleEmail?: string;
6+
}
7+
8+
export interface GitUserOptions {
9+
ruleName?: string;
10+
ruleEmail?: string;
11+
}
12+
13+
export const gitUserOptions: BuiltInGitUserOptions = {
14+
name: "",
15+
email: "",
16+
ruleName: "[\\s\\S]*",
17+
ruleEmail:
18+
"^[a-zA-Z0-9._%+-]+@(163|qq|126|139|sina|sohu|yeah|gmail)\\.(com|net)$",
19+
};

src/index.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
import type { CAC } from "cac";
22
import {
33
ACTIVATION,
4-
CodeGeniusOptions,
54
execCommand,
6-
gitUserOptions,
75
loggerInfo,
86
printError,
97
printInfo,
108
printWarring,
119
} from "code-genius";
1210

13-
const mergeConfig = async (config: CodeGeniusOptions) => {
14-
const commands = config && config?.commands;
15-
if (commands && commands.gituser) {
16-
const { ruleName, ruleEmail } = commands.gituser;
17-
return {
18-
ruleName: ruleName || gitUserOptions.ruleName,
19-
ruleEmail: ruleEmail || gitUserOptions.ruleEmail,
20-
};
21-
}
22-
return {
23-
ruleName: gitUserOptions.ruleName,
24-
ruleEmail: gitUserOptions.ruleEmail,
25-
};
26-
};
11+
import { GitUserOptions } from "./common";
2712

2813
async function setGitUserName(name: string, ruleName: string) {
2914
if (ACTIVATION) {
@@ -103,7 +88,8 @@ async function checkGitUserEmail(ruleEmail: string) {
10388
}
10489
}
10590

106-
const gitUserInstaller = (config: CodeGeniusOptions) => {
91+
const gitUserInstaller = (config: GitUserOptions) => {
92+
const { ruleEmail, ruleName } = config;
10793
return {
10894
name: "gitUserInstaller",
10995
setup: (cli: CAC) => {
@@ -116,7 +102,6 @@ const gitUserInstaller = (config: CodeGeniusOptions) => {
116102
.option("--rule-name <regexp>", "设置 user.name 匹配规则(转义字符串)")
117103
.option("--rule-email <regexp>", "设置 user.email 匹配规则(转义字符串)")
118104
.action(async (options) => {
119-
const { ruleName, ruleEmail } = await mergeConfig(config);
120105
const { name, email, ruleName: rName, ruleEmail: rEmail } = options;
121106
if (!name && !email) {
122107
await checkGitUserName(ruleName || rName);

0 commit comments

Comments
 (0)