Skip to content

Commit 03c017b

Browse files
committed
🐛fix(app): 修复一系列Bug
1 parent 8fa9873 commit 03c017b

File tree

11 files changed

+102
-91
lines changed

11 files changed

+102
-91
lines changed

.depcheckrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ignores": [
3+
"@release-it/conventional-changelog",
4+
"@types/rimraf",
5+
"cross-env",
6+
"simple-git-hooks",
7+
"typescript"
8+
],
9+
"skip-missing": false
10+
}

scripts/cmv-script.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { loggerWarring } from "@/shared/index";
21
import { gitCommitVerify } from "@/command/git-commit-verify";
32

43
async function cmv() {
5-
try {
6-
await Promise.all([gitCommitVerify()]);
7-
} catch (error) {
8-
loggerWarring(error);
9-
}
4+
await gitCommitVerify();
105
}
116

127
cmv();

scripts/dep-script.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { loggerWarring } from "@/shared/index";
21
import { npmDepCheck } from "@/command/npm-dep-check";
32

43
async function cmv() {
5-
try {
6-
await npmDepCheck();
7-
} catch (error) {
8-
loggerWarring(error);
9-
}
4+
await npmDepCheck();
105
}
116

127
cmv();

scripts/lint-script.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { eslintFix } from "@/command/eslint-fix";
22
import { gitUser } from "@/command/git-user";
33
import { prettierFormat } from "@/command/prettier-format";
4-
import { execCommand, printError } from "@/shared";
4+
import { execCommand } from "@/shared";
55

66
async function lint() {
7-
try {
8-
await gitUser({ ruleEmail: "^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$" });
9-
await prettierFormat(["./src/", "./scripts/"]);
10-
await execCommand("git", ["add", "."], {
11-
stdio: "inherit",
12-
});
13-
await eslintFix(["./src/", "./scripts/"]);
14-
} catch (error) {
15-
printError(error);
16-
}
7+
await gitUser({ ruleEmail: "^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$" });
8+
await prettierFormat(["./src/", "./scripts/"]);
9+
await execCommand("git", ["add", "."]);
10+
await eslintFix(["./src/", "./scripts/"]);
1711
}
1812

1913
lint();

scripts/prepare.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { gitInitSimpleHooks } from "@/command/git-init-hooks";
2-
import { loggerWarring } from "@/shared";
32

43
async function prepare() {
5-
try {
6-
await gitInitSimpleHooks(process.cwd());
7-
} catch (error) {
8-
loggerWarring(error);
9-
}
4+
gitInitSimpleHooks(process.cwd());
105
}
116

127
prepare();

src/command/eslint-fix.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { CAC } from "cac";
22

3-
import { execCommand, loggerInfo } from "@/shared/index";
3+
import {
4+
execCommand,
5+
loggerError,
6+
loggerInfo,
7+
printError,
8+
printInfo,
9+
} from "@/shared/index";
410
import { ACTIVATION, eslintGlob } from "@/shared/config";
511

612
export const eslintFix = async (paths: string[]) => {
@@ -9,13 +15,20 @@ export const eslintFix = async (paths: string[]) => {
915
console.table(paths);
1016
}
1117

12-
await execCommand(
13-
"npx",
14-
["eslint", "--fix", "--fix-type", "problem,suggestion", ...paths],
15-
{
16-
stdio: "inherit",
17-
},
18-
);
18+
try {
19+
await execCommand(
20+
"npx",
21+
["eslint", "--fix", "--fix-type", "problem,suggestion", ...paths],
22+
{
23+
stdio: "inherit",
24+
},
25+
);
26+
printInfo("代码已通过 eslint 校验");
27+
} catch (error) {
28+
printError(`代码未通过 eslint 校验`);
29+
loggerError(error);
30+
process.exit(1);
31+
}
1932
};
2033

2134
export default function eslintFixInstaller(cli: CAC) {

src/command/git-commit-verify.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import path from "node:path";
66
import { printError, printInfo, execCommand } from "@/shared/index";
77

88
export const gitCommitVerify = async () => {
9-
const dogit = await execCommand("git", ["rev-parse", "--show-toplevel"], {
10-
stdio: "inherit",
11-
});
9+
const dogit = await execCommand("git", ["rev-parse", "--show-toplevel"]);
1210
const root = path.join(dogit || "", ".git", "COMMIT_EDITMSG");
11+
1312
const content = readFileSync(root, { encoding: "utf-8" }).trim();
13+
1414
const REG_EXP =
1515
/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
1616
if (!REG_EXP.test(content)) {
17-
printError("Git 提交信息不符合 Angualr 规范~");
18-
printInfo("推荐: 运行 `npx code-genius commit` 生成提交信息");
17+
printError(
18+
"Git 提交信息不符合 Angualr 规范, 建议运行 `npx code-genius commit` 生成规范信息",
19+
);
1920
process.exit(1);
21+
} else {
22+
printInfo("Git 提交信息校验通过");
2023
}
2124
};
2225

src/command/git-init-hooks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export default function gitInitSimpleHooksInstaller(cli: CAC) {
2929
setup: () => {
3030
cli
3131
.command("hooks", "新增或修改 simple-git-hooks 配置后需要重新初始化")
32-
.action(async () => {
33-
await gitInitSimpleHooks();
34-
});
32+
.action(async () => await gitInitSimpleHooks());
3533
},
3634
};
3735
}

