UNPKG

ariaa

Version:
43 lines 1.47 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); import { CONFIG_FILE } from "#constants"; import { logger } from "#lib/structures"; import { magenta, underline } from "colorette"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import { homedir } from "node:os"; import path from "node:path"; function getConfig(json = false) { try { const config = readFileSync(path.join(homedir(), CONFIG_FILE), { encoding: "utf-8" }); return json ? JSON.parse(config) : config; } catch { throw new Error(`Config Not found! Please run ${underline(magenta(`ariaa setup`))}`); } } __name(getConfig, "getConfig"); function musicPath(title, format, album) { const { downloadPath } = getConfig(true); if (!existsSync(downloadPath)) throw new Error("Download path does not exist!"); const music = path.join(downloadPath, "Music"); if (!existsSync(music)) { logger.debug("Music folder does not exist, making one..."); mkdirSync(music); } if (album) { const albumPath = path.join(music, album); if (!existsSync(albumPath)) { logger.debug("Music folder does not exist, making one..."); mkdirSync(albumPath); } return path.join(albumPath, `${title}.${format}`); } return path.join(music, `${title}.${format}`); } __name(musicPath, "musicPath"); export { getConfig, musicPath }; //# sourceMappingURL=config.js.map