create-discordjs-nextgen 0.2.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.
- package/bin/create-discordjs-nextgen.js +135 -0
- package/package.json +7 -1
|
@@ -52,6 +52,11 @@ async function main() {
|
|
|
52
52
|
options: [
|
|
53
53
|
{ value: "voice", label: "Voice Support", hint: "Muzik ve ses sistemleri" },
|
|
54
54
|
{ value: "jsx", label: "JSX Support", hint: "discordjs-nextgen-jsx ile JSX komutlar" },
|
|
55
|
+
{ value: "cache", label: "Cache (Sade)", hint: "MemoryAdapter kullanır" },
|
|
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" },
|
|
55
60
|
],
|
|
56
61
|
initialValues: forceJsx ? ["jsx"] : [],
|
|
57
62
|
required: false,
|
|
@@ -123,6 +128,27 @@ async function main() {
|
|
|
123
128
|
: "JSX aktif: jsconfig.json yazildi, index dosyasina JSXPlugin eklendi, commands/prefix/hello.jsx olusturuldu."
|
|
124
129
|
);
|
|
125
130
|
}
|
|
131
|
+
if (plugins.includes("cache") || plugins.includes("cache-redis")) {
|
|
132
|
+
const isRedis = plugins.includes("cache-redis");
|
|
133
|
+
pluginNotes.push(
|
|
134
|
+
isRedis
|
|
135
|
+
? "Cache (Redis) aktif: ioredis kuruldu, index dosyasina RedisAdapter eklendi."
|
|
136
|
+
: "Cache (Sade) aktif: index dosyasina MemoryAdapter eklendi."
|
|
137
|
+
);
|
|
138
|
+
if (template === "advanced") {
|
|
139
|
+
pluginNotes.push(`Advanced sablonu secildigi icin commands/prefix/money.${extension} ornek komutu eklendi.`);
|
|
140
|
+
}
|
|
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
|
+
}
|
|
126
152
|
if (pluginNotes.length > 0) {
|
|
127
153
|
p.note(pluginNotes.join("\n"), "Bilgi");
|
|
128
154
|
}
|
|
@@ -181,6 +207,26 @@ async function generateProject(targetDir, config) {
|
|
|
181
207
|
pkg.dependencies["discordjs-nextgen-jsx"] = "latest";
|
|
182
208
|
}
|
|
183
209
|
|
|
210
|
+
if (config.plugins.includes("cache") || config.plugins.includes("cache-redis")) {
|
|
211
|
+
pkg.dependencies["discordjs-nextgen-cache"] = "latest";
|
|
212
|
+
if (config.plugins.includes("cache-redis")) {
|
|
213
|
+
pkg.dependencies["ioredis"] = "latest";
|
|
214
|
+
}
|
|
215
|
+
}
|
|
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
|
+
|
|
184
230
|
await writeLanguageConfig(targetDir, config.language, config.plugins.includes("jsx"));
|
|
185
231
|
await writeFile(targetDir, "package.json", JSON.stringify(pkg, null, 2));
|
|
186
232
|
await writeFile(targetDir, ".gitignore", "node_modules\n.env\ndist\n");
|
|
@@ -193,6 +239,16 @@ async function generateProject(targetDir, config) {
|
|
|
193
239
|
if (config.plugins.includes("jsx")) {
|
|
194
240
|
await injectJSXPlugin(targetDir, config.language);
|
|
195
241
|
}
|
|
242
|
+
|
|
243
|
+
if (config.plugins.includes("cache") || config.plugins.includes("cache-redis")) {
|
|
244
|
+
const useRedis = config.plugins.includes("cache-redis");
|
|
245
|
+
await injectCachePlugin(targetDir, extension, useRedis, config.template, config.language);
|
|
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
|
+
}
|
|
196
252
|
}
|
|
197
253
|
|
|
198
254
|
async function writeLanguageConfig(targetDir, language, useJsx) {
|
|
@@ -284,6 +340,85 @@ async function injectJSXPlugin(targetDir, language) {
|
|
|
284
340
|
await writeFile(targetDir, `commands/prefix/hello.${jsxExtension}`, jsxPrefixCommand);
|
|
285
341
|
}
|
|
286
342
|
|
|
343
|
+
async function injectCachePlugin(targetDir, extension, useRedis, template, language) {
|
|
344
|
+
const entryPath = path.join(targetDir, `index.${extension}`);
|
|
345
|
+
let content = await fsp.readFile(entryPath, "utf8");
|
|
346
|
+
|
|
347
|
+
const adapterName = useRedis ? "RedisAdapter" : "MemoryAdapter";
|
|
348
|
+
const importLine = `import { CachePlugin, ${adapterName} } from "discordjs-nextgen-cache";`;
|
|
349
|
+
|
|
350
|
+
if (!content.includes(importLine)) {
|
|
351
|
+
content = `${importLine}\n${content}`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!content.includes("new CachePlugin")) {
|
|
355
|
+
const pluginCode = useRedis
|
|
356
|
+
? `app.use(new CachePlugin({ adapter: new RedisAdapter() }));`
|
|
357
|
+
: `app.use(new CachePlugin({ adapter: new MemoryAdapter() }));`;
|
|
358
|
+
|
|
359
|
+
content = content.replace(/const app = new App\((\{[\s\S]*?\}|)\);/, (match) => `${match}\n\n${pluginCode}`);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
await fsp.writeFile(entryPath, content, "utf8");
|
|
363
|
+
|
|
364
|
+
if (template === "advanced") {
|
|
365
|
+
const cmdCode = language === "ts"
|
|
366
|
+
? `import type { PrefixCommand } from 'discordjs-nextgen';\n\nconst money: PrefixCommand = {\n name: 'money',\n description: 'Cache ile bakiye sistemi.',\n run: async (ctx) => {\n const userId = ctx.user.id;\n let user = await ctx.cache.user.get(userId) || { coins: 0 };\n user.coins += 100;\n await ctx.cache.user.set(userId, user);\n await ctx.reply(\`100 coin eklendi! Mevcut bakiyen: \${user.coins}\`);\n }\n};\n\nexport default money;\n`
|
|
367
|
+
: `const money = {\n name: 'money',\n description: 'Cache ile bakiye sistemi.',\n run: async (ctx) => {\n const userId = ctx.user.id;\n let user = await ctx.cache.user.get(userId) || { coins: 0 };\n user.coins += 100;\n await ctx.cache.user.set(userId, user);\n await ctx.reply(\`100 coin eklendi! Mevcut bakiyen: \${user.coins}\`);\n }\n};\n\nexport default money;\n`;
|
|
368
|
+
|
|
369
|
+
await writeFile(targetDir, `commands/prefix/money.${extension}`, cmdCode);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
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
|
+
|
|
287
422
|
async function copyTemplateDirectory(sourceDir, targetDir, context) {
|
|
288
423
|
if (!fs.existsSync(sourceDir)) return;
|
|
289
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
|
+
"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",
|