kafka-dance-api/config.js

29 lines
617 B
JavaScript
Raw Normal View History

const fs = require('fs')
const path = require('path')
const homedir = require('os').homedir()
const configFilePath = homedir + path.sep + '.kafka-dance'
const emptyConfig = () => ({
clusters: {}
})
const readConfig = () => {
if (!fs.existsSync(configFilePath)) {
return emptyConfig()
}
try {
return JSON.parse(fs.readFileSync(configFilePath).toString())
} catch (e) {
console.error(e.toString())
return emptyConfig()
}
}
const storeConfig = async config =>
fs.writeFile(configFilePath, JSON.stringify(config, null, 2), console.error)
module.exports = {
readConfig,
storeConfig
}