@yorha2b-lab/autodev 1.0.4 → 1.0.5
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/bin/autodev.js +0 -12
- package/package.json +1 -1
- package/src/services/llm.js +3 -2
- package/src/utils/utils.js +1 -6
package/bin/autodev.js
CHANGED
|
@@ -26,18 +26,6 @@ program.version('1.0.0').description('AI驱动的前端CRUD代码生成器')
|
|
|
26
26
|
|
|
27
27
|
program.option('-t, --template <type>', '指定前端框架模板', 'react')
|
|
28
28
|
|
|
29
|
-
program
|
|
30
|
-
.command('init')
|
|
31
|
-
.description('在当前目录初始化 .env 和 config.js 配置文件')
|
|
32
|
-
.action(() => {
|
|
33
|
-
const tplConfig = path.resolve(__dirname, '../config.js')
|
|
34
|
-
const tplEnv = path.resolve(__dirname, '../.env.example')
|
|
35
|
-
fs.copyFileSync(tplConfig, path.join(process.cwd(), 'config.js'))
|
|
36
|
-
fs.copyFileSync(tplEnv, path.join(process.cwd(), '.env'))
|
|
37
|
-
console.log('✅ 已生成 config.js')
|
|
38
|
-
console.log('✅ 已生成 .env')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
29
|
program
|
|
42
30
|
.command('watch:page')
|
|
43
31
|
.description('监听截图,自动生成完整的增删改查页面')
|
package/package.json
CHANGED
package/src/services/llm.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
const JSON5 = require('json5')
|
|
2
2
|
const sharp = require('sharp')
|
|
3
|
+
const OpenAI = require('openai')
|
|
3
4
|
const mockPrompt = require('../prompts/mock.js')
|
|
5
|
+
const { getConfig } = require('../utils/utils.js')
|
|
4
6
|
const apiPrompt = require('../prompts/watch-api.js')
|
|
5
|
-
const { getConfig, initOpenAI } = require('../utils/utils.js')
|
|
6
7
|
const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = require('../prompts/system.js')
|
|
7
8
|
|
|
8
9
|
const config = getConfig()
|
|
9
|
-
const openai =
|
|
10
|
+
const openai = new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
|
|
10
11
|
|
|
11
12
|
const askAI = async (model, messages, retryCount = 0) => {
|
|
12
13
|
|
package/src/utils/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const OpenAI = require('openai')
|
|
4
3
|
|
|
5
4
|
const getConfig = () => {
|
|
6
5
|
const localConfigPath = path.join(process.cwd(), 'config.js')
|
|
@@ -13,10 +12,6 @@ const getConfig = () => {
|
|
|
13
12
|
return config
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const initOpenAI = () => {
|
|
17
|
-
return new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
/**
|
|
21
16
|
* 大模型输出的标准 JSON 无法携带 render: (text) => <Tag> 等箭头函数。
|
|
22
17
|
* 我们在 Prompt 中要求大模型用 _CODE_ 占位符包裹函数字符串,
|
|
@@ -80,4 +75,4 @@ const copyComponents = (options, componentsDir = 'src/components') => {
|
|
|
80
75
|
fs.readdirSync(componentsDirectory).forEach(file => fs.copyFileSync(path.join(componentsDirectory, file), path.join(targetDir, file)))
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
module.exports = { getConfig, copyHooks, cleanCode,
|
|
78
|
+
module.exports = { getConfig, copyHooks, cleanCode, copyComponents, getExistingMenus, generateSmartImports }
|