vue2server7 2.1.0 → 2.3.0

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.
@@ -1,25 +1,52 @@
1
- import { defineConfig } from 'vite'
2
- import vue from '@vitejs/plugin-vue'
3
- import vueDevTools from 'vite-plugin-vue-devtools'
4
-
5
- export default defineConfig({
6
- plugins: [
7
- vue(),
8
- vueDevTools()
9
- ],
10
- server: {
11
- port: 5173,
12
- open: false,
13
- proxy: {
14
- '/api': {
15
- target: 'http://localhost:3000',
16
- changeOrigin: true,
17
- rewrite: (path) => path.replace(/^\/api/, '/api')
18
- }
19
- }
20
- },
21
- build: {
22
- outDir: 'dist',
23
- sourcemap: false
24
- }
25
- })
1
+ const fs = require("fs");
2
+
3
+ const content = fs.readFileSync("input.txt", "utf8");
4
+
5
+ // Java 类型 → TS 类型映射
6
+ function javaToTsType(javaType) {
7
+ const map = {
8
+ String: "string",
9
+ Integer: "number",
10
+ Long: "number",
11
+ Double: "number",
12
+ Float: "number",
13
+ BigDecimal: "number",
14
+ Boolean: "boolean",
15
+ Date: "string",
16
+ LocalDate: "string",
17
+ LocalDateTime: "string"
18
+ };
19
+
20
+ return map[javaType] || "any";
21
+ }
22
+
23
+ // 正则匹配 注解 + 字段
24
+ const regex =
25
+ /@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"[^)]*\)\s*[\r\n]+\s*private\s+(\w+)\s+(\w+)\s*;/g;
26
+
27
+ let match;
28
+ const jsonResult = [];
29
+ const tsFields = [];
30
+
31
+ while ((match = regex.exec(content)) !== null) {
32
+ const label = match[1]; // 中文
33
+ const javaType = match[2]; // Java类型
34
+ const field = match[3]; // 字段名
35
+ const tsType = javaToTsType(javaType);
36
+
37
+ jsonResult.push({
38
+ field,
39
+ label
40
+ });
41
+
42
+ tsFields.push(` /** ${label} */\n ${field}: ${tsType};`);
43
+ }
44
+
45
+ // 输出 JSON 文件
46
+ fs.writeFileSync("output.json", JSON.stringify(jsonResult, null, 2));
47
+
48
+ // 输出 TS 文件
49
+ const tsContent = `export interface Model {\n${tsFields.join("\n\n")}\n}\n`;
50
+ fs.writeFileSync("model.ts", tsContent);
51
+
52
+ console.log("✅ 已生成 output.json 和 model.ts");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
package/test/2.js ADDED
@@ -0,0 +1,80 @@
1
+ const fs = require("fs");
2
+
3
+ const content = fs.readFileSync("input.txt", "utf8");
4
+
5
+ // Java → TS 类型映射
6
+ function javaToTsType(javaType) {
7
+ const map = {
8
+ String: "string",
9
+ Integer: "number",
10
+ Long: "number",
11
+ Double: "number",
12
+ Float: "number",
13
+ BigDecimal: "number",
14
+ Boolean: "boolean",
15
+ Date: "string",
16
+ LocalDate: "string",
17
+ LocalDateTime: "string"
18
+ };
19
+ return map[javaType] || "any";
20
+ }
21
+
22
+ // 根据 TS 类型生成默认值
23
+ function defaultValue(tsType) {
24
+ switch (tsType) {
25
+ case "string":
26
+ return `""`;
27
+ case "number":
28
+ return `0`;
29
+ case "boolean":
30
+ return `false`;
31
+ default:
32
+ return `null`;
33
+ }
34
+ }
35
+
36
+ // 匹配注解 + 字段
37
+ const regex =
38
+ /@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"[^)]*\)\s*[\r\n]+\s*private\s+(\w+)\s+(\w+)\s*;/g;
39
+
40
+ let match;
41
+
42
+ const jsonResult = [];
43
+ const tsFields = [];
44
+ const formFields = [];
45
+
46
+ while ((match = regex.exec(content)) !== null) {
47
+ const label = match[1];
48
+ const javaType = match[2];
49
+ const field = match[3];
50
+
51
+ const tsType = javaToTsType(javaType);
52
+
53
+ // JSON
54
+ jsonResult.push({
55
+ field,
56
+ label
57
+ });
58
+
59
+ // TS
60
+ tsFields.push(` /** ${label} */\n ${field}: ${tsType};`);
61
+
62
+ // JS 表单对象
63
+ formFields.push(` ${field}: ${defaultValue(tsType)}`);
64
+ }
65
+
66
+ // 写 JSON
67
+ fs.writeFileSync("output.json", JSON.stringify(jsonResult, null, 2));
68
+
69
+ // 写 TS
70
+ const tsContent = `export interface Model {\n${tsFields.join("\n\n")}\n}\n`;
71
+ fs.writeFileSync("model.ts", tsContent);
72
+
73
+ // 写 JS 表单对象
74
+ const formContent = `export const formModel = {\n${formFields.join(",\n")}\n};\n`;
75
+ fs.writeFileSync("form.js", formContent);
76
+
77
+ console.log("✅ 已生成:");
78
+ console.log(" - output.json");
79
+ console.log(" - model.ts");
80
+ console.log(" - form.js");
package/test/1.js DELETED
@@ -1,24 +0,0 @@
1
- const fs = require("fs");
2
-
3
- // 读取 text 文件
4
- const content = fs.readFileSync("input.txt", "utf8");
5
-
6
- // 正则:匹配 注解 + 字段
7
- const regex =
8
- /@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"\s*\)\s*[\r\n]+\s*private\s+\w+\s+(\w+)\s*;/g;
9
-
10
- let match;
11
- const result = [];
12
-
13
- while ((match = regex.exec(content)) !== null) {
14
- const label = match[1]; // 中文
15
- const field = match[2]; // 字段名
16
-
17
- result.push({
18
- field,
19
- label
20
- });
21
- }
22
-
23
- // 输出 JSON
24
- console.log(JSON.stringify(result, null, 2));