@yorha2b-lab/autodev 1.0.6 → 1.0.8

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 CHANGED
@@ -3,6 +3,7 @@ const fs = require('fs')
3
3
  const path = require('path')
4
4
  const chalk = require('chalk')
5
5
  const figlet = require('figlet')
6
+ const { program } = require('commander')
6
7
 
7
8
  console.log(chalk.cyan(figlet.textSync('AutoDev', { horizontalLayout: 'full' })))
8
9
  console.log(chalk.gray('--------------------------------------------------'))
@@ -10,20 +11,7 @@ console.log(chalk.white(' [System] ') + chalk.green('YoRHa No.2 Type B Unit: ')
10
11
  console.log(chalk.white(' [Mission] ') + chalk.yellow('Generate Frontend CRUD: ') + chalk.cyan('Awaiting Command'))
11
12
  console.log(chalk.gray('--------------------------------------------------\n'))
12
13
 
13
- const localEnv = path.resolve(process.cwd(), '.env')
14
- const pkgEnv = path.resolve(__dirname, '../.env')
15
-
16
- require("dotenv").config({
17
- path: fs.existsSync(localEnv) ? localEnv : pkgEnv
18
- })
19
-
20
- const { program } = require('commander')
21
- const watchApi = require('../src/commands/watch-api')
22
- const watchPage = require('../src/commands/watch-page')
23
- const watchPart = require('../src/commands/watch-part')
24
-
25
14
  program.version('1.0.0').description('AI驱动的前端CRUD代码生成器')
26
-
27
15
  program.option('-t, --template <type>', '指定前端框架模板', 'react')
28
16
 
29
17
  program
@@ -41,16 +29,25 @@ program
41
29
  program
42
30
  .command('watch:page')
43
31
  .description('监听截图,自动生成完整的增删改查页面')
44
- .action(() => watchPage(program.opts()))
32
+ .action(() => {
33
+ const watchPage = require('../src/commands/watch-page')
34
+ watchPage(program.opts())
35
+ })
45
36
 
46
37
  program
47
38
  .command('watch:part')
48
39
  .description('监听截图,自动生成局部 UI 组件')
49
- .action(() => watchPart(program.opts()))
40
+ .action(() => {
41
+ const watchPart = require('../src/commands/watch-part')
42
+ watchPart(program.opts())
43
+ })
50
44
 
51
45
  program
52
46
  .command('watch:api')
53
47
  .description('监听 Swagger,自动对齐真实接口字段')
54
- .action(() => watchApi())
48
+ .action(() => {
49
+ const watchApi = require('../src/commands/watch-api')
50
+ watchApi()
51
+ })
55
52
 
56
53
  program.parse(process.argv)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -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
@@ -1,17 +1,19 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
1
3
  const JSON5 = require('json5')
2
4
  const sharp = require('sharp')
3
5
  const OpenAI = require('openai')
4
- const mockPrompt = require('../prompts/mock.js')
5
6
  const { getConfig } = require('../utils/utils.js')
6
- const apiPrompt = require('../prompts/watch-api.js')
7
- const { UI_DESIGNER, API_DESIGNER, MOCK_DESIGNER } = require('../prompts/system.js')
8
-
9
- const config = getConfig()
10
7
 
11
8
  let client = null
12
9
 
13
10
  const getOpenAI = () => {
14
11
  if (!client) {
12
+ const localEnv = path.resolve(process.cwd(), '.env')
13
+ const pkgEnv = path.resolve(__dirname, '../.env')
14
+ require("dotenv").config({
15
+ path: fs.existsSync(localEnv) ? localEnv : pkgEnv
16
+ })
15
17
  client = new OpenAI({ apiKey: process.env.API_KEY, baseURL: process.env.BASE_URL })
16
18
  }
17
19
  return client
@@ -36,6 +38,9 @@ const askAI = async (model, messages, retryCount = 0) => {
36
38
 
37
39
  module.exports = {
38
40
  generateMock: async (columns, fileName) => {
41
+ const config = getConfig()
42
+ const mockPrompt = require('../prompts/mock.js')
43
+ const { MOCK_DESIGNER } = require('../prompts/system.js')
39
44
  return askAI(
40
45
  config.textModel,
41
46
  [
@@ -45,11 +50,15 @@ module.exports = {
45
50
  )
46
51
  },
47
52
  recognizePage: async (prompt, filePath) => {
53
+ const config = getConfig()
54
+ const { UI_DESIGNER } = require('../prompts/system.js')
55
+
48
56
  const compressedBuffer = await sharp(filePath)
49
57
  .resize(1280, null, { withoutEnlargement: true })
50
58
  .jpeg({ quality: 80 })
51
59
  .toBuffer()
52
60
  const base64Image = compressedBuffer.toString('base64')
61
+
53
62
  return askAI(
54
63
  config.visionModel,
55
64
  [
@@ -65,6 +74,9 @@ module.exports = {
65
74
  )
66
75
  },
67
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')
68
80
  return askAI(
69
81
  config.textModel,
70
82
  [