vue2server7 2.2.0 → 2.3.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/test/3.js +75 -0
  3. package/test/1.js +0 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2server7",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "nodemon --watch src --ext ts --exec \"ts-node src/app.ts\"",
package/test/3.js ADDED
@@ -0,0 +1,75 @@
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
+ // 默认值
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
+ const regex =
37
+ /@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"[^)]*\)\s*[\r\n]+\s*private\s+(\w+)\s+(\w+)\s*;/g;
38
+
39
+ let match;
40
+
41
+ const jsonResult = [];
42
+ const tsFields = [];
43
+ const formFields = [];
44
+
45
+ while ((match = regex.exec(content)) !== null) {
46
+ const label = match[1];
47
+ const javaType = match[2];
48
+ const field = match[3];
49
+
50
+ const tsType = javaToTsType(javaType);
51
+
52
+ // JSON
53
+ jsonResult.push({ field, label });
54
+
55
+ // TS
56
+ tsFields.push(` /** ${label} */\n ${field}: ${tsType};`);
57
+
58
+ // JS 表单对象(带注释)
59
+ formFields.push(` /** ${label} */\n ${field}: ${defaultValue(tsType)}`);
60
+ }
61
+
62
+ // 写文件
63
+ fs.writeFileSync("output.json", JSON.stringify(jsonResult, null, 2));
64
+
65
+ fs.writeFileSync(
66
+ "model.ts",
67
+ `export interface Model {\n${tsFields.join("\n\n")}\n}\n`
68
+ );
69
+
70
+ fs.writeFileSync(
71
+ "form.js",
72
+ `export const formModel = {\n${formFields.join(",\n\n")}\n};\n`
73
+ );
74
+
75
+ console.log("✅ 已生成 output.json / model.ts / 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));