Skip to content

Commit 27a4bbb

Browse files
committed
✨ refactor(app): 重构代码结构,重构其他命令
1 parent 7a03e07 commit 27a4bbb

26 files changed

+173
-73
lines changed

README.md

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,92 @@ import { clear } from "code-genius";
126126
})();
127127
```
128128

129+
## hooks 命令
130+
131+
新增或修改 `simple-git-hooks` 配置后需要重新初始化, 支持命令模式和 **API** 模式;
132+
133+
### 命令模式
134+
135+
```bash
136+
codeg hooks
137+
```
138+
139+
### API 模式
140+
141+
```typescript
142+
import { gitInitSimpleHooks } from "code-genius";
143+
144+
(async () => {
145+
await gitInitSimpleHooks();
146+
})();
147+
```
148+
149+
## depcheck 命令
150+
151+
运行 `npm-check` 检查过时的、不正确的和未使用的依赖项, 支持命令模式和 **API** 模式;
152+
153+
### 命令模式
154+
155+
```bash
156+
codeg depcheck
157+
```
158+
159+
### API 模式
160+
161+
```typescript
162+
import { npmDepCheck } from "code-genius";
163+
164+
(async () => {
165+
await npmDepCheck();
166+
})();
167+
```
168+
169+
## registry 命令
170+
171+
切换 **NPM** 镜像地址, 支持命令模式, 询问模式和 API 模式;
172+
173+
### 命令模式
174+
175+
```bash
176+
# 设置 npm 官方源
177+
codeg registry -u https://registry.npmjs.org/
178+
```
179+
180+
### 询问模式
181+
182+
```bash
183+
# 启动询问模式
184+
codeg registry
185+
```
186+
187+
```
188+
# 询问过程
189+
1. 请选择 NPM 镜像
190+
```
191+
192+
### API 模式
193+
194+
```typescript
195+
import { npmRegistry } from "code-genius";
196+
197+
(async () => {
198+
await npmRegistry("https://registry.npmjs.org/");
199+
})();
200+
```
201+
202+
203+
129204
## 命令
130205

131-
| 命令 | 参数 | 默认值 | 功能描述 |
132-
| ---------- | ---------------------------------------------------------------------------------------- | --------- | --------------------------------------------------- |
133-
| commit | --no-emoji | true | 生成 angualr 规范的提交信息 |
134-
| verify | -- | -- | 校验 COMMIT_EDITMSG 中的信息是否符合 Angualr 规范 |
135-
| clear | --pattern \<pattern\> | './dist/' | 运行 rimraf 删除不再需要的文件或文件夹 |
136-
| hooks | -- | -- | 新增或修改 simple-git-hooks 配置后需要重新初始化 |
137-
| depcheck | -- | -- | 运行 npm-check 检查过时的、不正确的和未使用的依赖项 |
138-
| registry | -- | -- | 切换 NPM 镜像地址 |
139-
| fix | --pattern \<pattern\> | './src' | 运行 eslint 静态扫描和修复代码中存在的问题 |
140-
| format | --pattern \<pattern\> | './src' | 运行 prettier 格式化代码风格 |
141-
| create | -- | -- | 运行 npm create 快速创建基础项目 |
142-
| template | -n, --project-name \<project-name\>, -f, --framework \<framework\>, | -- | 快速创建 CodeGenius 基础项目 |
143-
| lighthouse | --url \<url\> | -- | 运行 lighthouse 分析及收集 Web 应用的性能指标 |
144-
| git-user | -n, --name \<name\>,-e, --email \<email\>,--rule-name \<regexp\>,--rule-email \<regexp\> | -- | 设置或校验 git user 信息是否规范 |
145-
| quantity | -p, --path <path> | -- | 运行 cloc 分析并统计代码量 |
206+
| 命令 | 参数 | 默认值 | 功能描述 |
207+
| ---------- | ---------------------------------------------------------------------------------------- | ------- | --------------------------------------------------- |
208+
| fix | --pattern \<pattern\> | './src' | 运行 eslint 静态扫描和修复代码中存在的问题 |
209+
| format | --pattern \<pattern\> | './src' | 运行 prettier 格式化代码风格 |
210+
| create | -- | -- | 运行 npm create 快速创建基础项目 |
211+
| template | -n, --project-name \<project-name\>, -f, --framework \<framework\>, | -- | 快速创建 CodeGenius 基础项目 |
212+
| lighthouse | --url \<url\> | -- | 运行 lighthouse 分析及收集 Web 应用的性能指标 |
213+
| git-user | -n, --name \<name\>,-e, --email \<email\>,--rule-name \<regexp\>,--rule-email \<regexp\> | -- | 设置或校验 git user 信息是否规范 |
214+
| quantity | -p, --path <path> | -- | 运行 cloc 分析并统计代码量 |
146215

147216
## 执照
148217

api-model/api-depcheck.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { npmDepCheck } from "../src/index";
2+
3+
(async () => {
4+
await npmDepCheck();
5+
})();

api-model/api-hooks.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { gitInitSimpleHooks } from "../src/index";
2+
3+
(async () => {
4+
await gitInitSimpleHooks();
5+
})();

api-model/api-registry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { npmRegistry } from "../src/index";
2+
3+
(async () => {
4+
await npmRegistry("https://registry.npmjs.org/");
5+
})();

scripts/cup-script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loggerWarring } from "@/shared";
1+
import { loggerWarring } from "@/helper";
22
import { clear } from "@/command/clear";
33

44
async function clearDist() {

scripts/lint-script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { eslintFix } from "@/command/eslint-fix";
22
import { gitUser } from "@/command/git-user";
33
import { prettierFormat } from "@/command/prettier-format";
4-
import { execCommand } from "@/shared";
4+
import { execCommand } from "@/helper";
55

66
async function lint() {
77
await gitUser({ ruleEmail: "^[a-zA-Z0-9._%+-]+@(gmail)\\.(com)$" });

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cac from "cac";
22

3-
import { cmdInstaller, handleError } from "@/shared/index";
3+
import { cmdInstaller, handleError } from "@/helper";
44

55
import pkg from "../package.json";
66
import config from "@/index";

src/command/clear.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import path from "node:path";
55
import fs from "fs-extra";
66
import enquirer from "enquirer";
77

8-
import { execCommand, loggerInfo } from "@/shared/index";
9-
import { ACTIVATION, clearGlob } from "@/shared/config";
10-
import { ClearOptions } from "@/shared/types";
8+
import { execCommand, loggerInfo } from "@/helper";
9+
import { ACTIVATION, clearGlob } from "@/config";
10+
import { ClearOptions } from "@/types";
1111

1212
const generateEnquirer = async (): Promise<ClearOptions> => {
1313
const files = fs

src/command/create-project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { CAC } from "cac";
22

33
import enquirer from "enquirer";
44

5-
import { execCommand, loggerInfo } from "@/shared/index";
6-
import { ACTIVATION, projectSources } from "@/shared/config";
7-
import { ProjectSource } from "@/shared/types";
5+
import { execCommand, loggerInfo } from "@/helper";
6+
import { ACTIVATION, projectSources } from "@/config";
7+
import { ProjectSource } from "@/types";
88

99
interface PromptResult {
1010
command: string;

src/command/eslint-fix.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
loggerInfo,
77
printError,
88
printInfo,
9-
} from "@/shared/index";
10-
import { ACTIVATION, eslintGlob } from "@/shared/config";
9+
} from "@/helper";
10+
import { ACTIVATION, eslintGlob } from "@/config";
1111

1212
export const eslintFix = async (paths: string[]) => {
1313
if (ACTIVATION) {

0 commit comments

Comments
 (0)