| 13996 | return folder.replace(/\/$/, "") + "/" |
| 13997 | } |
| 13998 | static runCommand(instance, command = "", param = undefined) { |
| 13999 | const run = name => { |
| 14000 | console.log(`Running ${name}:`) |
| 14001 | instance[name](param) |
| 14002 | } |
| 14003 | if (instance[command + "Command"]) return run(command + "Command") |
| 14004 | // Get commands from both the child and parent classes |
| 14005 | const classes = [Object.getPrototypeOf(instance), Object.getPrototypeOf(Object.getPrototypeOf(instance))] |
| 14006 | const allCommands = classes.map(classInstance => Object.getOwnPropertyNames(classInstance).filter(atom => atom.endsWith("Command"))).flat() |
| 14007 | allCommands.sort() |
| 14008 | const commandAsNumber = parseInt(command) - 1 |
| 14009 | if (command.match(/^\d+$/) && allCommands[commandAsNumber]) return run(allCommands[commandAsNumber]) |
| 14010 | console.log(`\n❌ No command provided. Available commands:\n\n` + allCommands.map((name, index) => `${index + 1}. ${name.replace("Command", "")}`).join("\n") + "\n") |
| 14011 | } |
| 14012 | static removeReturnChars(str = "") { |
| 14013 | return str.replace(/\r/g, "") |
| 14014 | } |