@ad1m/djb
Version:
A streamlined library for creating Discord bots with Discord.js, featuring a simple command and event handler structure.
35 lines (34 loc) • 932 B
JavaScript
// src/utils/url.ts
import { fileURLToPath } from "url";
import { dirname, resolve } from "path";
import { existsSync } from "fs";
var getCurrentModuleType = () => {
if (typeof __dirname !== "undefined") {
return "cjs";
} else if (typeof import.meta?.url !== "undefined") {
return "esm";
} else {
throw new Error("Unable to determine module type.");
}
};
var getCurrenDir = () => {
const mType = getCurrentModuleType();
switch (mType) {
case "cjs":
return __dirname;
case "esm":
return dirname(fileURLToPath(import.meta.url));
}
};
var getAppPath = () => {
const distAppPath = resolve(process.cwd(), "dist", "app");
const appPath = resolve(process.cwd(), "app");
if (existsSync(distAppPath)) return distAppPath;
else if (existsSync(appPath)) return appPath;
else throw new Error("No /app directory found.");
};
export {
getAppPath,
getCurrenDir,
getCurrentModuleType
};