discordjs-gen 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Gerador de Template DJS
2
+
3
+ - Abra o terminal, execute: "npm i discordjs-gen" e logo em seguida: "discordjs-gen" no terminal;
4
+ - Escolha a versão, e aguarde para baixar todos os pacotes.
5
+ - Não esqueça de mudar o token no .env! <3
package/bin/index.js ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+
3
+ import inquirer from "inquirer";
4
+ import chalk from "chalk";
5
+ import { TemplateGenerator, BaseTypes } from "../dist/index.js";
6
+
7
+ console.clear();
8
+
9
+ console.log(chalk.cyan.bold(`🚀 DiscordJS Generator ` + chalk.white.bold('|' + chalk.green.bold(` Discordjs-gen`))));
10
+
11
+ console.log(`
12
+ Escolha o template:
13
+
14
+ [1] Template - SlashCommands | V14
15
+ [2] Template - PrefixCommands | V14
16
+ `);
17
+
18
+ const { option } = await inquirer.prompt([
19
+ {
20
+ type: "input",
21
+ name: "option",
22
+ message: "Digite o número da opção:",
23
+ validate: (value) => {
24
+ if (value !== "1" && value !== "2") {
25
+ return "Escolha apenas 1 ou 2";
26
+ }
27
+ return true;
28
+ }
29
+ }
30
+ ]);
31
+
32
+ const type =
33
+ option === "1"
34
+ ? BaseTypes.Slash
35
+ : BaseTypes.Prefix;
36
+
37
+ const generator = new TemplateGenerator();
38
+ generator.createBase({ type });
39
+
40
+ console.log(chalk.green("\n✔ Projeto gerado com sucesso!\n") + chalk.cyan.bold("Obrigado por apoiar o discordjs-gen! =)\n"));
@@ -0,0 +1,15 @@
1
+ declare enum BaseTypes {
2
+ Slash = 1,
3
+ Prefix = 2
4
+ }
5
+ interface BaseOptions {
6
+ type: BaseTypes;
7
+ templateName?: "slash" | "prefix";
8
+ }
9
+ declare class TemplateGenerator {
10
+ private readonly destinationDir;
11
+ private copyFolder;
12
+ private installDependencies;
13
+ createBase(options: BaseOptions): void;
14
+ }
15
+ export { TemplateGenerator, BaseTypes };
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { exec } from "node:child_process";
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+ var BaseTypes;
8
+ (function (BaseTypes) {
9
+ BaseTypes[BaseTypes["Slash"] = 1] = "Slash";
10
+ BaseTypes[BaseTypes["Prefix"] = 2] = "Prefix";
11
+ })(BaseTypes || (BaseTypes = {}));
12
+ const COLORS = {
13
+ SUCCESS: "\x1b[32m",
14
+ ERROR: "\x1b[31m",
15
+ INFO: "\x1b[36m"
16
+ };
17
+ const TEMPLATES = {
18
+ slash: path.join(__dirname, "templates", "slash"),
19
+ prefix: path.join(__dirname, "templates", "prefix")
20
+ };
21
+ class TemplateGenerator {
22
+ constructor() {
23
+ this.destinationDir = process.cwd();
24
+ }
25
+ copyFolder(source, destination) {
26
+ if (!fs.existsSync(destination)) {
27
+ fs.mkdirSync(destination, { recursive: true });
28
+ }
29
+ for (const file of fs.readdirSync(source)) {
30
+ const src = path.join(source, file);
31
+ const dest = path.join(destination, file);
32
+ if (fs.statSync(src).isDirectory()) {
33
+ this.copyFolder(src, dest);
34
+ }
35
+ else {
36
+ fs.copyFileSync(src, dest);
37
+ }
38
+ }
39
+ }
40
+ installDependencies() {
41
+ const pkgPath = path.join(this.destinationDir, "package.json");
42
+ if (!fs.existsSync(pkgPath)) {
43
+ console.log(`${COLORS.INFO}ℹ Nenhum package.json encontrado. Pulando npm install.`);
44
+ return;
45
+ }
46
+ console.log(`\n${COLORS.INFO}📦 Instalando dependências...\n`);
47
+ exec("npm install", { cwd: this.destinationDir }, (error) => {
48
+ if (error) {
49
+ console.log(`\n${COLORS.ERROR}⚠ Falha ao instalar dependências.\nExecute manualmente: npm install\n`);
50
+ return;
51
+ }
52
+ console.log(`\n${COLORS.SUCCESS}✔ Dependências instaladas com sucesso!\n`);
53
+ });
54
+ }
55
+ createBase(options) {
56
+ var _a;
57
+ const template = (_a = options.templateName) !== null && _a !== void 0 ? _a : (options.type === BaseTypes.Prefix ? "prefix" : "slash");
58
+ const templatePath = TEMPLATES[template];
59
+ if (!templatePath || !fs.existsSync(templatePath)) {
60
+ console.error(`${COLORS.ERROR}✖ Template '${template}' não encontrado`);
61
+ process.exit(1);
62
+ }
63
+ this.copyFolder(templatePath, this.destinationDir);
64
+ console.log(`${COLORS.SUCCESS}✔ Template '${template}' gerado com sucesso`);
65
+ this.installDependencies();
66
+ }
67
+ }
68
+ export { TemplateGenerator, BaseTypes };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "discordjs-gen",
3
+ "version": "1.0.1",
4
+ "description": "Gerador de templates para bots Discord.js",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "tsc"
10
+ },
11
+ "bin": {
12
+ "discordjs-gen": "bin/index.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "bin"
17
+ ],
18
+ "keywords": [
19
+ "discord",
20
+ "discordjs",
21
+ "generator",
22
+ "template"
23
+ ],
24
+ "author": "JoaoNotch",
25
+ "license": "ISC",
26
+ "dependencies": {
27
+ "chalk": "^5.6.2",
28
+ "discord.js": "^14.6.0",
29
+ "fs-extra": "^11.1.1",
30
+ "inquirer": "^13.1.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/fs-extra": "^11.0.1",
34
+ "typescript": "^5.0.4"
35
+ }
36
+ }