21 lines
591 B
JavaScript
21 lines
591 B
JavaScript
|
|
const fs = require('fs-extra');
|
||
|
|
const path = require('path');
|
||
|
|
const os = require('os');
|
||
|
|
|
||
|
|
const configPath = path.join(os.homedir(), '.cad-router-config.json');
|
||
|
|
const defaultConfigPath = path.join(__dirname, '..', 'config', 'defaultConfig.json');
|
||
|
|
|
||
|
|
async function loadConfig() {
|
||
|
|
if (await fs.pathExists(configPath)) {
|
||
|
|
return fs.readJson(configPath);
|
||
|
|
}
|
||
|
|
|
||
|
|
const defaultConfig = await fs.readJson(defaultConfigPath);
|
||
|
|
await fs.writeJson(configPath, defaultConfig, { spaces: 2 });
|
||
|
|
return defaultConfig;
|
||
|
|
}
|
||
|
|
|
||
|
|
loadConfig.getConfigPath = () => configPath;
|
||
|
|
|
||
|
|
module.exports = { loadConfig };
|