| 55 | } |
| 56 | |
| 57 | export function loadJsonFile(possiblePaths, required = true) { |
| 58 | for (const filePath of possiblePaths) { |
| 59 | if (fs.existsSync(filePath)) { |
| 60 | try { |
| 61 | const content = fs.readFileSync(filePath, 'utf8') |
| 62 | return { data: JSON.parse(content), path: filePath } |
| 63 | } catch (error) { |
| 64 | log('ERROR', `Failed to parse JSON file: ${filePath}`) |
| 65 | log('ERROR', `Parse error: ${error.message}`) |
| 66 | if (required) process.exit(1) |
| 67 | return null |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (required) { |
| 73 | log('ERROR', 'Required file not found. Searched in:') |
| 74 | possiblePaths.forEach(p => log('ERROR', ` - ${p}`)) |
| 75 | process.exit(1) |
| 76 | } |
| 77 | |
| 78 | return null |
| 79 | } |
| 80 | |
| 81 | export function loadConfig(projectRoot) { |
| 82 | const possiblePaths = [ |