Skip to content

Commit 9b70cf7

Browse files
committed
✨refactor(feature): 接入 npm-check 模块
1 parent e251a53 commit 9b70cf7

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ npm i -g code-genius
1818

1919
## 终端命令
2020

21-
| 命令 | 参数 | 默认值 | 功能描述 |
22-
| ------ | --------------------- | --------- | ------------------------------------------------- |
23-
| commit | --no-emoji | true | 生成 angualr 规范的提交信息 |
24-
| verify | -- | -- | 校验 COMMIT_EDITMSG 中的信息是否符合 Angualr 规范 |
25-
| clear | --pattern \<pattern\> | './dist/' | 运行 rimraf 删除不再需要的文件或文件夹 |
26-
| hooks | -- | -- | 新增或修改 simple-git-hooks 配置后需要重新初始化 |
27-
| run | -- | -- | 列出可以运行的全部脚本 |
28-
| fix | --pattern \<pattern\> | './src' | 运行 eslint 静态扫描和修复代码中存在的问题 |
29-
| format | --pattern \<pattern\> | ./src' | 运行 prettier 格式化代码风格 |
21+
| 命令 | 参数 | 默认值 | 功能描述 |
22+
| -------- | --------------------- | --------- | --------------------------------------------------- |
23+
| commit | --no-emoji | true | 生成 angualr 规范的提交信息 |
24+
| verify | -- | -- | 校验 COMMIT_EDITMSG 中的信息是否符合 Angualr 规范 |
25+
| clear | --pattern \<pattern\> | './dist/' | 运行 rimraf 删除不再需要的文件或文件夹 |
26+
| hooks | -- | -- | 新增或修改 simple-git-hooks 配置后需要重新初始化 |
27+
| run | -- | -- | 列出可以运行的全部脚本 |
28+
| fix | --pattern \<pattern\> | './src' | 运行 eslint 静态扫描和修复代码中存在的问题 |
29+
| format | --pattern \<pattern\> | ./src' | 运行 prettier 格式化代码风格 |
30+
| depcheck | -- | -- | 运行 npm-check 检查过时的、不正确的和未使用的依赖项 |
3031

3132
## 执照
3233

src/command/npm-dep-check.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ACTIVATION } from "../shared/config";
2+
import { execCommand } from "../shared/index";
3+
4+
export const npmDepCheck = async () => {
5+
await execCommand("npx", ["npm-check"], {
6+
stdio: "inherit",
7+
});
8+
};

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from "./command/git-commit";
33
export * from "./command/git-commit-verify";
44
export * from "./command/git-init-hooks";
55
export * from "./command/npm-run";
6+
export * from "./command/npm-dep-check";
67
export * from "./command/eslint-fix";
78
export * from "./command/prettier-format";
89

src/setup.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { gitCommit } from "./command/git-commit";
1717
import { gitInitSimpleHooks } from "./command/git-init-hooks";
1818
import { clear } from "./command/clear";
1919
import { npmRun } from "./command/npm-run";
20+
import { npmDepCheck } from "./command/npm-dep-check";
2021

2122
export const commandSet: CommandSet = {
2223
gitCommitCmd: (cli: CAC) => {
@@ -30,14 +31,14 @@ export const commandSet: CommandSet = {
3031
});
3132
});
3233
},
33-
gitCommitVerifySetup: (cli: CAC) => {
34+
gitCommitVerifyCmd: (cli: CAC) => {
3435
cli
3536
.command("verify", "校验 COMMIT_EDITMSG 中的信息是否符合 Angualr 规范")
3637
.action(async () => {
3738
await gitCommitVerify();
3839
});
3940
},
40-
clearSetup: (cli: CAC) => {
41+
clearCmd: (cli: CAC) => {
4142
cli
4243
.command("clear", "运行 rimraf 删除不再需要的文件或文件夹")
4344
.option("-p, --pattern <pattern>", "设置配置规则", {
@@ -51,22 +52,32 @@ export const commandSet: CommandSet = {
5152
await clear(patterns);
5253
});
5354
},
54-
initSimpleGitHooks: (cli: CAC) => {
55+
initSimpleGitHooksCmd: (cli: CAC) => {
5556
cli
5657
.command("hooks", "新增或修改 simple-git-hooks 配置后需要重新初始化")
5758
.action(async () => {
5859
await gitInitSimpleHooks();
5960
});
6061
},
61-
npmRunSetup: (cli: CAC) => {
62+
npmDepCheck: (cli: CAC) => {
63+
cli
64+
.command(
65+
"depcheck",
66+
"运行 npm-check 检查过时的、不正确的和未使用的依赖项",
67+
)
68+
.action(async () => {
69+
await npmDepCheck();
70+
});
71+
},
72+
npmRunCmd: (cli: CAC) => {
6273
cli.command("run", "列出可以运行的全部脚本").action(async () => {
6374
await npmRun();
6475
});
6576
},
66-
eslintFix: (cli: CAC) => {
77+
eslintFixCmd: (cli: CAC) => {
6778
cli
6879
.command("fix", "运行 eslint 静态扫描和修复代码中存在的问题")
69-
.option("-p, --pattern <pattern>", "设置配置规则", {
80+
.option("-p, --pattern <pattern>", "设置匹配规则", {
7081
default: [...eslintGlob],
7182
})
7283
.action(async (options) => {
@@ -77,10 +88,10 @@ export const commandSet: CommandSet = {
7788
await eslintFix(patterns);
7889
});
7990
},
80-
prettierFormat: (cli: CAC) => {
91+
prettierFormatCmd: (cli: CAC) => {
8192
cli
8293
.command("format", "运行 prettier 格式化代码风格")
83-
.option("-p, --pattern <pattern>", "设置配置规则", {
94+
.option("-p, --pattern <pattern>", "设置匹配规则", {
8495
default: [...formatGlob],
8596
})
8697
.action(async (options) => {

0 commit comments

Comments
 (0)