29 lines
645 B
JavaScript
29 lines
645 B
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const homedir = require('os').homedir()
|
|
|
|
const configFilePath = homedir + path.sep + '.kafka-dance.json'
|
|
|
|
const emptyConfig = () => ({
|
|
clusters: {},
|
|
frontendUrl: 'http://localhost:5173',
|
|
})
|
|
|
|
const readConfig = () => {
|
|
if (fs.existsSync(configFilePath)) {
|
|
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
|
|
} |