mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
api/load-from-fs: always load files from root of api folder
This commit is contained in:
parent
8e7b63ade6
commit
0e0ad7cb0e
1 changed files with 9 additions and 1 deletions
|
@ -1,12 +1,20 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import { join, dirname } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const root = join(
|
||||||
|
dirname(fileURLToPath(import.meta.url)),
|
||||||
|
'../../'
|
||||||
|
);
|
||||||
|
|
||||||
export function loadJSON(path) {
|
export function loadJSON(path) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(fs.readFileSync(path, 'utf-8'))
|
return JSON.parse(fs.readFileSync(join(root, path), 'utf-8'))
|
||||||
} catch {
|
} catch {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadFile(path) {
|
export function loadFile(path) {
|
||||||
try {
|
try {
|
||||||
return fs.readFileSync(path, 'utf-8')
|
return fs.readFileSync(path, 'utf-8')
|
||||||
|
|
Loading…
Reference in a new issue