@yorha2b-lab/autodev 1.0.7 → 1.0.9
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 +6 -0
- package/package.json +1 -1
- package/src/commands/watch-api.js +3 -2
- package/src/commands/watch-page.js +8 -7
- package/src/commands/watch-part.js +5 -2
- package/src/core/react-compiler.js +1 -0
- package/src/prompts/watch-page.js +2 -1
- package/src/services/llm.js +10 -6
- package/templates/react/components/EditableCell.js +1 -1
- package/templates/react/components/MyTable.js +2 -2
- package/templates/react/index.hbs +19 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const chokidar = require('chokidar')
|
|
4
|
-
const { getConfig } = require('../utils/utils.js')
|
|
5
|
-
const { alignSwaggerFields } = require('../services/llm.js')
|
|
6
4
|
|
|
7
5
|
const watchApi = () => {
|
|
8
6
|
|
|
7
|
+
const { getConfig } = require('../utils/utils.js')
|
|
8
|
+
const { alignSwaggerFields } = require('../services/llm.js')
|
|
9
|
+
|
|
9
10
|
const config = getConfig()
|
|
10
11
|
|
|
11
12
|
const watcher = chokidar.watch('./swagger', {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const ora = require('ora')
|
|
3
3
|
const path = require('path')
|
|
4
|
-
const chokidar = require('chokidar')
|
|
5
|
-
const Handlebars = require('handlebars')
|
|
6
|
-
const pagePrompt = require('../prompts/watch-page.js')
|
|
7
|
-
const { createTaskQueue } = require('../core/task-queue')
|
|
8
|
-
const stringify = require('json-stringify-pretty-compact')
|
|
9
|
-
const { recognizePage, generateMock } = require('../services/llm.js')
|
|
10
|
-
const { getConfig, copyHooks, copyComponents, getExistingMenus } = require('../utils/utils.js')
|
|
11
4
|
|
|
12
5
|
const watchPage = options => {
|
|
13
6
|
|
|
7
|
+
const chokidar = require('chokidar')
|
|
8
|
+
const Handlebars = require('handlebars')
|
|
9
|
+
const pagePrompt = require('../prompts/watch-page.js')
|
|
10
|
+
const { createTaskQueue } = require('../core/task-queue')
|
|
11
|
+
const stringify = require('json-stringify-pretty-compact')
|
|
12
|
+
const { recognizePage, generateMock } = require('../services/llm.js')
|
|
13
|
+
const { getConfig, copyHooks, copyComponents, getExistingMenus } = require('../utils/utils.js')
|
|
14
|
+
|
|
14
15
|
const config = getConfig()
|
|
15
16
|
const compilerPath = path.join(__dirname, `../core/${options.template}-compiler.js`)
|
|
16
17
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const chokidar = require('chokidar')
|
|
3
|
-
const partPrompt = require('../prompts/watch-part.js')
|
|
4
|
-
const { recognizePage } = require('../services/llm.js')
|
|
5
3
|
const stringify = require('json-stringify-pretty-compact')
|
|
6
4
|
|
|
7
5
|
const watchPart = () => {
|
|
6
|
+
|
|
7
|
+
const { recognizePage } = require('../services/llm.js')
|
|
8
|
+
|
|
8
9
|
const watcher = chokidar.watch('./screenPart', {
|
|
9
10
|
persistent: true,
|
|
10
11
|
ignored: /(^|[\/\\])\../,
|
|
@@ -13,10 +14,12 @@ const watchPart = () => {
|
|
|
13
14
|
pollInterval: 100
|
|
14
15
|
}
|
|
15
16
|
})
|
|
17
|
+
|
|
16
18
|
watcher.on('add', async filePath => {
|
|
17
19
|
try {
|
|
18
20
|
const startTime = Date.now()
|
|
19
21
|
console.log(`🚀 检测到新图片: 开始识别...`)
|
|
22
|
+
const partPrompt = require('../prompts/watch-part.js')
|
|
20
23
|
const pageConfig = await recognizePage(partPrompt, filePath)
|
|
21
24
|
const optionDict = pageConfig.optionDict || {}
|
|
22
25
|
delete pageConfig.optionDict
|
|
@@ -37,6 +37,7 @@ const index = ({ fileName, indexTpl, pageConfig }) => {
|
|
|
37
37
|
hasOperate,
|
|
38
38
|
columnsValue,
|
|
39
39
|
tabs: pageConfig.tabs,
|
|
40
|
+
hasExpandable: pageConfig.table.expandable,
|
|
40
41
|
hasPagination: pageConfig.table.pagination,
|
|
41
42
|
operations: pageConfig.table.operation || [],
|
|
42
43
|
hasRowSelection: pageConfig.table.rowSelection,
|
|
@@ -15,6 +15,7 @@ module.exports = `
|
|
|
15
15
|
4.表格:
|
|
16
16
|
{
|
|
17
17
|
pagination: true/false,
|
|
18
|
+
expandable: true/false,
|
|
18
19
|
rowSelection: true/false,
|
|
19
20
|
staticInfo:{has:true/false,text:''},
|
|
20
21
|
operation: [{label:'操作',action:'操作动词+ByRecord'}],
|
|
@@ -28,7 +29,7 @@ module.exports = `
|
|
|
28
29
|
如果是下拉框列(所对应的查询项明确是下拉框),请加入render:_CODE_text=>对应的options.find(item=>item.value===text)?.label_CODE_
|
|
29
30
|
如果列需要过滤请加上filters:[],onFilter: _CODE_(value, record) => record[对应的英文名词].includes(value)_CODE_
|
|
30
31
|
5.功能按钮
|
|
31
|
-
functionButtion:[{btn:'btn',action:'
|
|
32
|
+
functionButtion:[{btn:'btn',action:'操作动词+模块英文名词'}]
|
|
32
33
|
如果和表格行操作重复请在action加上BySelected前缀
|
|
33
34
|
如果是导出功能,对应的动词为export+对应的英文名词,没有名词则为exportData
|
|
34
35
|
6.下拉选项字典
|
package/src/services/llm.js
CHANGED
|
@@ -3,18 +3,12 @@ const path = require('path')
|
|
|
3
3
|
const JSON5 = require('json5')
|
|
4
4
|
const sharp = require('sharp')
|
|
5
5
|
const OpenAI = require('openai')
|
|
6
|
-
const mockPrompt = require('../prompts/mock.js')
|
|
7
6
|
const { getConfig } = require('../utils/utils.js')
|
|
8
|
-
const apiPrompt = require('../prompts/watch-api.js')
|
|
9
|
-
const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = require('../prompts/system.js')
|
|
10
|
-
|
|
11
|
-
const config = getConfig()
|
|
12
7
|
|
|
13
8
|
let client = null
|
|
14
9
|
|
|
15
10
|
const getOpenAI = () => {
|
|
16
11
|
if (!client) {
|
|
17
|
-
|
|
18
12
|
const localEnv = path.resolve(process.cwd(), '.env')
|
|
19
13
|
const pkgEnv = path.resolve(__dirname, '../.env')
|
|
20
14
|
require("dotenv").config({
|
|
@@ -44,6 +38,9 @@ const askAI = async (model, messages, retryCount = 0) => {
|
|
|
44
38
|
|
|
45
39
|
module.exports = {
|
|
46
40
|
generateMock: async (columns, fileName) => {
|
|
41
|
+
const config = getConfig()
|
|
42
|
+
const mockPrompt = require('../prompts/mock.js')
|
|
43
|
+
const { MOCK_DESIGNER } = require('../prompts/system.js')
|
|
47
44
|
return askAI(
|
|
48
45
|
config.textModel,
|
|
49
46
|
[
|
|
@@ -53,11 +50,15 @@ module.exports = {
|
|
|
53
50
|
)
|
|
54
51
|
},
|
|
55
52
|
recognizePage: async (prompt, filePath) => {
|
|
53
|
+
const config = getConfig()
|
|
54
|
+
const { UI_DESIGNER } = require('../prompts/system.js')
|
|
55
|
+
|
|
56
56
|
const compressedBuffer = await sharp(filePath)
|
|
57
57
|
.resize(1280, null, { withoutEnlargement: true })
|
|
58
58
|
.jpeg({ quality: 80 })
|
|
59
59
|
.toBuffer()
|
|
60
60
|
const base64Image = compressedBuffer.toString('base64')
|
|
61
|
+
|
|
61
62
|
return askAI(
|
|
62
63
|
config.visionModel,
|
|
63
64
|
[
|
|
@@ -73,6 +74,9 @@ module.exports = {
|
|
|
73
74
|
)
|
|
74
75
|
},
|
|
75
76
|
alignSwaggerFields: async (swaggerStr, resourceStr) => {
|
|
77
|
+
const config = getConfig()
|
|
78
|
+
const apiPrompt = require('../prompts/watch-api.js')
|
|
79
|
+
const { API_DESIGNER } = require('../prompts/system.js')
|
|
76
80
|
return askAI(
|
|
77
81
|
config.textModel,
|
|
78
82
|
[
|
|
@@ -49,7 +49,7 @@ export const EditableCell = ({ title, record, editable, children, dataIndex, han
|
|
|
49
49
|
inputNode = <InputNumber ref={inputRef} onPressEnter={save} onBlur={save} />
|
|
50
50
|
break
|
|
51
51
|
case 'select':
|
|
52
|
-
inputNode = <Select ref={inputRef} options={options} onBlur={save}
|
|
52
|
+
inputNode = <Select ref={inputRef} options={options} onBlur={save} />
|
|
53
53
|
break;
|
|
54
54
|
case 'checkbox':
|
|
55
55
|
inputNode = <Checkbox.Group options={options} onChange={save} />
|
|
@@ -8,7 +8,7 @@ const components = {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const MyTable = ({ size, onSave, onChange, pagination, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], editable = false, scroll = { x: 'max-content' }, ...restProps }) => {
|
|
11
|
+
export const MyTable = ({ size, onSave, onChange, pagination, rowClassName, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], editable = false, scroll = { x: 'max-content' }, ...restProps }) => {
|
|
12
12
|
|
|
13
13
|
const mergedColumns = columns.map(col => {
|
|
14
14
|
if (!col.editable) {
|
|
@@ -42,7 +42,7 @@ export const MyTable = ({ size, onSave, onChange, pagination, columns = [], rowS
|
|
|
42
42
|
size={size ?? 'middle'}
|
|
43
43
|
rowSelection={rowSelection}
|
|
44
44
|
components={editable ? components : undefined}
|
|
45
|
-
rowClassName={editable ? () => 'editable-row' :
|
|
45
|
+
rowClassName={editable ? () => 'editable-row' : rowClassName}
|
|
46
46
|
/>
|
|
47
47
|
)
|
|
48
48
|
}
|
|
@@ -5,6 +5,9 @@ export default props => {
|
|
|
5
5
|
{{#if hasTabs}}
|
|
6
6
|
const [activeKey, setActiveKey] = useState(tabs[0].key)
|
|
7
7
|
{{/if}}
|
|
8
|
+
{{#if hasExpandable}}
|
|
9
|
+
const [expandedRowKeys, setExpandedRowKeys] = useState([])
|
|
10
|
+
{{/if}}
|
|
8
11
|
{{#if hasRowSelection}}
|
|
9
12
|
const [selectedRows, setSelectedRows] = useState([])
|
|
10
13
|
{{/if}}
|
|
@@ -48,6 +51,19 @@ export default props => {
|
|
|
48
51
|
}
|
|
49
52
|
{{/if}}
|
|
50
53
|
|
|
54
|
+
{{#if hasExpandable}}
|
|
55
|
+
const onExpand = async (expanded, record) => {
|
|
56
|
+
if (expanded) {
|
|
57
|
+
setExpandedRowKeys([...expandedRowKeys, record.key])
|
|
58
|
+
} else {
|
|
59
|
+
setExpandedRowKeys(expandedRowKeys.filter(item => item !== record.key))
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const expandedRowRender = record => (<div>自定义渲染</div>)
|
|
64
|
+
|
|
65
|
+
{{/if}}
|
|
66
|
+
|
|
51
67
|
const modalSubmit = async values => {
|
|
52
68
|
const response = await request('/api')
|
|
53
69
|
refresh()
|
|
@@ -94,6 +110,9 @@ export default props => {
|
|
|
94
110
|
loading={loading}
|
|
95
111
|
dataSource={dataSource}
|
|
96
112
|
columns={ {{columnsValue}} }
|
|
113
|
+
{{#if hasExpandable}}
|
|
114
|
+
expandable=\{{ onExpand, expandedRowKeys, expandedRowRender, columnWidth: 24 }}
|
|
115
|
+
{{/if}}
|
|
97
116
|
{{#if hasPagination}}
|
|
98
117
|
pagination=\{{ total, showSizeChanger: true, current: search.pageNo, pageSize: search.pageSize }}
|
|
99
118
|
onChange={(pagination, filters, sorter) => setSearch({ ...search , pageNo: pagination.current, pageSize: pagination.pageSize, orderBy: sorter.column ? sorter.field : undefined })}
|