generator-discord 1.2.6 → 1.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.
- package/app/index.d.ts +4 -3
- package/app/index.d.ts.map +1 -0
- package/app/index.js +79 -97
- package/app/index.js.map +1 -1
- package/package.json +14 -8
- package/src/index.ts +13 -9
- package/test/generator.test.ts +70 -56
- /package/templates/python/{bot.py → main.py} +0 -0
package/app/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import Generator from 'yeoman-generator';
|
|
3
3
|
type BotType = 'typescript' | 'javascript' | 'python' | 'rust';
|
|
4
4
|
interface Answers {
|
|
@@ -9,12 +9,13 @@ interface Answers {
|
|
|
9
9
|
}
|
|
10
10
|
export default class DiscordGenerator extends Generator {
|
|
11
11
|
private answers;
|
|
12
|
-
constructor(args: string | string[], options:
|
|
12
|
+
constructor(args: string | string[], options: Record<string, unknown>);
|
|
13
13
|
prompting(): Promise<void>;
|
|
14
14
|
logo(): void;
|
|
15
15
|
writing(): void;
|
|
16
16
|
install(): Promise<void>;
|
|
17
17
|
end(): Promise<void>;
|
|
18
|
-
_replaceWords(content: Buffer, answers: Answers): string;
|
|
18
|
+
_replaceWords(content: string | Buffer, answers: Answers): string;
|
|
19
19
|
}
|
|
20
20
|
export {};
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAYzC,KAAK,OAAO,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE/D,UAAU,OAAO;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACtB;AAGD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IACtD,OAAO,CAAC,OAAO,CAA0B;gBAE7B,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI/D,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA6ChC,IAAI,IAAI,IAAI;IAYZ,OAAO,IAAI,IAAI;IAuBT,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBxB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB1B,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;CAWjE"}
|
package/app/index.js
CHANGED
|
@@ -1,74 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const yeoman_generator_1 = __importDefault(require("yeoman-generator"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
1
|
+
import Generator from 'yeoman-generator';
|
|
2
|
+
import path from 'path';
|
|
17
3
|
const TEMPLATE_DIR = '../templates/';
|
|
18
4
|
const USER_DIR = '.';
|
|
19
5
|
const BOT_NAME = /<%= bot-name %>/g;
|
|
20
6
|
const BOT_TOKEN = /<%= bot-token %>/g;
|
|
21
7
|
// needed for rust
|
|
22
8
|
const BOT_NAME_RUST = /bot_name/g;
|
|
23
|
-
class DiscordGenerator extends
|
|
9
|
+
export default class DiscordGenerator extends Generator {
|
|
10
|
+
answers = {};
|
|
24
11
|
constructor(args, options) {
|
|
25
12
|
super(args, options);
|
|
26
|
-
this.answers = {};
|
|
27
13
|
}
|
|
28
|
-
prompting() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
]);
|
|
71
|
-
});
|
|
14
|
+
async prompting() {
|
|
15
|
+
this.logo();
|
|
16
|
+
this.answers = await this.prompt([
|
|
17
|
+
{
|
|
18
|
+
type: 'input',
|
|
19
|
+
name: 'botName',
|
|
20
|
+
message: 'Your Discord Bot name:',
|
|
21
|
+
default: 'my-bot',
|
|
22
|
+
validate: (input) => new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$').test(input)
|
|
23
|
+
? true
|
|
24
|
+
: 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: 'list',
|
|
28
|
+
name: 'botType',
|
|
29
|
+
message: 'The type of Discord Bot you want to create.',
|
|
30
|
+
choices: [
|
|
31
|
+
{
|
|
32
|
+
name: 'New Discord Bot (TypeScript)',
|
|
33
|
+
value: 'typescript'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'New Discord Bot (JavaScript)',
|
|
37
|
+
value: 'javascript'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'New Discord Bot (Python)',
|
|
41
|
+
value: 'python'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'New Discord Bot (Rust)',
|
|
45
|
+
value: 'rust'
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'input',
|
|
51
|
+
name: 'botToken',
|
|
52
|
+
message: 'Your Discord Bot Token. (Enter to leave blank)',
|
|
53
|
+
default: 'your-bot-token'
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
72
56
|
}
|
|
73
57
|
logo() {
|
|
74
58
|
this.log(' \x1b[36m_____ _ _ \x1b[31m_');
|
|
@@ -82,8 +66,9 @@ class DiscordGenerator extends yeoman_generator_1.default {
|
|
|
82
66
|
this.log('\x1b[0m');
|
|
83
67
|
}
|
|
84
68
|
writing() {
|
|
85
|
-
|
|
69
|
+
const currentUrl = new URL('.', import.meta.url).pathname;
|
|
86
70
|
const paths = ['.'];
|
|
71
|
+
this.sourceRoot(path.join(currentUrl, TEMPLATE_DIR + this.answers.botType));
|
|
87
72
|
// iterate over all files
|
|
88
73
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
89
74
|
const path = paths[i];
|
|
@@ -92,43 +77,41 @@ class DiscordGenerator extends yeoman_generator_1.default {
|
|
|
92
77
|
});
|
|
93
78
|
}
|
|
94
79
|
}
|
|
95
|
-
install() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
80
|
+
async install() {
|
|
81
|
+
this.log('');
|
|
82
|
+
if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
|
|
83
|
+
const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
|
|
84
|
+
if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript' && !this.args.includes('skip-install')) {
|
|
100
85
|
this.log('Installing dependencies...');
|
|
101
|
-
this.
|
|
102
|
-
if (this.answers.botType === 'typescript') {
|
|
103
|
-
this.log('Building your Discord Bot...');
|
|
104
|
-
this.spawnCommandSync('npm', ['run', 'build'], options);
|
|
105
|
-
}
|
|
86
|
+
await this.spawn('npm', ['install'], options);
|
|
106
87
|
}
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
end() {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const answer = yield this.prompt({
|
|
113
|
-
type: 'list',
|
|
114
|
-
name: 'openWithCode',
|
|
115
|
-
message: 'Do you want to open your Discord Bot with \x1b[36mVisual Studio Code\x1b[0m?',
|
|
116
|
-
choices: [
|
|
117
|
-
{
|
|
118
|
-
name: 'open with `code`',
|
|
119
|
-
value: true
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: 'skip',
|
|
123
|
-
value: false
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
});
|
|
127
|
-
this.log('');
|
|
128
|
-
if (answer && answer.openWithCode) {
|
|
129
|
-
this.spawnCommand('code', [this.destinationPath(USER_DIR, this.answers.botName)]);
|
|
88
|
+
if (this.answers.botType === 'typescript' && !this.args.includes('skip-build')) {
|
|
89
|
+
this.log('Building your Discord Bot...');
|
|
90
|
+
await this.spawn('npm', ['run', 'build'], options);
|
|
130
91
|
}
|
|
92
|
+
}
|
|
93
|
+
this.log('Your Discord Bot \'\x1b[32m' + this.answers.botName + '\x1b[0m\' has been created!');
|
|
94
|
+
}
|
|
95
|
+
async end() {
|
|
96
|
+
const answer = await this.prompt({
|
|
97
|
+
type: 'list',
|
|
98
|
+
name: 'openWithCode',
|
|
99
|
+
message: 'Do you want to open your Discord Bot with \x1b[36mVisual Studio Code\x1b[0m?',
|
|
100
|
+
choices: [
|
|
101
|
+
{
|
|
102
|
+
name: 'open with `code`',
|
|
103
|
+
value: true
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'skip',
|
|
107
|
+
value: false
|
|
108
|
+
}
|
|
109
|
+
]
|
|
131
110
|
});
|
|
111
|
+
this.log('');
|
|
112
|
+
if (answer && answer.openWithCode) {
|
|
113
|
+
this.spawn('code', [this.destinationPath(USER_DIR, this.answers.botName)]);
|
|
114
|
+
}
|
|
132
115
|
}
|
|
133
116
|
_replaceWords(content, answers) {
|
|
134
117
|
if (answers.botType === 'rust') {
|
|
@@ -141,5 +124,4 @@ class DiscordGenerator extends yeoman_generator_1.default {
|
|
|
141
124
|
.replace(BOT_NAME, answers.botName);
|
|
142
125
|
}
|
|
143
126
|
}
|
|
144
|
-
exports.default = DiscordGenerator;
|
|
145
127
|
//# sourceMappingURL=index.js.map
|
package/app/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,YAAY,GAAG,eAAe,CAAC;AACrC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AACpC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC,kBAAkB;AAClB,MAAM,aAAa,GAAG,WAAW,CAAC;AAYlC,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,SAAS;IAC9C,OAAO,GAAY,EAAa,CAAC;IAEzC,YAAY,IAAuB,EAA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E;YAClC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,eAAe,CACvC,QAAQ,EACR,IAAI,CAAC,OAAO,CAAC,OAAO,CACpB,CAAC,CAAC,CAAC;SACJ;IACF,CAAC;IAED,aAAa,CAAC,OAAwB,EAAE,OAAgB;QACvD,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE;YAC/B,OAAO,OAAO,CAAC,QAAQ,EAAE;iBACvB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;iBACpC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;SAC1C;QAED,OAAO,OAAO,CAAC,QAAQ,EAAE;aACvB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;aACpC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-discord",
|
|
3
3
|
"displayName": "Generator-Discord",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"
|
|
4
|
+
"version": "1.3.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./app/index.js",
|
|
6
7
|
"description": "Yeoman generator for Discord.js",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=16.0.0"
|
|
10
|
+
},
|
|
7
11
|
"keywords": [
|
|
8
12
|
"yeoman-generator",
|
|
9
13
|
"discord.js",
|
|
@@ -15,6 +19,7 @@
|
|
|
15
19
|
"watch": "tsc -w",
|
|
16
20
|
"test": "vitest run",
|
|
17
21
|
"lint": "eslint src test --ext .ts",
|
|
22
|
+
"lint:fix": "eslint src test --ext .ts --fix",
|
|
18
23
|
"debug": "npx --node-arg=--inspect yo discord",
|
|
19
24
|
"clean": "npx rimraf app && npx rimraf node_modules"
|
|
20
25
|
},
|
|
@@ -36,14 +41,15 @@
|
|
|
36
41
|
},
|
|
37
42
|
"homepage": "https://github.com/emilkrebs/Generator-Discord",
|
|
38
43
|
"dependencies": {
|
|
39
|
-
"yeoman-generator": "^
|
|
44
|
+
"yeoman-generator": "^6.0.1"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
43
|
-
"@typescript-eslint/parser": "^6.
|
|
44
|
-
"eslint": "^8.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.8.0",
|
|
48
|
+
"@typescript-eslint/parser": "^6.8.0",
|
|
49
|
+
"eslint": "^8.51.0",
|
|
45
50
|
"typescript": "^5.2.2",
|
|
46
|
-
"vitest": "^0.34.
|
|
47
|
-
"yeoman-
|
|
51
|
+
"vitest": "^0.34.6",
|
|
52
|
+
"yeoman-environment": "^3.19.3",
|
|
53
|
+
"yeoman-test": "^8.1.0"
|
|
48
54
|
}
|
|
49
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface Answers {
|
|
|
23
23
|
export default class DiscordGenerator extends Generator {
|
|
24
24
|
private answers: Answers = {} as Answers;
|
|
25
25
|
|
|
26
|
-
constructor(args: string | string[], options:
|
|
26
|
+
constructor(args: string | string[], options: Record<string, unknown>) {
|
|
27
27
|
super(args, options);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -85,9 +85,11 @@ export default class DiscordGenerator extends Generator {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
writing(): void {
|
|
88
|
-
|
|
88
|
+
const currentUrl = new URL('.', import.meta.url).pathname;
|
|
89
89
|
const paths = ['.'];
|
|
90
90
|
|
|
91
|
+
this.sourceRoot(path.join(currentUrl, TEMPLATE_DIR + this.answers.botType));
|
|
92
|
+
|
|
91
93
|
// iterate over all files
|
|
92
94
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
93
95
|
const path = paths[i];
|
|
@@ -99,7 +101,7 @@ export default class DiscordGenerator extends Generator {
|
|
|
99
101
|
path
|
|
100
102
|
),
|
|
101
103
|
{
|
|
102
|
-
process: (content) => this._replaceWords(content, this.answers)
|
|
104
|
+
process: (content: string | Buffer) => this._replaceWords(content, this.answers)
|
|
103
105
|
}
|
|
104
106
|
);
|
|
105
107
|
}
|
|
@@ -110,12 +112,14 @@ export default class DiscordGenerator extends Generator {
|
|
|
110
112
|
if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
|
|
111
113
|
const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
|
|
112
114
|
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
+
if(this.answers.botType === 'typescript' || this.answers.botType === 'javascript' && !this.args.includes('skip-install')) {
|
|
116
|
+
this.log('Installing dependencies...');
|
|
117
|
+
await this.spawn('npm', ['install'], options);
|
|
118
|
+
}
|
|
115
119
|
|
|
116
|
-
if (this.answers.botType === 'typescript') {
|
|
120
|
+
if (this.answers.botType === 'typescript' && !this.args.includes('skip-build')) {
|
|
117
121
|
this.log('Building your Discord Bot...');
|
|
118
|
-
this.
|
|
122
|
+
await this.spawn('npm', ['run', 'build'], options);
|
|
119
123
|
}
|
|
120
124
|
}
|
|
121
125
|
|
|
@@ -141,14 +145,14 @@ export default class DiscordGenerator extends Generator {
|
|
|
141
145
|
});
|
|
142
146
|
this.log('');
|
|
143
147
|
if (answer && answer.openWithCode) {
|
|
144
|
-
this.
|
|
148
|
+
this.spawn('code', [this.destinationPath(
|
|
145
149
|
USER_DIR,
|
|
146
150
|
this.answers.botName
|
|
147
151
|
)]);
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
_replaceWords(content: Buffer, answers: Answers): string {
|
|
155
|
+
_replaceWords(content: string | Buffer, answers: Answers): string {
|
|
152
156
|
if (answers.botType === 'rust') {
|
|
153
157
|
return content.toString()
|
|
154
158
|
.replace(BOT_TOKEN, answers.botToken)
|
package/test/generator.test.ts
CHANGED
|
@@ -1,78 +1,79 @@
|
|
|
1
1
|
import { describe, test } from 'vitest';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createHelpers } from 'yeoman-test';
|
|
4
|
-
import {EOL} from 'os';
|
|
5
4
|
|
|
6
|
-
const
|
|
7
|
-
|
|
5
|
+
const currentUrl = new URL('../', import.meta.url).pathname;
|
|
6
|
+
|
|
7
|
+
const defaultAnswers = {
|
|
8
|
+
botName: 'test-bot',
|
|
8
9
|
botType: 'typescript',
|
|
9
10
|
botToken: 'xxx',
|
|
10
11
|
openWithCode: false,
|
|
11
12
|
};
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
botName
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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)
|
|
14
|
+
describe('Check yeoman generator works', () => {
|
|
15
|
+
const targetRoot = path.join(currentUrl, defaultAnswers.botName) + '/';
|
|
16
|
+
|
|
17
|
+
test('Should produce TypeScript files', async () => {
|
|
18
|
+
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
19
|
+
context.targetDirectory = targetRoot;
|
|
20
|
+
context.cleanTestDirectory(true);
|
|
21
|
+
await context
|
|
22
|
+
.withAnswers(defaultAnswers)
|
|
23
|
+
.withArguments(['skip-install', 'skip-build'])
|
|
27
24
|
.then((result) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const files = [
|
|
26
|
+
targetRoot + 'config.json',
|
|
27
|
+
targetRoot + 'src/index.ts',
|
|
28
|
+
targetRoot + 'tsconfig.json',
|
|
29
|
+
targetRoot + 'package.json',
|
|
30
|
+
];
|
|
31
|
+
result.assertFile(files);
|
|
32
|
+
result.assertJsonFileContent(targetRoot + 'config.json', CONFIG_JSON_EXPECTED);
|
|
32
33
|
});
|
|
33
|
-
context.cleanup();
|
|
34
|
+
context.cleanup();
|
|
34
35
|
}, 120_000);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
context
|
|
38
|
-
context.
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
|
|
37
|
+
test('Should produce Python files', async () => {
|
|
38
|
+
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
39
|
+
context.targetDirectory = targetRoot;
|
|
40
|
+
context.cleanTestDirectory(true);
|
|
41
|
+
await context
|
|
42
|
+
.withAnswers({...defaultAnswers, botType: 'python'})
|
|
41
43
|
.then((result) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
const files = [
|
|
45
|
+
targetRoot + 'main.py',
|
|
46
|
+
targetRoot + 'requirements.txt',
|
|
47
|
+
];
|
|
48
|
+
result.assertFile(files);
|
|
49
|
+
result.assertFileContent(targetRoot + 'main.py', PYTHON_BOT_EXPECTED);
|
|
44
50
|
});
|
|
45
|
-
context.cleanup();
|
|
51
|
+
context.cleanup();
|
|
46
52
|
}, 120_000);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
context
|
|
50
|
-
context.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
botType: 'rust',
|
|
55
|
-
})
|
|
53
|
+
|
|
54
|
+
test('Should produce Rust files', async () => {
|
|
55
|
+
const context = createHelpers({}).run(path.join(currentUrl, './app'));
|
|
56
|
+
context.targetDirectory = targetRoot;
|
|
57
|
+
context.cleanTestDirectory(true);
|
|
58
|
+
await context
|
|
59
|
+
.withAnswers({...defaultAnswers, botType: 'rust'})
|
|
56
60
|
.then((result) => {
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
const files = [
|
|
62
|
+
targetRoot + 'src/main.rs',
|
|
63
|
+
targetRoot + 'Cargo.toml',
|
|
64
|
+
];
|
|
65
|
+
result.assertFile(files);
|
|
66
|
+
result.assertFileContent(targetRoot + 'Cargo.toml', CARGO_TOML_EXPECTED);
|
|
59
67
|
});
|
|
60
|
-
context.cleanup();
|
|
61
|
-
}
|
|
62
|
-
, 120_000);
|
|
68
|
+
context.cleanup();
|
|
69
|
+
}, 120_000);
|
|
63
70
|
});
|
|
64
71
|
|
|
72
|
+
const CONFIG_JSON_EXPECTED: Record<string, string> = {
|
|
73
|
+
'token':'xxx'
|
|
74
|
+
};
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
return str.replace(/\r?\n/g, EOL);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// norminlize end of line
|
|
71
|
-
const CONFIG_JSON_EXPECTED = normilizeEOL(`{
|
|
72
|
-
"token":"xxx"
|
|
73
|
-
}`);
|
|
74
|
-
|
|
75
|
-
const BOT_PY_EXPECTED = normilizeEOL(`import discord
|
|
76
|
+
const PYTHON_BOT_EXPECTED = `import discord
|
|
76
77
|
|
|
77
78
|
intents = discord.Intents.default()
|
|
78
79
|
intents.message_content = True
|
|
@@ -91,4 +92,17 @@ async def on_message(message):
|
|
|
91
92
|
if message.content.startswith('!ping'):
|
|
92
93
|
await message.channel.send('Pong!')
|
|
93
94
|
|
|
94
|
-
client.run('
|
|
95
|
+
client.run('xxx')
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
const CARGO_TOML_EXPECTED = `[package]
|
|
99
|
+
name = "test-bot"
|
|
100
|
+
version = "0.1.0"
|
|
101
|
+
edition = "2021"
|
|
102
|
+
|
|
103
|
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
104
|
+
|
|
105
|
+
[dependencies]
|
|
106
|
+
serenity = { version = "0.11.6", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
|
|
107
|
+
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
|
|
108
|
+
`;
|
|
File without changes
|