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

Function loadJsonFile

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

Source from the content-addressed store, hash-verified

67}
68
69export 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
94export function loadConfig(projectRoot, isDev = false) {
95 const possiblePaths = isDev

Callers 3

clearSessions.jsFile · 0.90
loadConfigFunction · 0.85
loadAccountsFunction · 0.85

Calls 1

logFunction · 0.85

Tested by

no test coverage detected