-
Notifications
You must be signed in to change notification settings - Fork 0
/
configParser.js
79 lines (71 loc) · 3.1 KB
/
configParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 3 args: config filename, desired action (validate or getProp), prop to get
const fs = require('fs')
const action = process.argv[2]
const moduleId = process.argv[3]
let configPath = `${__dirname}/config.json`
if (!fs.existsSync(configPath)) {
configPath = `${__dirname}/config.default.json`
}
const config = require(configPath)
const moduleCustomization = config.moduleCustomization.filter(c => c.module === moduleId)[0] ?? {}
const getNtfyConfigsForModule = () => {
const moduleTopic = (moduleCustomization && moduleCustomization.ntfyTopic) || moduleId
const mainConfigName = (moduleCustomization && moduleCustomization.ntfyConfig) || config.ntfyConfig.defaultConfig
const fallBackConfigName = (moduleCustomization && moduleCustomization.ntfyFallback) || config.ntfyConfig.fallbackConfig
const mainConfig = mainConfigName && config.ntfyConfig.configs.filter(c => c.id === mainConfigName)[0]
const fallbackConfig = fallBackConfigName && mainConfigName != fallBackConfigName && config.ntfyConfig.configs.filter(c => c.id === fallBackConfigName)[0]
if (!mainConfig) {
console.error(`Could not determine main ntfy config for module '${moduleId}'!`)
process.exit(1)
}
const finalConfigs = [{ ...mainConfig, topic: `${mainConfig.topicPrefix || ''}${moduleTopic}` }]
if (fallbackConfig) {
finalConfigs.push({ ...fallbackConfig, topic: `${fallbackConfig.topicPrefix || ''}${moduleTopic}` })
}
return finalConfigs
}
switch (action) {
case 'isModuleEnabled':
console.log(
moduleCustomization.enabled === true ||
(config.modulesEnabledByDefault === true && moduleCustomization.enabled !== false)
)
break;
case 'shouldCatchModuleCrashes':
console.log(config.catchModuleCrashes === true)
break;
case 'getModuleAllowedFailCount':
console.log(config.allowModuleFailCount || 1)
break;
case 'getLoggerArgForModule':
if (moduleCustomization && moduleCustomization.loggerArg) {
console.log(moduleCustomization.loggerArg)
}
break;
case 'getParserArgForModule':
if (moduleCustomization && moduleCustomization.parserArg) {
console.log(moduleCustomization.parserArg)
}
break;
case 'getNtfyConfigsForModule':
console.log(JSON.stringify(getNtfyConfigsForModule()))
break;
case 'getModuleSummaryString':
const ntfyConfigs = process.argv[4] ? JSON.parse(process.argv[4]) : getNtfyConfigsForModule()
console.log(`'${moduleId}' to ${ntfyConfigs.map(c => `'${c.host}/${c.topic}'`).join(' or ')}`)
break;
case 'getDefaultPriorityForModule':
if (moduleCustomization && moduleCustomization.defaultPriority) {
console.log(moduleCustomization.defaultPriority)
}
break;
case 'getDefaultTagsForModule':
if (moduleCustomization && moduleCustomization.defaultTags) {
console.log(moduleCustomization.defaultTags)
}
break;
default:
console.error(`Unknown action '${action}'!`)
process.exit(1)
break;
}