mirror of
https://github.com/GenderDysphoria/GenderDysphoria.fyi.git
synced 2025-01-31 07:16:17 +00:00
27 lines
701 B
JavaScript
27 lines
701 B
JavaScript
|
|
||
|
const path = require('path');
|
||
|
const ROOT = path.resolve(__dirname, '../..');
|
||
|
const fs = require('fs-extra');
|
||
|
|
||
|
exports.readFile = function readFile (fpath) {
|
||
|
fpath = exports.resolve(fpath);
|
||
|
return fs.readFile(fpath).catch((err) => {
|
||
|
throw new Error(err.trace);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
exports.resolve = function resolve (...args) {
|
||
|
args = args.filter(Boolean);
|
||
|
let fpath = args.shift();
|
||
|
if (!fpath) return ROOT;
|
||
|
if (fpath[0] === '/') throw new Error('Did you mean to resolve this? ' + fpath);
|
||
|
if (fpath[0] === '/') fpath = fpath.slice(1);
|
||
|
return path.resolve(ROOT, fpath, ...args);
|
||
|
};
|
||
|
|
||
|
exports.relative = function relative (fpath) {
|
||
|
return path.relative(ROOT, fpath);
|
||
|
};
|
||
|
|
||
|
exports.ROOT = ROOT;
|