@yorha2b-lab/autodev 1.0.23 → 1.0.25
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
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
拒绝重复劳动!为什么你需要 Auto CRUD Copilot?
|
|
14
14
|
告别手写 Table/Form:截图即代码,提升你的开发效率,告别烦人的复制粘贴。
|
|
15
|
-
拒绝接口联调痛苦:自动读取
|
|
15
|
+
拒绝接口联调痛苦:自动读取 Response,AI 帮你抹平前后端字段命名差异。
|
|
16
16
|
架构解耦:核心逻辑与 UI 框架分离,React/Vue/Angular 均可适配。
|
|
17
17
|
|
|
18
18
|
## ✨ 特性
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- 🔧 **智能生成**: 支持React、Vue、Angular等多种前端框架模板
|
|
22
22
|
- 📊 **表格组件**: 自动生成可编辑、可排序、可筛选的数据表格
|
|
23
23
|
- 📝 **表单组件**: 智能生成搜索表单和模态框表单
|
|
24
|
-
- 🔌 **API对齐**: 自动对齐
|
|
24
|
+
- 🔌 **API对齐**: 自动对齐Response接口与前端字段映射
|
|
25
25
|
- 🎨 **UI组件**: 支持多种UI组件类型(输入框、选择器、日期等)
|
|
26
26
|
- 📱 **响应式**: 生成的代码支持响应式布局
|
|
27
27
|
|
|
@@ -49,6 +49,8 @@ API_KEY=your_api_key_here
|
|
|
49
49
|
BASE_URL=your_api_base_url_here
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
🚗 **获取API Key直通车**: [阿里云百炼控制台](https://bailian.console.aliyun.com/cn-beijing?tab=doc#/doc/)
|
|
53
|
+
|
|
52
54
|
### 基本使用
|
|
53
55
|
|
|
54
56
|
1. **生成完整CRUD页面**
|
|
@@ -68,7 +70,6 @@ autodev watch:part
|
|
|
68
70
|
3. **对齐API字段**
|
|
69
71
|
|
|
70
72
|
```bash
|
|
71
|
-
# 将Swagger文档放入swagger目录
|
|
72
73
|
autodev watch:api
|
|
73
74
|
```
|
|
74
75
|
|
|
@@ -95,7 +96,7 @@ autodev watch:part -t vue
|
|
|
95
96
|
|
|
96
97
|
### watch:api 命令
|
|
97
98
|
|
|
98
|
-
监听 `
|
|
99
|
+
监听 `response` 目录下的与模块同名的json文件,自动对齐真实接口字段。
|
|
99
100
|
|
|
100
101
|
```bash
|
|
101
102
|
autodev watch:api
|
|
@@ -107,7 +108,7 @@ autodev watch:api
|
|
|
107
108
|
your-project/
|
|
108
109
|
├── screenShot/ # 页面截图目录
|
|
109
110
|
├── screenPart/ # 组件截图目录
|
|
110
|
-
├──
|
|
111
|
+
├── response/ # Response目录
|
|
111
112
|
├── mock/ # 生成的Mock数据
|
|
112
113
|
├── src/
|
|
113
114
|
│ ├── pages/ # 生成的页面代码
|
package/bin/autodev.js
CHANGED
|
@@ -25,7 +25,7 @@ program
|
|
|
25
25
|
const tplEnv = path.resolve(__dirname, '../.env.example')
|
|
26
26
|
const targetEnv = path.join(process.cwd(), '.env')
|
|
27
27
|
const targetConfig = path.join(process.cwd(), 'config.js')
|
|
28
|
-
fs.mkdirSync(path.join(process.cwd(), '
|
|
28
|
+
fs.mkdirSync(path.join(process.cwd(), 'response'), { recursive: true })
|
|
29
29
|
fs.mkdirSync(path.join(process.cwd(), 'screenShot'), { recursive: true })
|
|
30
30
|
fs.mkdirSync(path.join(process.cwd(), 'screenPart'), { recursive: true })
|
|
31
31
|
if (fs.existsSync(targetEnv)) {
|
|
@@ -61,7 +61,7 @@ program
|
|
|
61
61
|
|
|
62
62
|
program
|
|
63
63
|
.command('watch:api')
|
|
64
|
-
.description('监听
|
|
64
|
+
.description('监听 Response,自动对齐真实接口字段')
|
|
65
65
|
.action(() => {
|
|
66
66
|
const watchApi = require('../src/commands/watch-api')
|
|
67
67
|
watchApi()
|
package/package.json
CHANGED
|
@@ -7,11 +7,11 @@ const chokidar = require('chokidar')
|
|
|
7
7
|
const watchApi = () => {
|
|
8
8
|
|
|
9
9
|
const { getConfig } = require('../utils/utils.js')
|
|
10
|
-
const {
|
|
10
|
+
const { alignResponseFields } = require('../services/llm.js')
|
|
11
11
|
|
|
12
12
|
const config = getConfig()
|
|
13
13
|
|
|
14
|
-
const watcher = chokidar.watch('./
|
|
14
|
+
const watcher = chokidar.watch('./response', {
|
|
15
15
|
persistent: true,
|
|
16
16
|
ignored: /(^|[\/\\])\../,
|
|
17
17
|
awaitWriteFinish: {
|
|
@@ -23,13 +23,13 @@ const watchApi = () => {
|
|
|
23
23
|
watcher.on('add', async filePath => {
|
|
24
24
|
const startTime = Date.now()
|
|
25
25
|
const fileName = path.basename(filePath, path.extname(filePath))
|
|
26
|
-
const spinner = ora(chalk.cyan(`🤖 Pod 153: [报告] 侦测到未知的
|
|
26
|
+
const spinner = ora(chalk.cyan(`🤖 Pod 153: [报告] 侦测到未知的 Response 数据源 [${fileName}],开始进行语义对齐...`))
|
|
27
27
|
spinner.start()
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
|
-
const
|
|
30
|
+
const responseStr = fs.readFileSync(filePath, 'utf8')
|
|
31
31
|
let resourceStr = fs.readFileSync(`./${config.pagesDir}/${fileName}/resource.js`, 'utf8')
|
|
32
|
-
const result = await
|
|
32
|
+
const result = await alignResponseFields(responseStr, resourceStr)
|
|
33
33
|
Object.entries(result).forEach(([oldField, newField]) => {
|
|
34
34
|
if (oldField === newField) return
|
|
35
35
|
const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
|
|
@@ -36,7 +36,7 @@ const watchPage = options => {
|
|
|
36
36
|
const { index, resource } = require(compilerPath)
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
|
-
//
|
|
39
|
+
// 首次运行时复制模板到目标项目
|
|
40
40
|
copyTemplateDir(options, 'hooks', config.hooksDir)
|
|
41
41
|
copyTemplateDir(options, 'utils', config.utilsDir)
|
|
42
42
|
copyTemplateDir(options, 'components', config.componentsDir)
|
package/src/prompts/watch-api.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
|
|
1
|
+
module.exports = (responseStr, resourceStr) => `
|
|
2
|
+
responseStr: ${responseStr}
|
|
3
3
|
resourceStr: ${resourceStr}
|
|
4
4
|
resourceStr是前端目前猜测的字段名列表(请从resourceStr中提取dataIndex和name),
|
|
5
|
-
|
|
5
|
+
responseStr是后端的真实响应。
|
|
6
6
|
请比对两者,找出现有前端字段名应该被替换为哪个真实的后端字段名。
|
|
7
7
|
匹配规则: 1.完全相同 2.下划线/驼峰转换 3.语义相似。
|
|
8
|
-
请只输出一个JSON对象, Key为前端猜测的旧名字, Value为
|
|
8
|
+
请只输出一个JSON对象, Key为前端猜测的旧名字, Value为Response里的真实新名字。
|
|
9
9
|
例如:{"key_1": "key1"}
|
|
10
10
|
如果没有找到对应的,请不要包含在结果中。
|
|
11
11
|
`.trim()
|
package/src/services/llm.js
CHANGED
|
@@ -117,12 +117,12 @@ module.exports = {
|
|
|
117
117
|
},
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* 对齐
|
|
121
|
-
* @param {string}
|
|
120
|
+
* 对齐 Response 接口字段与前端字段
|
|
121
|
+
* @param {string} responseStr - 真实接口响应数据
|
|
122
122
|
* @param {string} resourceStr - 前端 resource.js 内容
|
|
123
123
|
* @returns {Object} 字段映射对象 { oldName: newName }
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
alignResponseFields: async (responseStr, resourceStr) => {
|
|
126
126
|
const config = getConfig()
|
|
127
127
|
const apiPrompt = require('../prompts/watch-api.js')
|
|
128
128
|
const { API_DESIGNER } = require('../prompts/system.js')
|
|
@@ -130,7 +130,7 @@ module.exports = {
|
|
|
130
130
|
config.textModel,
|
|
131
131
|
[
|
|
132
132
|
{ role: 'system', content: API_DESIGNER },
|
|
133
|
-
{ role: 'user', content: apiPrompt(
|
|
133
|
+
{ role: 'user', content: apiPrompt(responseStr, resourceStr) }
|
|
134
134
|
]
|
|
135
135
|
)
|
|
136
136
|
}
|