const { readFileSync, existsSync } = require('fs') const { resolve } = require('path') /** * 路由分析模块 * 负责分析路由配置 */ class RouteAnalyzer { constructor() { this.routes = [] } /** * 分析路由配置 * @returns {Array} 路由数组 */ analyzeRoutes() { this.routes = [] try { const routeConfigPath = resolve(__dirname, '../../src/renderer/router/index.js') if (existsSync(routeConfigPath)) { const routeContent = readFileSync(routeConfigPath, 'utf-8') this.routes = this.parseRouteConfig(routeContent) } } catch (error) { // 静默处理错误 } return this.routes } /** * 解析路由配置 * @param {string} routeContent - 路由配置内容 * @returns {Array} 路由数组 */ parseRouteConfig(routeContent) { const routes = [] // 简单的路由解析,查找路由定义 const routeMatches = routeContent.match(/path:\s*['"]([^'"]+)['"][\s\S]*?component:\s*['"]([^'"]+)['"]/g) if (routeMatches) { routeMatches.forEach(match => { const pathMatch = match.match(/path:\s*['"]([^'"]+)['"]/) const componentMatch = match.match(/component:\s*['"]([^'"]+)['"]/) if (pathMatch && componentMatch) { routes.push({ path: pathMatch[1], component: componentMatch[1] }) } }) } return routes } /** * 获取模块列表 * @returns {Array} 模块目录列表 */ getModuleDirs() { const moduleDirs = [] try { const modulesPath = resolve(__dirname, '../../src/renderer/modules') if (existsSync(modulesPath)) { const dirs = require('fs').readdirSync(modulesPath, { withFileTypes: true }) dirs.forEach(dirent => { if (dirent.isDirectory()) { moduleDirs.push(dirent.name) } }) } } catch (error) { // 静默处理错误 } return moduleDirs } } module.exports = RouteAnalyzer