create-discordjs-nextgen 0.3.0 → 1.0.0

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.
@@ -54,6 +54,9 @@ async function main() {
54
54
  { value: "jsx", label: "JSX Support", hint: "discordjs-nextgen-jsx ile JSX komutlar" },
55
55
  { value: "cache", label: "Cache (Sade)", hint: "MemoryAdapter kullanır" },
56
56
  { value: "cache-redis", label: "Cache (with Redis)", hint: "RedisAdapter + ioredis kullanır" },
57
+ { value: "db-sqlite", label: "Database (SQLite)", hint: "discordjs-nextgen-db + better-sqlite3" },
58
+ { value: "db-mysql", label: "Database (MySQL)", hint: "discordjs-nextgen-db + mysql2" },
59
+ { value: "db-mongo", label: "Database (MongoDB/Mongoose)", hint: "discordjs-nextgen-db + mongoose" },
57
60
  ],
58
61
  initialValues: forceJsx ? ["jsx"] : [],
59
62
  required: false,
@@ -136,6 +139,16 @@ async function main() {
136
139
  pluginNotes.push(`Advanced sablonu secildigi icin commands/prefix/money.${extension} ornek komutu eklendi.`);
137
140
  }
138
141
  }
142
+ const dbPlugin = plugins.find(p => p.startsWith("db-"));
143
+ if (dbPlugin) {
144
+ let dbName = "SQLite";
145
+ if (dbPlugin === "db-mysql") dbName = "MySQL";
146
+ if (dbPlugin === "db-mongo") dbName = "MongoDB/Mongoose";
147
+ pluginNotes.push(`Database (${dbName}) aktif: discordjs-nextgen-db kuruldu, models/ klasoru olusturuldu.`);
148
+ if (template === "advanced") {
149
+ pluginNotes.push(`Advanced sablonu secildigi icin commands/prefix/dbtest.${extension} ornek komutu eklendi.`);
150
+ }
151
+ }
139
152
  if (pluginNotes.length > 0) {
140
153
  p.note(pluginNotes.join("\n"), "Bilgi");
141
154
  }
@@ -201,6 +214,19 @@ async function generateProject(targetDir, config) {
201
214
  }
202
215
  }
203
216
 
217
+ if (config.plugins.some(p => p.startsWith("db-"))) {
218
+ pkg.dependencies["discordjs-nextgen-db"] = "latest";
219
+ if (config.plugins.includes("db-sqlite")) {
220
+ pkg.dependencies["better-sqlite3"] = "latest";
221
+ }
222
+ if (config.plugins.includes("db-mysql")) {
223
+ pkg.dependencies["mysql2"] = "latest";
224
+ }
225
+ if (config.plugins.includes("db-mongo")) {
226
+ pkg.dependencies["mongoose"] = "latest";
227
+ }
228
+ }
229
+
204
230
  await writeLanguageConfig(targetDir, config.language, config.plugins.includes("jsx"));
205
231
  await writeFile(targetDir, "package.json", JSON.stringify(pkg, null, 2));
206
232
  await writeFile(targetDir, ".gitignore", "node_modules\n.env\ndist\n");
@@ -218,6 +244,11 @@ async function generateProject(targetDir, config) {
218
244
  const useRedis = config.plugins.includes("cache-redis");
219
245
  await injectCachePlugin(targetDir, extension, useRedis, config.template, config.language);
220
246
  }
247
+
248
+ const dbPlugin = config.plugins.find(p => p.startsWith("db-"));
249
+ if (dbPlugin) {
250
+ await injectDatabasePlugin(targetDir, extension, dbPlugin, config.template, config.language);
251
+ }
221
252
  }
222
253
 
223
254
  async function writeLanguageConfig(targetDir, language, useJsx) {
@@ -339,6 +370,55 @@ async function injectCachePlugin(targetDir, extension, useRedis, template, langu
339
370
  }
340
371
  }
341
372
 
