(possiblePaths, required = true)
| 67 | } |
| 68 | |
| 69 | export function loadJsonFile(possiblePaths, required = true) { |
| 70 | for (const filePath of possiblePaths) { |
| 71 | if (fs.existsSync(filePath)) { |
| 72 | try { |
| 73 | const content = fs.readFileSync(filePath, 'utf8') |
| 74 | return { data: JSON.parse(content), path: filePath } |
| 75 | } catch (error) { |
| 76 | log('ERROR', `解析JSON文件失败: ${filePath}`) |
| 77 | log('ERROR', `解析错误: ${error.message}`) |
| 78 | if (required) process.exit(1) |
| 79 | return null |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (required) { |
| 85 | log('ERROR', '找不到必需的文件') |
| 86 | log('ERROR', '在以下位置搜索:') |
| 87 | possiblePaths.forEach(p => log('ERROR', ` - ${p}`)) |
| 88 | process.exit(1) |
| 89 | } |
| 90 | |
| 91 | return null |
| 92 | } |
| 93 | |
| 94 | export function loadConfig(projectRoot, isDev = false) { |
| 95 | const possiblePaths = isDev |
no test coverage detected