@yorha2b-lab/autodev 1.0.15 → 1.0.17
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/package.json
CHANGED
|
@@ -17,7 +17,7 @@ const watchPage = options => {
|
|
|
17
17
|
const { createTaskQueue } = require('../core/task-queue') // 任务队列,控制并发
|
|
18
18
|
const stringify = require('json-stringify-pretty-compact') // 格式化 JSON
|
|
19
19
|
const { recognizePage, generateMock } = require('../services/llm.js') // AI 服务
|
|
20
|
-
const { getConfig,
|
|
20
|
+
const { getConfig, copyTemplateDir, getExistingMenus } = require('../utils/utils.js') // 工具函数
|
|
21
21
|
|
|
22
22
|
const config = getConfig()
|
|
23
23
|
|
|
@@ -37,8 +37,8 @@ const watchPage = options => {
|
|
|
37
37
|
|
|
38
38
|
try {
|
|
39
39
|
// 首次运行时复制 hooks 和 components 模板到目标项目
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
copyTemplateDir(options, 'hooks', config.hooksDir)
|
|
41
|
+
copyTemplateDir(options, 'components', config.componentsDir)
|
|
42
42
|
} catch (error) {
|
|
43
43
|
console.error('❌ 程序运行出错:', error)
|
|
44
44
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -86,28 +86,24 @@ const generateSmartImports = (codeStr, hasTabs) => {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* 复制模板目录到目标项目
|
|
90
90
|
* @param {Object} options - 命令行选项
|
|
91
|
-
* @param {string}
|
|
91
|
+
* @param {string} templateSubDir - 模板子目录(如 'hooks'、'components')
|
|
92
|
+
* @param {string} targetSubDir - 目标子目录(如 'src/hooks'、'src/components')
|
|
92
93
|
*/
|
|
93
|
-
const
|
|
94
|
-
const targetDir = path.join(process.cwd(),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
fs.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const copyComponents = (options, componentsDir = 'src/components') => {
|
|
106
|
-
const targetDir = path.join(process.cwd(), componentsDir)
|
|
107
|
-
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true }) // 递归创建目录
|
|
108
|
-
const componentsDirectory = path.join(__dirname, `../../templates/${options.template}/components`)
|
|
109
|
-
fs.readdirSync(componentsDirectory).forEach(file => fs.copyFileSync(path.join(componentsDirectory, file), path.join(targetDir, file)))
|
|
94
|
+
const copyTemplateDir = (options, templateSubDir, targetSubDir) => {
|
|
95
|
+
const targetDir = path.join(process.cwd(), targetSubDir)
|
|
96
|
+
const sourceDir = path.join(__dirname, `../../templates/${options.template}/${templateSubDir}`)
|
|
97
|
+
if (!fs.existsSync(sourceDir)) return
|
|
98
|
+
fs.mkdirSync(targetDir, { recursive: true })
|
|
99
|
+
fs.readdirSync(sourceDir).forEach(file => {
|
|
100
|
+
const src = path.join(sourceDir, file)
|
|
101
|
+
const dest = path.join(targetDir, file)
|
|
102
|
+
if (!fs.existsSync(dest)) {
|
|
103
|
+
fs.copyFileSync(src, dest)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
110
106
|
}
|
|
111
107
|
|
|
112
108
|
// 导出工具函数
|
|
113
|
-
module.exports = { getConfig,
|
|
109
|
+
module.exports = { getConfig, cleanCode, getExistingMenus, copyTemplateDir, generateSmartImports }
|