mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-21 12:48:28 +00: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 path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
const splitDir = path.dirname(fileURLToPath(import.meta.url)).split('/');
|
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../');
|
||||||
splitDir.splice(-2);
|
|
||||||
const dir = splitDir.join('/');
|
|
||||||
|
|
||||||
export function loadJSON(filePath) {
|
export function loadJSON(filePath) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(`${dir}/${filePath}`, 'utf-8'))
|
return JSON.parse(fs.readFileSync(path.join(dir, filePath), 'utf-8'))
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user