mirror of
https://github.com/wukko/cobalt.git
synced 2024-05-17 05:37:16 +01:00
api/util: make JSON file loading platform independent
This commit is contained in:
parent
877933a17f
commit
2a7a0df8a1
|
@ -3,13 +3,11 @@ import * as fs from "fs";
|
|||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const splitDir = path.dirname(fileURLToPath(import.meta.url)).split('/');
|
||||
splitDir.splice(-2);
|
||||
const dir = splitDir.join('/');
|
||||
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../');
|
||||
|
||||
export function loadJSON(filePath) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(`${dir}/${filePath}`, 'utf-8'))
|
||||
return JSON.parse(fs.readFileSync(path.join(dir, filePath), 'utf-8'))
|
||||
} catch(e) {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue