UNPKG

dressed

Version:

A sleek, serverless-ready Discord bot framework.

48 lines 1.82 kB
import { sep } from "node:path"; import { patternToRegex, scorePattern } from "@dressed/matcher"; import { warnSymbol } from "../../../utils/log.js"; import { createHandlerParser } from "./index.js"; const validComponentCategories = ["buttons", "modals", "selects"]; export const parseComponents = createHandlerParser({ colNames: ["Component", "Category"], uniqueKeys: ["category", "regex"], itemMessages({ name, path }) { const category = getCategory(path); return { confict: `"${name}" conflicts with another ${category === null || category === void 0 ? void 0 : category.slice(0, -1)}, skipping`, cols: [category !== null && category !== void 0 ? category : ""], }; }, createData({ name, path, exports: { pattern = name } = {} }) { const category = getCategory(path); if (!category) { throw `${warnSymbol} Category for "${name}" could not be determined, skipping`; } return { category, ...(pattern instanceof RegExp ? { regex: pattern.source, score: scorePattern(pattern.source), } : { regex: patternToRegex(pattern).source, score: scorePattern(pattern), }), }; }, postMortem: (c) => c.sort((a, b) => b.data.score - a.data.score), }); function getCategory(path) { const parts = path.split(sep); const compIndex = parts.lastIndexOf("components"); if (compIndex === -1) return null; for (let i = parts.length - 2; i > compIndex; i--) { if (validComponentCategories.includes(parts[i])) { return parts[i]; } } return null; } //# sourceMappingURL=components.js.map