create-discordjs-nextgen 0.2.0 → 0.3.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.
|
@@ -52,6 +52,8 @@ 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" },
|
|
55
57
|
],
|
|
56
58
|
initialValues: forceJsx ? ["jsx"] : [],
|
|
57
59
|
required: false,
|
|
@@ -123,6 +125,17 @@ async function main() {
|
|
|
123
125
|
: "JSX aktif: jsconfig.json yazildi, index dosyasina JSXPlugin eklendi, commands/prefix/hello.jsx olusturuldu."
|
|
124
126
|
);
|
|
125
127
|
}
|
|
128
|
+
if (plugins.includes("cache") || plugins.includes("cache-redis")) {
|
|
129
|
+
const isRedis = plugins.includes("cache-redis");
|
|
130
|
+
pluginNotes.push(
|
|
131
|
+
isRedis
|
|
132
|
+
? "Cache (Redis) aktif: ioredis kuruldu, index dosyasina RedisAdapter eklendi."
|
|
133
|
+
: "Cache (Sade) aktif: index dosyasina MemoryAdapter eklendi."
|
|
134
|
+
);
|
|
135
|
+
if (template === "advanced") {
|
|
136
|
+
pluginNotes.push(`Advanced sablonu secildigi icin commands/prefix/money.${extension} ornek komutu eklendi.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
126
139
|
if (pluginNotes.length > 0) {
|
|
127
140
|
p.note(pluginNotes.join("\n"), "Bilgi");
|
|
128
141
|
}
|
|
@@ -181,6 +194,13 @@ async function generateProject(targetDir, config) {
|
|
|
181
194
|
pkg.dependencies["discordjs-nextgen-jsx"] = "latest";
|
|
182
195
|
}
|
|
183
196
|
|
|
197
|
+
if (config.plugins.includes("cache") || config.plugins.includes("cache-redis")) {
|
|
198
|
+
pkg.dependencies["discordjs-nextgen-cache"] = "latest";
|
|
199
|
+
if (config.plugins.includes("cache-redis")) {
|
|
200
|
+
pkg.dependencies["ioredis"] = "latest";
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
184
204
|
await writeLanguageConfig(targetDir, config.language, config.plugins.includes("jsx"));
|
|
185
205
|
await writeFile(targetDir, "package.json", JSON.stringify(pkg, null, 2));
|
|
186
206
|
await writeFile(targetDir, ".gitignore", "node_modules\n.env\ndist\n");
|
|
@@ -193,6 +213,11 @@ async function generateProject(targetDir, config) {
|
|
|
193
213
|
if (config.plugins.includes("jsx")) {
|
|
194
214
|
await injectJSXPlugin(targetDir, config.language);
|
|
195
215
|
}
|
|
216
|
+
|
|
217
|
+
if (config.plugins.includes("cache") || config.plugins.includes("cache-redis")) {
|
|
218
|
+
const useRedis = config.plugins.includes("cache-redis");
|
|
219
|
+
await injectCachePlugin(targetDir, extension, useRedis, config.template, config.language);
|
|
220
|
+
}
|
|
196
221
|
}
|
|
197
222
|
|
|
198
223
|
async function writeLanguageConfig(targetDir, language, useJsx) {
|
|
@@ -284,6 +309,36 @@ async function injectJSXPlugin(targetDir, language) {
|
|
|
284
309
|
await writeFile(targetDir, `commands/prefix/hello.${jsxExtension}`, jsxPrefixCommand);
|
|
285
310
|
}
|
|
286
311
|
|
|
312
|
+
async function injectCachePlugin(targetDir, extension, useRedis, template, language) {
|
|
313
|
+
const entryPath = path.join(targetDir, `index.${extension}`);
|
|
314
|
+
let content = await fsp.readFile(entryPath, "utf8");
|
|
315
|
+
|
|
316
|
+
const adapterName = useRedis ? "RedisAdapter" : "MemoryAdapter";
|
|
317
|
+
const importLine = `import { CachePlugin, ${adapterName} } from "discordjs-nextgen-cache";`;
|
|
318
|
+
|
|
319
|
+
if (!content.includes(importLine)) {
|
|
320
|
+
content = `${importLine}\n${content}`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!content.includes("new CachePlugin")) {
|
|
324
|
+
const pluginCode = useRedis
|
|
325
|
+
? `app.use(new CachePlugin({ adapter: new RedisAdapter() }));`
|
|
326
|
+
: `app.use(new CachePlugin({ adapter: new MemoryAdapter() }));`;
|
|
327
|
+
|
|
328
|
+
content = content.replace(/const app = new App\((\{[\s\S]*?\}|)\);/, (match) => `${match}\n\n${pluginCode}`);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
await fsp.writeFile(entryPath, content, "utf8");
|
|
332
|
+
|
|
333
|
+
if (template === "advanced") {
|
|
334
|
+
const cmdCode = language === "ts"
|
|
335
|
+
? `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`
|
|
336
|
+
: `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`;
|
|
337
|
+
|
|
338
|
+
await writeFile(targetDir, `commands/prefix/money.${extension}`, cmdCode);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
287
342
|
async function copyTemplateDirectory(sourceDir, targetDir, context) {
|
|
288
343
|
if (!fs.existsSync(sourceDir)) return;
|
|
289
344
|
const entries = await fsp.readdir(sourceDir, { withFileTypes: true });
|