meocord
Version:
MeoCord is a lightweight and modular framework for building scalable Discord bots using TypeScript and Discord.js. It simplifies bot development with an extensible architecture, TypeScript-first approach, and powerful CLI tools.
49 lines • 5.51 kB
JavaScript
function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}/**
* MeoCord Framework
* Copyright (C) 2025 Ukasyah Rahmatullah Zada
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/import fs from"fs";import path from"path";import{exec}from"child_process";import{Logger}from"../common/index.js";import{camelCase,kebabCase,startCase}from"lodash-es";import{fileURLToPath}from"url";var __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),logger=new Logger("MeoCord");/**
* Converts a given name to a properly formatted class name.
* @param originalName - The original name to be converted to a class name.
* @returns The formatted class name.
* @throws Will exit the process if the generated class name is invalid.
*/export function toClassName(a){var b=startCase(camelCase(a)).replace(/\s/g,"");return /^[A-Z][A-Za-z0-9]*$/.test(b)||(logger.error("Invalid class name \"".concat(a,"\". Must start with a letter and contain alphanumeric characters.")),process.exit(1)),b}/**
* Validates and formats a given name, splitting it into parts,
* converting it to kebab-case, and generating a class name.
* @param originalName - The name to validate and format. It can include slashes for nested paths.
* @returns An object containing the name parts, kebab-case name, and class name.
* @throws Will exit the process if the name is undefined, invalid,
* or the generated class name is invalid.
*/export function validateAndFormatName(a){a||(logger.error("Guard name is required."),process.exit(1));var b=a.split("/"),c=b.pop();c||(logger.error("Invalid guard name."),process.exit(1));var d=kebabCase(c),e=toClassName(c);return{parts:b,kebabCaseName:d,className:e}}/**
* Ensures that a given directory exists. Creates the directory and any necessary parent directories if they do not exist.
* @param directory - The absolute path of the directory to create.
*/export function createDirectoryIfNotExists(a){fs.existsSync(a)||fs.mkdirSync(a,{recursive:!0})}/**
* Writes the provided content to a file and runs ESLint on the file for formatting.
* @param filePath - The absolute path of the file to create or overwrite.
* @param content - The content to write to the file.
* @throws Logs an error if the file creation or ESLint command fails.
*/export function generateFile(a,b){try{fs.writeFileSync(a,b),logger.log("Guard file created at: ".concat(path.relative(process.cwd(),a))),exec("npx eslint --fix ".concat(a))}catch(b){logger.error("Failed to create guard file at ".concat(a),b)}}/**
* Builds and returns a template string for a given class name using a specific template file.
* @param className - The name of the class to insert into the template.
* @param templateFileName - The name of the template file to use.
* @returns The populated template string.
* @throws Will throw an error if the template file cannot be read.
*/export function buildTemplate(a,b){for(var c=path.resolve(__dirname,"..","bin","builder-template",b),d=fs.readFileSync(c,"utf-8"),e={className:a},f=0,g=Object.entries(e);f<g.length;f++){var h=_slicedToArray(g[f],2),i=h[0],j=h[1];d=d.replaceAll("{{".concat(i,"}}"),j)}return d}/**
* Populates a template file with the provided variables by replacing placeholders in the template.
* @param filePath - The path to the template file.
* @param variables - An object containing variable names and their replacement values.
* @returns The populated template string.
* @throws Will throw an error if the template file cannot be read.
*/export function populateTemplate(a,b){for(var c=fs.readFileSync(a,"utf-8"),d=0,e=Object.entries(b);d<e.length;d++){var f=_slicedToArray(e[d],2),g=f[0],h=f[1];c=c.replaceAll("{{".concat(g,"}}"),h)}return c}