generator-discord 1.1.0 → 1.1.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
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
<div id="badges" align="center">
|
|
11
11
|
|
|
12
12
|
[](https://github.com/emilkrebs/generator-discord/actions/workflows/build.yml)
|
|
13
|
+
[](https://github.com/emilkrebs/generator-discord/actions/workflows/test.yml)
|
|
13
14
|
[](https://www.npmjs.com/package/generator-discord)
|
|
14
15
|
[](https://www.npmjs.com/package/generator-discord)
|
|
15
16
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-discord",
|
|
3
3
|
"displayName": "Generator-Discord",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"main": "./app/index.js",
|
|
6
6
|
"description": "Yeoman generator for Discord.js",
|
|
7
7
|
"keywords": [
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"app",
|
|
21
21
|
"templates",
|
|
22
|
-
"src"
|
|
22
|
+
"src",
|
|
23
|
+
"test"
|
|
23
24
|
],
|
|
24
25
|
"types": "app/index.d.ts",
|
|
25
26
|
"author": "Emil Krebs",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// write a unit test for the yeoman generator
|
|
2
|
+
|
|
3
|
+
import { describe, test } from 'vitest';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { createHelpers } from 'yeoman-test';
|
|
6
|
+
import {EOL} from 'os'
|
|
7
|
+
|
|
8
|
+
const typescriptAnswers = {
|
|
9
|
+
botName: 'typescript-bot',
|
|
10
|
+
botType: 'typescript',
|
|
11
|
+
botToken: 'xxx',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const pythonAnswers = {
|
|
15
|
+
botName: 'python-bot',
|
|
16
|
+
botType: 'python',
|
|
17
|
+
botToken: 'xxxx',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('Check if the generator works', () => {
|
|
21
|
+
test('Should generate typescript files', async () => {
|
|
22
|
+
const context = createHelpers({}).run(path.join(__dirname, '../app'));
|
|
23
|
+
context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
|
|
24
|
+
context.cleanTestDirectory(true); // clean-up test-temp
|
|
25
|
+
await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
|
|
26
|
+
.withAnswers(typescriptAnswers)
|
|
27
|
+
.then((result) => {
|
|
28
|
+
result.assertFile([`${typescriptAnswers.botName}/package.json`]);
|
|
29
|
+
result.assertFile([`${typescriptAnswers.botName}/config.json`]);
|
|
30
|
+
result.assertFile([`${typescriptAnswers.botName}/src/index.ts`]);
|
|
31
|
+
result.assertFileContent(`${typescriptAnswers.botName}/config.json`, CONFIG_JSON_EXPECTED);
|
|
32
|
+
});
|
|
33
|
+
context.cleanup(); // clean-up
|
|
34
|
+
}, 120_000);
|
|
35
|
+
test('Should generate python files', async () => {
|
|
36
|
+
const context = createHelpers({}).run(path.join(__dirname, '../app'));
|
|
37
|
+
context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
|
|
38
|
+
context.cleanTestDirectory(true); // clean-up test-temp
|
|
39
|
+
await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
|
|
40
|
+
.withAnswers(pythonAnswers)
|
|
41
|
+
.then((result) => {
|
|
42
|
+
result.assertFile([`${pythonAnswers.botName}/bot.py`]);
|
|
43
|
+
result.assertFileContent(`${pythonAnswers.botName}/bot.py`, BOT_PY_EXPECTED);
|
|
44
|
+
});
|
|
45
|
+
context.cleanup(); // clean-up
|
|
46
|
+
}, 120_000);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function normilizeEOL(str: string) {
|
|
51
|
+
return str.replace(/\r?\n/g, EOL);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// norminlize end of line
|
|
55
|
+
const CONFIG_JSON_EXPECTED = normilizeEOL(`{
|
|
56
|
+
"token":"xxx"
|
|
57
|
+
}`);
|
|
58
|
+
|
|
59
|
+
const BOT_PY_EXPECTED = normilizeEOL(`import discord
|
|
60
|
+
from discord.ext import commands
|
|
61
|
+
|
|
62
|
+
# Define bot prefix and create bot instance
|
|
63
|
+
bot_prefix = "!"
|
|
64
|
+
bot = commands.Bot(command_prefix=bot_prefix)
|
|
65
|
+
|
|
66
|
+
# Define bot events
|
|
67
|
+
@bot.event
|
|
68
|
+
async def on_ready():
|
|
69
|
+
print(f"Logged in as {bot.user.name} ({bot.user.id})")
|
|
70
|
+
|
|
71
|
+
# Define bot commands
|
|
72
|
+
@bot.command()
|
|
73
|
+
async def ping(ctx):
|
|
74
|
+
await ctx.send("Pong!")
|
|
75
|
+
|
|
76
|
+
# Run bot with bot token
|
|
77
|
+
bot.run("xxxx")
|
|
78
|
+
|
|
79
|
+
# For more information on how to use discord.py, visit https://discordpy.readthedocs.io/en/latest/`);
|