MCPcopy Create free account
hub / github.com/TheNetsky/Microsoft-Rewards-Script / loadJsonFile

Function loadJsonFile

scripts/utils.js:57–79  ·  view source on GitHub ↗
(possiblePaths, required = true)

Source from the content-addressed store, hash-verified

55}
56
57export 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
81export function loadConfig(projectRoot) {
82 const possiblePaths = [

Callers 1

loadConfigFunction · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected