Browse Source

前端路由关系收集基本OK

master
hejl 17 hours ago
parent
commit
bd6679dabd
  1. 4
      gofaster/app/plugins/modules/api-collector.js
  2. 5
      gofaster/app/plugins/modules/component-relationship-analyzer-ast.js
  3. 1
      gofaster/app/plugins/modules/data-cleaner.js
  4. 1
      gofaster/app/plugins/modules/trigger-analyzer-simple.js
  5. 15
      gofaster/app/plugins/modules/trigger-analyzer.js
  6. 9
      gofaster/app/plugins/route-mapping-plugin.js
  7. 2
      gofaster/app/src/renderer/modules/route-sync/direct-route-mappings.js

4
gofaster/app/plugins/modules/api-collector.js

@ -40,7 +40,6 @@ class ApiCollector {
// 如果无法从配置文件获取,返回空字符串(使用相对路径) // 如果无法从配置文件获取,返回空字符串(使用相对路径)
return '' return ''
} catch (error) { } catch (error) {
console.warn('⚠ 无法获取API基础URL,使用相对路径:', error.message)
return '' return ''
} }
} }
@ -101,7 +100,6 @@ class ApiCollector {
const serviceApiMappings = this.analyzeServiceFile(servicePath, serviceName, moduleName) const serviceApiMappings = this.analyzeServiceFile(servicePath, serviceName, moduleName)
moduleApiMappings.push(...serviceApiMappings) moduleApiMappings.push(...serviceApiMappings)
} catch (error) { } catch (error) {
console.error(`分析服务文件失败: ${serviceFile}`, error.message)
} }
}) })
@ -149,7 +147,6 @@ class ApiCollector {
} }
}) })
} catch (error) { } catch (error) {
console.error(`❌ 分析服务文件失败: ${servicePath}`, error.message)
} }
return apiMappings return apiMappings
@ -249,7 +246,6 @@ class ApiCollector {
} }
} }
} catch (error) { } catch (error) {
console.error(`❌ 解析注解失败: ${servicePath}`, error.message)
} }
return null return null

5
gofaster/app/plugins/modules/component-relationship-analyzer-ast.js