373
+ async function injectDatabasePlugin(targetDir, extension, pluginName, template, language) {
374
+ const entryPath = path.join(targetDir, `index.${extension}`);
375
+ let content = await fsp.readFile(entryPath, "utf8");
376
+
377
+ let adapterName, adapterImport, pluginConfig;
378
+
379
+ if (pluginName === "db-sqlite") {
380
+ adapterName = "SQLiteAdapter";
381
+ adapterImport = `import { DatabasePlugin, SQLiteAdapter } from "discordjs-nextgen-db";`;
382
+ pluginConfig = `app.use(new DatabasePlugin({ folder: "./models", adapter: new SQLiteAdapter({ path: "./database.sqlite" }) }));`;
383
+ } else if (pluginName === "db-mysql") {
384
+ adapterName = "MySQLAdapter";
385
+ adapterImport = `import { DatabasePlugin, MySQLAdapter } from "discordjs-nextgen-db";`;
386
+ pluginConfig = `app.use(new DatabasePlugin({ folder: "./models", adapter: new MySQLAdapter({ host: "localhost", user: "root", database: "nextgen" }) }));`;
387
+ } else if (pluginName === "db-mongo") {
388
+ adapterName = "MongooseAdapter";
389
+ adapterImport = `import { DatabasePlugin, MongooseAdapter } from "discordjs-nextgen-db";`;
390
+ pluginConfig = `app.use(new DatabasePlugin({ folder: "./models", adapter: new MongooseAdapter({ uri: "mongodb://localhost:27017/nextgen" }) }));`;
391
+ }
392
+
393
+ if (!content.includes(adapterImport)) {
394
+ content = `${adapterImport}\n${content}`;
395
+ }
396
+
397
+ if (!content.includes("new DatabasePlugin")) {
398
+ content = content.replace(/const app = new App\((\{[\s\S]*?\}|)\);/, (match) => `${match}\n\n${pluginConfig}`);
399
+ }
400
+
401
+ await fsp.writeFile(entryPath, content, "utf8");
402
+
403
+ // Create models directory
404
+ const modelsDir = path.join(targetDir, "models");
405
+ if (!fs.existsSync(modelsDir)) {
406
+ await fsp.mkdir(modelsDir);
407
+ }
408
+
409
+ // Create sample user model
410
+ const userModelCode = `export default (db) => {\n db.define("user");\n};\n`;
411
+ await fsp.writeFile(path.join(modelsDir, `user.${extension}`), userModelCode, "utf8");
412
+
413
+ if (template === "advanced") {
414
+ const dbCmdCode = language === "ts"
415
+ ? `import type { PrefixCommand } from 'discordjs-nextgen';\n\nconst dbtest: PrefixCommand = {\n name: 'dbtest',\n description: 'Database CRUD testi.',\n run: async (ctx) => {\n const userId = ctx.user.id;\n let data = await ctx.db.user.get(userId) || { count: 0 };\n data.count += 1;\n await ctx.db.user.set(userId, data);\n await ctx.reply(\`DB Test: \${data.count} kez çalıştırıldı.\`);\n }\n};\n\nexport default dbtest;\n`
416
+ : `const dbtest = {\n name: 'dbtest',\n description: 'Database CRUD testi.',\n run: async (ctx) => {\n const userId = ctx.user.id;\n let data = await ctx.db.user.get(userId) || { count: 0 };\n data.count += 1;\n await ctx.db.user.set(userId, data);\n await ctx.reply(\`DB Test: \${data.count} kez çalıştırıldı.\`);\n }\n};\n\nexport default dbtest;\n`;
417
+
418
+ await writeFile(targetDir, `commands/prefix/dbtest.${extension}`, dbCmdCode);
419
+ }
420
+ }
421
+
342
422
  async function copyTemplateDirectory(sourceDir, targetDir, context) {
343
423
  if (!fs.existsSync(sourceDir)) return;
344
424
  const entries = await fsp.readdir(sourceDir, { withFileTypes: true });
package/package.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "create-discordjs-nextgen",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "Scaffold a Discord bot powered by discordjs-nextgen",
5
5
  "bin": {
6
6
  "create-discordjs-nextgen": "./bin/create-discordjs-nextgen.js"
7
7
  },
8
8
  "type": "module",
9
+ "homepage": "https://discordjs-nextgen.vercel.app/docs/cli",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/burakbehlull/discordjs-nextgen-cli",
13
+ "directory": "nextgen-cli"
14
+ },
9
15
  "files": [
10
16
  "bin",
11
17
  "README.md",