Skip to content

Commit 8fa9873

Browse files
committed
🔧chore(feature): 添加代码统计命令
1 parent ee8533f commit 8fa9873

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ npm i -g code-genius
3232
| create | -- | -- | 运行 npm create 快速创建基础项目 |
3333
| template | -n, --project-name \<project-name\>, -f, --framework \<framework\>, | -- | 快速创建 CodeGenius 基础项目 |
3434
| lighthouse | --url \<url\> | -- | 运行 lighthouse 分析及收集 Web 应用的性能指标 |
35-
| lighthouse | -n, --name \<name\>,-e, --email \<email\>,--rule-name \<regexp\>,--rule-email \<regexp\> | -- | 设置或校验 git user 信息是否规范 |
35+
| git-user | -n, --name \<name\>,-e, --email \<email\>,--rule-name \<regexp\>,--rule-email \<regexp\> | -- | 设置或校验 git user 信息是否规范 |
36+
| quantity | -p, --path <path> | -- | 运行 cloc 分析并统计代码量 |
3637

3738
## 执照
3839

src/command/quantity.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { CAC } from "cac";
2+
3+
import { execCommand, loggerInfo } from "@/shared/index";
4+
import path from "node:path";
5+
import { ACTIVATION } from "@/shared/config";
6+
7+
export const quantity = async (dir: string) => {
8+
if (ACTIVATION) {
9+
loggerInfo("clear 参数信息: \n");
10+
console.table({ dir });
11+
}
12+
const root = path.join(process.cwd(), dir);
13+
await execCommand("npx", ["cloc", root], {
14+
stdio: "inherit",
15+
});
16+
};
17+
18+
export default function quantityInstaller(cli: CAC) {
19+
return {
20+
name: "quantityInstaller",
21+
setup: () => {
22+
cli
23+
.command("quantity", "运行 cloc 分析并统计代码量")
24+
.option("-p, --path <path>", "设置代码路径", {
25+
default: ".",
26+
})
27+
.action(async (options) => {
28+
const { path } = options;
29+
await quantity(path);
30+
});
31+
},
32+
};
33+
}

src/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import prettierFormatInstaller from "./command/prettier-format";
1313
import templateInstaller from "./command/template";
1414
import lighthouseInstaller from "./command/lighthouse";
1515
import gitUserInstaller from "./command/git-user";
16+
import quantityInstaller from "./command/quantity";
1617

1718
export function cmdInstaller(cli: CAC) {
1819
gitCommitInstaller(cli).setup();
@@ -28,4 +29,5 @@ export function cmdInstaller(cli: CAC) {
2829
templateInstaller(cli).setup();
2930
lighthouseInstaller(cli).setup();
3031
gitUserInstaller(cli).setup();
32+
quantityInstaller(cli).setup();
3133
}

0 commit comments

Comments
 (0)