2022-08-18 16:45:43 -04:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const homedir = require('os').homedir()
|
|
|
|
|
|
|
|
const configFilePath = homedir + path.sep + '.kafka-dance'
|
|
|
|
|
|
|
|
const emptyConfig = () => ({
|
2022-09-08 21:51:10 -04:00
|
|
|
clusters: {},
|
|
|
|
frontendUrl: 'http://localhost:5173',
|
2022-08-18 16:45:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
const readConfig = () => {
|
2022-09-08 21:51:10 -04:00
|
|
|
if (fs.existsSync(configFilePath)) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(fs.readFileSync(configFilePath).toString())
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.toString())
|
|
|
|
}
|
2022-08-18 16:45:43 -04:00
|
|
|
}
|
2022-09-08 21:51:10 -04:00
|
|
|
return emptyConfig()
|
2022-08-18 16:45:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const storeConfig = async config =>
|
|
|
|
fs.writeFile(configFilePath, JSON.stringify(config, null, 2), console.error)
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
readConfig,
|
|
|
|
storeConfig
|
|
|
|
}
|