@ -39,14 +39,12 @@ class ComponentRelationshipAnalyzerAST {
...component ...component
})) }))
console.log(`🔍 开始分析组件关系,触发源组件数量: ${triggerSourceComponents.length}`)
// 为每个触发源组件分析其与顶级组件的关系 // 为每个触发源组件分析其与顶级组件的关系
triggerSourceComponents.forEach(triggerComponent => { triggerSourceComponents.forEach(triggerComponent => {
this.analyzeComponentToTopLevel(triggerComponent, topLevelComponents) this.analyzeComponentToTopLevel(triggerComponent, topLevelComponents)
}) })
console.log(`🔍 分析完成,找到 ${this.componentRelationships.length} 个组件关系`)
return this.componentRelationships return this.componentRelationships
} }
@ -96,7 +94,6 @@ class ComponentRelationshipAnalyzerAST {
// 避免重复处理同一个触发源 // 避免重复处理同一个触发源
if (this.processedComponents.has(triggerKey)) { if (this.processedComponents.has(triggerKey)) {
console.log(` 跳过重复处理: ${triggerKey}`)
return return
} }
@ -204,7 +201,6 @@ class ComponentRelationshipAnalyzerAST {
viewFiles.forEach(file => { viewFiles.forEach(file => {
const componentName = file.replace('.vue', '') const componentName = file.replace('.vue', '')
if (this.componentReferencesTargetAST(viewsPath, file, targetComponent)) { if (this.componentReferencesTargetAST(viewsPath, file, targetComponent)) {
console.log(`🔍 找到父组件: ${moduleName}:${componentName} -> ${targetComponent.module}:${targetComponent.component}`)
parents.push({ parents.push({
component: componentName, component: componentName,
module: moduleName, module: moduleName,
@ -221,7 +217,6 @@ class ComponentRelationshipAnalyzerAST {
componentFiles.forEach(file => { componentFiles.forEach(file => {
const componentName = file.replace('.vue', '') const componentName = file.replace('.vue', '')
if (this.componentReferencesTargetAST(componentsPath, file, targetComponent)) { if (this.componentReferencesTargetAST(componentsPath, file, targetComponent)) {
console.log(`🔍 找到父组件: ${moduleName}:${componentName} -> ${targetComponent.module}:${targetComponent.component}`)
parents.push({ parents.push({
component: componentName, component: componentName,
module: moduleName, module: moduleName,

1
gofaster/app/plugins/modules/data-cleaner.js

@ -34,7 +34,6 @@ class DataCleaner {
return cleanedMappings return cleanedMappings
} catch (error) { } catch (error) {
console.error('❌ 清理数据结构失败:', error.message)
return null return null
} }
} }

1
gofaster/app/plugins/modules/trigger-analyzer-simple.js

@ -95,7 +95,6 @@ class TriggerAnalyzerSimple {
} }
} }
} catch (error) { } catch (error) {
console.warn(`获取模块组件时出错: ${error.message}`)
} }
return components return components

15
gofaster/app/plugins/modules/trigger-analyzer.js

@ -98,7 +98,6 @@ class TriggerAnalyzer {
}) })
} }
} catch (error) { } catch (error) {
console.warn(`分析模块 ${moduleName} 时出错:`, error.message)
} }
// 去重 // 去重
@ -522,7 +521,6 @@ class TriggerAnalyzer {
}) })
} }
} catch (error) { } catch (error) {
console.warn(`扫描模块 ${moduleDir} 的组件时出错:`, error.message)
} }
} }
@ -557,7 +555,6 @@ class TriggerAnalyzer {
} }
} }
} catch (error) { } catch (error) {
console.warn(`获取组件 ${componentName} 的authType时出错:`, error.message)
} }
return null return null
@ -618,7 +615,6 @@ class TriggerAnalyzer {
}) })
} catch (error) { } catch (error) {
console.warn(`分析组件 ${filePath} 时出错:`, error.message)
} }
return triggerSources return triggerSources
@ -645,7 +641,6 @@ class TriggerAnalyzer {
return ast return ast
} catch (error) { } catch (error) {
console.warn('解析Vue组件脚本时出错:', error.message)
return null return null
} }
} }
@ -903,7 +898,6 @@ class TriggerAnalyzer {
} }
} catch (error) { } catch (error) {
console.warn(`追溯可视组件时出错:`, error.message)
} }
return null return null
@ -967,7 +961,6 @@ class TriggerAnalyzer {
return this.findEventBindingInTemplate(templateAst, methodName, componentName, filePath) return this.findEventBindingInTemplate(templateAst, methodName, componentName, filePath)
} catch (error) { } catch (error) {
console.warn(`解析Vue模板时出错:`, error.message)
return null return null
} }
} }
@ -1249,7 +1242,6 @@ class TriggerAnalyzer {
// 获取节点的位置信息 // 获取节点的位置信息
const loc = node.loc const loc = node.loc
if (!loc) { if (!loc) {
console.warn(`节点没有位置信息,无法添加name属性`)
return return
} }
@ -1257,7 +1249,6 @@ class TriggerAnalyzer {
const startLine = loc.start.line const startLine = loc.start.line
const startColumn = loc.start.column const startColumn = loc.start.column
console.log(`尝试为第${startLine}行第${startColumn}列的button添加name属性: ${nameValue}`)
// 将内容按行分割 // 将内容按行分割
const lines = content.split('\n') const lines = content.split('\n')
@ -1267,7 +1258,6 @@ class TriggerAnalyzer {
const lineIndex = startLine - 1 const lineIndex = startLine - 1
let line = lines[lineIndex] let line = lines[lineIndex]
console.log(`当前行内容: ${line}`)
// 在button标签中添加name属性 // 在button标签中添加name属性
// 查找button标签的开始位置 // 查找button标签的开始位置
@ -1286,7 +1276,6 @@ class TriggerAnalyzer {
const newContent = lines.join('\n') const newContent = lines.join('\n')
writeFileSync(filePath, newContent, 'utf-8') writeFileSync(filePath, newContent, 'utf-8')
console.log(`已为 ${filePath} 中的button添加name属性: ${nameValue}`)
} else { } else {
// 如果button标签跨行,查找button开始标签 // 如果button标签跨行,查找button开始标签
const buttonStartMatch = line.match(/<button[^>]*$/) const buttonStartMatch = line.match(/<button[^>]*$/)
@ -1303,16 +1292,12 @@ class TriggerAnalyzer {
const newContent = lines.join('\n') const newContent = lines.join('\n')
writeFileSync(filePath, newContent, 'utf-8') writeFileSync(filePath, newContent, 'utf-8')
console.log(`已为 ${filePath} 中的跨行button添加name属性: ${nameValue}`)
} else { } else {
console.warn(`未找到button标签`)
} }
} }
} else { } else {
console.warn(`行号超出范围: ${startLine}`)
} }
} catch (error) { } catch (error) {
console.warn(`为Vue文件添加name属性时出错:`, error.message)
} }
} }

9
gofaster/app/plugins/route-mapping-plugin.js

@ -12,15 +12,7 @@ const ComponentRelationshipAnalyzerAST = require('./modules/component-relationsh
* 收集直接映射关系 * 收集直接映射关系
*/ */
function routeMappingPlugin() { function routeMappingPlugin() {
// 检查是否在静默模式下运行
const isSilentMode = process.env.ROUTE_MAPPING_SILENT === 'true' || process.argv.includes('--silent')
// 日志函数
const log = (message) => {
if (!isSilentMode) {
console.log(message)
}
}
return { return {
name: 'route-mapping-phase1', name: 'route-mapping-phase1',
@ -175,7 +167,6 @@ function routeMappingPlugin() {
} catch (error) { } catch (error) {
this._generationInProgress = false this._generationInProgress = false
console.error('❌ 生成direct-route-mappings.js时出错:', error)
throw error throw error
} }
} }

2
gofaster/app/src/renderer/modules/route-sync/direct-route-mappings.js

@ -252,7 +252,7 @@ export default {
"id": 15, "id": 15,
"component": "PasswordChangeModal", "component": "PasswordChangeModal",
"module": "user-management", "module": "user-management",
"triggerName": "passwordchangemodal-input-0xe3cd", "triggerName": "passwordchangemodal-input-l447v0",
"triggerType": "input" "triggerType": "input"
} }
] ]

Loading…
Cancel
Save