src/command/git-user.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ import {
1010
import { ACTIVATION, gitUserOptions } from "@/shared/config";
1111
import { GitUserOptions } from "..";
1212

13-
async function printCurrentGitUser(isBefore: boolean = true) {
14-
printInfo(`${isBefore ? "当前" : "最新"}使用的 Git UserName :`);
15-
await execCommand("git", ["config", "user.name"], {
16-
stdio: "inherit",
17-
});
18-
printInfo(`${isBefore ? "当前" : "最新"}使用的 Git UserEmail :`);
19-
await execCommand("git", ["config", "user.email"], {
20-
stdio: "inherit",
21-
});
13+
async function printCurrentGitUser() {
14+
const name = await execCommand("git", ["config", "user.name"]);
15+
const email = await execCommand("git", ["config", "user.email"]);
16+
printInfo(`\ngit config info:\n user.name: ${name}\n user.email: ${email}`);
2217
}
2318

2419
export const gitUser = async (options: GitUserOptions) => {
@@ -31,46 +26,41 @@ export const gitUser = async (options: GitUserOptions) => {
3126
const nameRegExp = new RegExp(ruleName!);
3227
const emailRegExp = new RegExp(ruleEmail!, "i");
3328

34-
await printCurrentGitUser(true);
29+
await printCurrentGitUser();
3530

3631
if (name) {
3732
if (!nameRegExp.test(name)) {
38-
printWarring(`因输入的 ${name} 不符合 name 规则, 未能成功设置 name`);
33+
printWarring(`设置失败(user.name), ${name} 不符合规范`);
3934
} else {
4035
await execCommand("git", ["config", "user.name", name], {
4136
stdio: "inherit",
4237
});
43-
printInfo(`最新使用的 Git UserName :`);
44-
await execCommand("git", ["config", "user.name"], {
45-
stdio: "inherit",
46-
});
38+
const result = await execCommand("git", ["config", "user.name"]);
39+
printInfo(`更新成功(user.name): ${result}`);
4740
}
4841
}
4942

5043
if (email) {
5144
if (!emailRegExp.test(email)) {
52-
printWarring(`因输入的 ${email} 不符合 email 规则, 未能成功设置 email`);
45+
printWarring(`设置失败(user.email), ${email} 不符合规范`);
5346
} else {
5447
await execCommand("git", ["config", "user.email", email], {
5548
stdio: "inherit",
5649
});
57-
printInfo(`最新使用的 Git UserEmail :`);
58-
await execCommand("git", ["config", "user.email"], {
59-
stdio: "inherit",
60-
});
50+
const result = await execCommand("git", ["config", "user.email"]);
51+
printInfo(`更新成功(user.email): ${result}`);
6152
}
6253
}
6354

6455
if (!name && !email) {
6556
const username = await execCommand("git", ["config", "user.name"]);
6657
if (!nameRegExp.test(username)) {
67-
printError("Git 配置的 user.name 不符合规范, 请更换");
58+
printError(`${username} 不符合 ${ruleName} 规范`);
6859
process.exit(1);
6960
}
70-
7161
const useremail = await execCommand("git", ["config", "user.email"]);
7262
if (!emailRegExp.test(useremail)) {
73-
printError("Git 配置的 user.email 不符合规范, 请更换");
63+
printError(`${useremail} 不符合 ${ruleEmail} 规范`);
7464
process.exit(1);
7565
}
7666
}
@@ -94,10 +84,7 @@ export default function gitUserInstaller(cli: CAC) {
9484
default: gitUserOptions.ruleEmail,
9585
},
9686
)
97-
.action(async (options) => {
98-
console.log(options);
99-
await gitUser(options);
100-
});
87+
.action(async (options) => await gitUser(options));
10188
},
10289
};
10390
}

src/command/npm-dep-check.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import type { CAC } from "cac";
22

3-
import { execCommand } from "@/shared/index";
3+
import {
4+
execCommand,
5+
loggerError,
6+
printError,
7+
printInfo,
8+
} from "@/shared/index";
49

510
export const npmDepCheck = async () => {
6-
await execCommand("npx", ["npm-check"], {
7-
stdio: "inherit",
8-
});
11+
try {
12+
await execCommand("npx", ["depcheck"], {
13+
stdio: "inherit",
14+
});
15+
printInfo("项目依赖检查通过");
16+
} catch (error) {
17+
printError(`项目依赖存在一些问题`);
18+
loggerError(error);
19+
process.exit(1);
20+
}
921
};
1022

1123
export default function npmDepCheckInstaller(cli: CAC) {
@@ -15,11 +27,9 @@ export default function npmDepCheckInstaller(cli: CAC) {
1527
cli
1628
.command(
1729
"depcheck",
18-
"运行 npm-check 检查过时的、不正确的和未使用的依赖项",
30+
"运行 depcheck 检查过时的、不正确的和未使用的依赖项",
1931
)
20-
.action(async () => {
21-
await npmDepCheck();
22-
});
32+
.action(async () => await npmDepCheck());
2333
},
2434
};
2535
}

0 commit comments

Comments
 (0)