Config: preparing the arrival of new config files (for bots). Code refactoring.

This commit is contained in:
John Livingston
2021-12-07 11:59:32 +01:00
parent 2244ae22c2
commit f8ce4e6583
4 changed files with 102 additions and 68 deletions

View File

@ -113,20 +113,23 @@ async function testProsodyCorrectlyRunning (options: RegisterServerOptions): Pro
try {
const wantedConfig = await getProsodyConfig(options)
const filePath = wantedConfig.paths.config
const configFiles = wantedConfig.getConfigFiles()
for (const configFile of configFiles) {
const filePath = configFile.path
await fs.promises.access(filePath, fs.constants.R_OK) // throw an error if file does not exist.
result.messages.push(`The prosody configuration file (${filePath}) exists`)
const actualContent = await fs.promises.readFile(filePath, {
encoding: 'utf-8'
})
await fs.promises.access(filePath, fs.constants.R_OK) // throw an error if file does not exist.
result.messages.push(`The prosody configuration file (${configFile.key}: ${filePath}) exists`)
const actualContent = await fs.promises.readFile(filePath, {
encoding: 'utf-8'
})
const wantedContent = wantedConfig.content
if (actualContent === wantedContent) {
result.messages.push('Prosody configuration file content is correct.')
} else {
result.messages.push('Prosody configuration file content is not correct.')
return result
const wantedContent = configFile.content
if (actualContent === wantedContent) {
result.messages.push(`Prosody configuration file '${configFile.key}' content is correct.`)
} else {
result.messages.push(`Prosody configuration file '${configFile.key}' content is not correct.`)
return result
}
}
} catch (error) {
result.messages.push('Error when requiring the prosody config file: ' + (error as string))