diff --git a/bin/commands/RegisterCommands.js b/bin/commands/RegisterCommands.js index 9b68664..347ec14 100644 --- a/bin/commands/RegisterCommands.js +++ b/bin/commands/RegisterCommands.js @@ -1,10 +1,12 @@ const { RegisterCommand, RegisterJSONCommand } = require("../CommandsHandler"); const InitCommand = require("./InitCommand"); const RunCommand = require("./RunCommand"); +const TemplateCommand = require("./TemplateCommand"); const VersionCommand = require("./VersionCommand"); module.exports = (program) => { RegisterJSONCommand(program, VersionCommand()); RegisterJSONCommand(program, InitCommand()); RegisterJSONCommand(program, RunCommand()); + RegisterJSONCommand(program, TemplateCommand()) } \ No newline at end of file diff --git a/bin/commands/TemplateCommand.js b/bin/commands/TemplateCommand.js new file mode 100644 index 0000000..efbb663 --- /dev/null +++ b/bin/commands/TemplateCommand.js @@ -0,0 +1,39 @@ +const CommandBuilder = require("../CommandBuilder"); +const Templates = require("@redactcord/templates"); +const simpleGit = require("simple-git"); +const git = simpleGit.default(process.cwd()) + +module.exports = () => { + return CommandBuilder.createBuilder("template") + .setDescription("Displays or Creates templates") + .addArgument("[template]") + .setCallback((template) => { + const templates = Templates.TEMPLATES; + if (!template) { + + if (!templates.length) + return console.log("No Templates are found at this current time. templates package may have not been updated in the main package"); + + let tab = ` `; + let string = ``; + + for (const template of templates) { + string += `${tab}|-${template}\n`; + } + + console.log(string.trim()); + } else { + + const index = templates.indexOf(template); + if (index == -1) + return console.log("Not Present in the templates list."); + const templateValue = templates[index]; + const url = `${Templates.GithubPrefix}${templateValue}`; + + git.clone(url, process.cwd()).then((value) => { + console.log("Cloned Template " + templateValue + " to " + process.cwd()); + }); + } + + }); +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d40bef7..bb9c932 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,11 @@ "version": "1.0.1", "license": "MIT", "dependencies": { + "@redactcord/templates": "^0.0.1", "better-sqlite3": "^9.0.0", "cli-color": "^2.0.3", "commander": "^11.1.0", - "discord.js": "^14.13.0", + "discord.js": "^14.12.1", "dotenv": "^16.3.1", "eval": "^0.1.8", "figlet": "^1.6.0", @@ -23,8 +24,9 @@ "quick.db": "^9.1.7", "quickmongo": "^5.2.0", "quickpostgres": "^3.0.2", + "simple-git": "^3.20.0", "typescript": "^5.2.2", - "watch": "^1.0.2", + "watch": "^0.13.0", "yaml": "^2.3.3" }, "bin": { @@ -769,6 +771,19 @@ "node": ">=16.11.0" } }, + "node_modules/@kwsites/file-exists": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/file-exists/-/file-exists-1.1.1.tgz", + "integrity": "sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==", + "dependencies": { + "debug": "^4.1.1" + } + }, + "node_modules/@kwsites/promise-deferred": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz", + "integrity": "sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==" + }, "node_modules/@ljharb/through": { "version": "2.3.11", "resolved": "https://registry.npmjs.org/@ljharb/through/-/through-2.3.11.tgz", @@ -789,6 +804,11 @@ "sparse-bitfield": "^3.0.3" } }, + "node_modules/@redactcord/templates": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@redactcord/templates/-/templates-0.0.1.tgz", + "integrity": "sha512-t9zDz7hxWCmwoq3CNRZJXfHg8/fLl8Fjgo0NvvwDeYtxtHHbB8biWo0OV/5mgVqFxgOUNWhpeK3qHFJj2ZbgtQ==" + }, "node_modules/@sapphire/async-queue": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.0.tgz", @@ -1745,27 +1765,27 @@ "integrity": "sha512-X4CDiMnDbA3s3RaUXWXmgAIbY1uxab3fqe3qwzg5XutR3wjqi7M3IkgQbsIBzpqBN2YWr/Qdv7JrFRqSgb4TFg==" }, "node_modules/discord.js": { - "version": "14.13.0", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.13.0.tgz", - "integrity": "sha512-Kufdvg7fpyTEwANGy9x7i4od4yu5c6gVddGi5CKm4Y5a6sF0VBODObI3o0Bh7TGCj0LfNT8Qp8z04wnLFzgnbA==", - "dependencies": { - "@discordjs/builders": "^1.6.5", - "@discordjs/collection": "^1.5.3", - "@discordjs/formatters": "^0.3.2", - "@discordjs/rest": "^2.0.1", - "@discordjs/util": "^1.0.1", - "@discordjs/ws": "^1.0.1", + "version": "14.12.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.12.1.tgz", + "integrity": "sha512-gGjhTkauIPgFXxpBl0UZgyehrKhDe90cIS8Hn1xFBYQ63EuUAkKoUqRNmc/pcla6DD16s4cUz5tAbdSpXivnxw==", + "dependencies": { + "@discordjs/builders": "^1.6.4", + "@discordjs/collection": "^1.5.2", + "@discordjs/formatters": "^0.3.1", + "@discordjs/rest": "^2.0.0", + "@discordjs/util": "^1.0.0", + "@discordjs/ws": "^1.0.0", "@sapphire/snowflake": "^3.5.1", "@types/ws": "^8.5.5", - "discord-api-types": "0.37.50", + "discord-api-types": "^0.37.50", "fast-deep-equal": "^3.1.3", "lodash.snakecase": "^4.1.1", "tslib": "^2.6.1", - "undici": "5.22.1", + "undici": "^5.22.1", "ws": "^8.13.0" }, "engines": { - "node": ">=16.11.0" + "node": ">=16.9.0" } }, "node_modules/dotenv": { @@ -1868,14 +1888,6 @@ "es5-ext": "~0.10.14" } }, - "node_modules/exec-sh": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.2.2.tgz", - "integrity": "sha512-FIUCJz1RbuS0FKTdaAafAByGS0CPvU3R0MeHxgtl+djzCc//F8HakL8GzmVNZanasTbTAY/3DRFA0KpVqj/eAw==", - "dependencies": { - "merge": "^1.2.0" - } - }, "node_modules/expand-template": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", @@ -2244,11 +2256,6 @@ "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", "optional": true }, - "node_modules/merge": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/merge/-/merge-1.2.1.tgz", - "integrity": "sha512-VjFo4P5Whtj4vsLzsYBu5ayHhoHJ0UqNm7ibvShmbmoz7tGi0vXaoJbGdB+GmDMLUdg8DpQXEIeVDAe8MaABvQ==" - }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -2826,6 +2833,20 @@ "simple-concat": "^1.0.0" } }, + "node_modules/simple-git": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/simple-git/-/simple-git-3.20.0.tgz", + "integrity": "sha512-ozK8tl2hvLts8ijTs18iFruE+RoqmC/mqZhjs/+V7gS5W68JpJ3+FCTmLVqmR59MaUQ52MfGQuWsIqfsTbbJ0Q==", + "dependencies": { + "@kwsites/file-exists": "^1.1.1", + "@kwsites/promise-deferred": "^1.1.1", + "debug": "^4.3.4" + }, + "funding": { + "type": "github", + "url": "https://github.com/steveukx/git-js?sponsor=1" + } + }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", @@ -3072,18 +3093,17 @@ } }, "node_modules/watch": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/watch/-/watch-1.0.2.tgz", - "integrity": "sha512-1u+Z5n9Jc1E2c7qDO8SinPoZuHj7FgbgU1olSFoyaklduDvvtX7GMMtlE6OC9FTXq4KvNAOfj6Zu4vI1e9bAKA==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/watch/-/watch-0.13.0.tgz", + "integrity": "sha512-yTgNlr/8OjaGYq2FIv/PjU0zlv/pdAOmVSEeHNVcApFTT6ocWnMLhXlB6n/Rz9VVWXZmZkvkDnJ+iAIi/JjUJA==", + "engines": [ + "node >=0.1.95" + ], "dependencies": { - "exec-sh": "^0.2.0", - "minimist": "^1.2.0" + "minimist": "^1.1.0" }, "bin": { "watch": "cli.js" - }, - "engines": { - "node": ">=0.1.95" } }, "node_modules/wcwidth": { diff --git a/package.json b/package.json index f46cfca..90bb483 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,11 @@ "@types/node": "^20.8.6" }, "dependencies": { + "@redactcord/templates": "^0.0.1", "better-sqlite3": "^9.0.0", "cli-color": "^2.0.3", "commander": "^11.1.0", - "discord.js": "^14.13.0", + "discord.js": "^14.12.1", "dotenv": "^16.3.1", "eval": "^0.1.8", "figlet": "^1.6.0", @@ -42,8 +43,9 @@ "quick.db": "^9.1.7", "quickmongo": "^5.2.0", "quickpostgres": "^3.0.2", + "simple-git": "^3.20.0", "typescript": "^5.2.2", - "watch": "^1.0.2", + "watch": "^0.13.0", "yaml": "^2.3.3" } } diff --git a/packages/templates/index.d.ts b/packages/templates/index.d.ts new file mode 100644 index 0000000..ed18e09 --- /dev/null +++ b/packages/templates/index.d.ts @@ -0,0 +1,2 @@ +export const TEMPLATES: string[]; +export const GithubPrefix: string; \ No newline at end of file diff --git a/packages/templates/index.js b/packages/templates/index.js new file mode 100644 index 0000000..2f04bb2 --- /dev/null +++ b/packages/templates/index.js @@ -0,0 +1,4 @@ +module.exports = { + TEMPLATES: [], + GithubPrefix: "https://github.com/" +} \ No newline at end of file diff --git a/packages/templates/package.json b/packages/templates/package.json new file mode 100644 index 0000000..d62b1a9 --- /dev/null +++ b/packages/templates/package.json @@ -0,0 +1,24 @@ +{ + "name": "@redactcord/templates", + "version": "0.0.1", + "description": "Provides all template urls for the main package", + "main": "index.js", + "typings": "index.d.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Max Jackson", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/redactdev/redactcord.git" + }, + "keywords": [ + "urls", + "templates" + ], + "bugs": { + "url": "https://github.com/redactdev/redactcord/issues" + }, + "homepage": "https://github.com/redactdev/redactcord#readme" +} diff --git a/src/utils/Loader.ts b/src/utils/Loader.ts index 49f41f5..29cdfbd 100644 --- a/src/utils/Loader.ts +++ b/src/utils/Loader.ts @@ -4,7 +4,7 @@ import { RedactError } from "../error/RedactError"; export class Loader { - public loadFrom(folder: string, deep: boolean = false) { + public loadFrom(folder: string, deep: boolean = false, iscwd: boolean = true) { const arr: E[] = []; const hirearchy = readdirSync(folder); @@ -17,9 +17,13 @@ export class Loader { } else { - if (!item.endsWith(".js") || !item.endsWith(".ts")) - throw new RedactError("Invalid Extension", "An invalid extension was found in a file name: \"" + item + "\". Make sure it's .ts or .js"); - const r = require(path.join(folder, item)); + let p = ``; + if (iscwd) { + p += path.join(process.cwd(), folder, item) + } else { + p += path.join(folder, item) + } + const r = require(p); let clazz: E; try { clazz = r(); diff --git a/typings/index.d.ts b/typings/index.d.ts index 27a0694..2c8221b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -45,7 +45,7 @@ export class CommandsManager extends Loader { } export class Loader { - public loadFrom(folder: string, deep: boolean = false): E[]; + public loadFrom(folder: string, deep: boolean = false, iscwd: boolean = true): E[]; } export class EventManager extends Loader { @@ -70,6 +70,7 @@ type MessageArguments = string[]; export abstract class RedactCommand { + constructor(commandData: ComandData); public setRedactClient(redactClient: RedactClient): void; public getRedactClient(): RedactClient; public getCommandData(): CommandData;