feima-vite-plugins 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# feima-vite-plugins
|
|
2
|
+
|
|
3
|
+
Vite 插件集合,提供多个实用的 Vite 插件。
|
|
4
|
+
|
|
5
|
+
## 插件列表
|
|
6
|
+
|
|
7
|
+
- `fvxeTableIdCheck` - FVxeTable ID 检查插件
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install feima-vite-plugins
|
|
13
|
+
# 或
|
|
14
|
+
pnpm add feima-vite-plugins
|
|
15
|
+
# 或
|
|
16
|
+
yarn add feima-vite-plugins
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 使用
|
|
20
|
+
|
|
21
|
+
### fvxeTableIdCheck
|
|
22
|
+
|
|
23
|
+
在开发环境中自动检查 FVxeTable 组件的 ID 是否重复或包含中文。
|
|
24
|
+
|
|
25
|
+
#### 功能
|
|
26
|
+
|
|
27
|
+
- ✅ 检查 FVxeTable 组件的 `id` 属性是否重复
|
|
28
|
+
- ✅ 检查 `id` 属性是否包含中文
|
|
29
|
+
- ✅ 实时监听文件变化,自动更新检查结果
|
|
30
|
+
- ✅ 在浏览器中显示错误覆盖层
|
|
31
|
+
- ✅ 仅在开发环境生效
|
|
32
|
+
|
|
33
|
+
#### 配置
|
|
34
|
+
|
|
35
|
+
在 `vite.config.ts` 中引入并配置:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { defineConfig } from 'vite'
|
|
39
|
+
import vue from '@vitejs/plugin-vue'
|
|
40
|
+
import { fvxeTableIdCheck } from 'feima-vite-plugins'
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
plugins: [
|
|
44
|
+
vue(),
|
|
45
|
+
fvxeTableIdCheck()
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### 检查规则
|
|
51
|
+
|
|
52
|
+
插件会扫描项目中所有 `.vue` 文件,查找以下格式的组件:
|
|
53
|
+
|
|
54
|
+
```vue
|
|
55
|
+
<f-vxe-table id="table1" />
|
|
56
|
+
<!-- 或 -->
|
|
57
|
+
<FVxeTable id="table1" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**错误示例:**
|
|
61
|
+
|
|
62
|
+
1. **ID 重复**:
|
|
63
|
+
```vue
|
|
64
|
+
<!-- 文件 A.vue -->
|
|
65
|
+
<f-vxe-table id="table1" />
|
|
66
|
+
|
|
67
|
+
<!-- 文件 B.vue -->
|
|
68
|
+
<f-vxe-table id="table1" /> <!-- ❌ 错误:ID 重复 -->
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. **ID 包含中文**:
|
|
72
|
+
```vue
|
|
73
|
+
<f-vxe-table id="表格1" /> <!-- ❌ 错误:ID 不能包含中文 -->
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### 错误提示
|
|
77
|
+
|
|
78
|
+
当检测到错误时,插件会:
|
|
79
|
+
- 在控制台输出详细的错误信息
|
|
80
|
+
- 在浏览器中显示错误覆盖层
|
|
81
|
+
- 列出所有包含重复 ID 的文件路径
|
|
82
|
+
|
|
83
|
+
## 开发
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 安装依赖
|
|
87
|
+
pnpm install
|
|
88
|
+
|
|
89
|
+
# 构建
|
|
90
|
+
pnpm build
|
|
91
|
+
|
|
92
|
+
# 发布前会自动构建
|
|
93
|
+
pnpm publish
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
ISC
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAOlD,wBAAgB,gBAAgB,IAAI,MAAM,CAwIzC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
const TABLE_REG = /<(f-vxe-table|FVxeTable)[^>]*\s+id\s*=\s*["']([^"']+)["'][^>]*>/g;
|
|
4
|
+
export function fvxeTableIdCheck() {
|
|
5
|
+
const idMap = new Map();
|
|
6
|
+
let root = "";
|
|
7
|
+
let errorMsgs = [];
|
|
8
|
+
function containsChinese(str) {
|
|
9
|
+
return /[\u4e00-\u9fa5]/.test(str);
|
|
10
|
+
}
|
|
11
|
+
function clearFile(file) {
|
|
12
|
+
for (const [, files] of idMap) {
|
|
13
|
+
files.delete(file);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function collectFromFile(file) {
|
|
17
|
+
if (!file.endsWith(".vue"))
|
|
18
|
+
return;
|
|
19
|
+
const code = fs.readFileSync(file, "utf-8");
|
|
20
|
+
let match;
|
|
21
|
+
while ((match = TABLE_REG.exec(code))) {
|
|
22
|
+
const id = match[2];
|
|
23
|
+
if (containsChinese(id)) {
|
|
24
|
+
errorMsgs.push(`FVxeTable id 不能包含中文: "${id}" (文件: ${path.relative(root, file)})`);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (!idMap.has(id))
|
|
28
|
+
idMap.set(id, new Set());
|
|
29
|
+
idMap.get(id).add(file);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function showErrorOverlay(server, message) {
|
|
33
|
+
server.ws.send({
|
|
34
|
+
type: "error",
|
|
35
|
+
err: {
|
|
36
|
+
message,
|
|
37
|
+
stack: "",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function clearErrorOverlay(server) {
|
|
42
|
+
server.ws.send({ type: "full-reload" });
|
|
43
|
+
}
|
|
44
|
+
function report(server) {
|
|
45
|
+
let hasDuplicate = false;
|
|
46
|
+
let message = "";
|
|
47
|
+
if (errorMsgs.length) {
|
|
48
|
+
message += errorMsgs.join("\n") + "\n\n";
|
|
49
|
+
}
|
|
50
|
+
for (const [id, files] of idMap) {
|
|
51
|
+
if (files.size > 1) {
|
|
52
|
+
hasDuplicate = true;
|
|
53
|
+
message +=
|
|
54
|
+
`FVxeTable id 重复: "${id}"\n` +
|
|
55
|
+
[...files].map((f) => ` - ${path.relative(root, f)}`).join("\n") +
|
|
56
|
+
"\n\n";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if ((hasDuplicate || errorMsgs.length) && server) {
|
|
60
|
+
console.error("\n🚨 " + message);
|
|
61
|
+
showErrorOverlay(server, message);
|
|
62
|
+
}
|
|
63
|
+
if (!hasDuplicate && errorMsgs.length === 0 && server) {
|
|
64
|
+
clearErrorOverlay(server);
|
|
65
|
+
}
|
|
66
|
+
errorMsgs = [];
|
|
67
|
+
return hasDuplicate || errorMsgs.length > 0;
|
|
68
|
+
}
|
|
69
|
+
function scanAll(dir) {
|
|
70
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const full = path.join(dir, entry.name);
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
scanAll(full);
|
|
75
|
+
}
|
|
76
|
+
else if (full.endsWith(".vue")) {
|
|
77
|
+
collectFromFile(full);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
name: "vite-plugin-fvxe-table-id-check",
|
|
83
|
+
configResolved(config) {
|
|
84
|
+
root = config.root;
|
|
85
|
+
},
|
|
86
|
+
configureServer(server) {
|
|
87
|
+
// 仅在开发环境生效
|
|
88
|
+
if (process.env.NODE_ENV !== "development") {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// 1️⃣ 启动时全量扫描
|
|
92
|
+
scanAll(path.join(root, "src"));
|
|
93
|
+
report(server);
|
|
94
|
+
// 2️⃣ 监听文件修改
|
|
95
|
+
server.watcher.on("change", (file) => {
|
|
96
|
+
if (!file.endsWith(".vue"))
|
|
97
|
+
return;
|
|
98
|
+
clearFile(file);
|
|
99
|
+
collectFromFile(file);
|
|
100
|
+
report(server);
|
|
101
|
+
});
|
|
102
|
+
// 3️⃣ 监听新增文件
|
|
103
|
+
server.watcher.on("add", (file) => {
|
|
104
|
+
if (!file.endsWith(".vue"))
|
|
105
|
+
return;
|
|
106
|
+
collectFromFile(file);
|
|
107
|
+
report(server);
|
|
108
|
+
});
|
|
109
|
+
// 4️⃣ 监听删除文件
|
|
110
|
+
server.watcher.on("unlink", (file) => {
|
|
111
|
+
if (!file.endsWith(".vue"))
|
|
112
|
+
return;
|
|
113
|
+
clearFile(file);
|
|
114
|
+
report(server);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "feima-vite-plugins",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vite 插件集合 - 包含 FVxeTable ID 检查插件",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://git.fmszh.com/feima/feima-vite-plugins.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"author": "",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"vite",
|
|
27
|
+
"vite-plugin",
|
|
28
|
+
"fvxe-table",
|
|
29
|
+
"id-check"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"prepublishOnly": "pnpm build"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"vite": "^5.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"typescript": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vite": "^4.0.0 || ^5.0.0"
|
|
44
|
+
},
|
|
45
|
+
"packageManager": "pnpm@10.8.0+sha512.0e82714d1b5b43c74610193cb20734897c1d00de89d0e18420aebc5977fa13d780a9cb05734624e81ebd81cc876cd464794850641c48b9544326b5622ca29971"
|
|
46
|
+
}
|