mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-28 23:24:26 -05:00
21 lines
604 B
JavaScript
21 lines
604 B
JavaScript
|
import fs from 'fs';
|
||
|
import { fileURLToPath } from 'url';
|
||
|
import path from 'path';
|
||
|
|
||
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||
|
|
||
|
export default function (configPath = './config.json') {
|
||
|
const fullConfigPath = path.resolve(__dirname, '../', configPath);
|
||
|
if (!fs.existsSync(fullConfigPath)) throw new Error('Config file does not exist.');
|
||
|
const unparsedConfig = fs.readFileSync(fullConfigPath, 'utf8');
|
||
|
|
||
|
let parsedConfig;
|
||
|
try {
|
||
|
parsedConfig = JSON.parse(unparsedConfig);
|
||
|
} catch (err) {
|
||
|
throw new Error('Unable to parse config file.');
|
||
|
}
|
||
|
|
||
|
return parsedConfig;
|
||
|
}
|