generator-discord 1.2.4 → 1.2.5

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.js CHANGED
@@ -22,6 +22,7 @@ const BOT_NAME_RUST = /bot_name/g;
22
22
  class DiscordGenerator extends yeoman_generator_1.default {
23
23
  constructor(args, options) {
24
24
  super(args, options);
25
+ this.answers = {};
25
26
  }
26
27
  prompting() {
27
28
  return __awaiter(this, void 0, void 0, function* () {
@@ -32,7 +33,7 @@ class DiscordGenerator extends yeoman_generator_1.default {
32
33
  name: 'botName',
33
34
  message: 'Your Discord Bot name:',
34
35
  default: 'my-bot',
35
- validate: (input) => new RegExp("^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(input)
36
+ validate: (input) => new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$').test(input)
36
37
  ? true
37
38
  : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
38
39
  },
@@ -69,15 +70,15 @@ class DiscordGenerator extends yeoman_generator_1.default {
69
70
  });
70
71
  }
71
72
  logo() {
72
- this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
73
- this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
74
- this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
75
- this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
76
- this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
77
- this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
78
- this.log(" \x1b[34m_/ | ");
79
- this.log(" \x1b[35m|__/ ");
80
- this.log("\x1b[0m");
73
+ this.log(' \x1b[36m_____ _ _ \x1b[31m_ ');
74
+ this.log(' \x1b[36m| __ \\(_) | | \x1b[31m(_) ');
75
+ this.log(' \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ');
76
+ this.log(' \x1b[36m| | | | / __|/ __/ _ \\| \'__/ _` | \x1b[33m| / __|');
77
+ this.log(' \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\');
78
+ this.log(' \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/');
79
+ this.log(' \x1b[34m_/ | ');
80
+ this.log(' \x1b[35m|__/ ');
81
+ this.log('\x1b[0m');
81
82
  }
82
83
  writing() {
83
84
  this.sourceRoot(path_1.default.join(__dirname, TEMPLATE_DIR + this.answers.botType));
package/app/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wEAAyC;AACzC,gDAAwB;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,MAAM,aAAa,GAAG,WAAW,CAAC;AAYlC,MAAqB,gBAAiB,SAAQ,0BAAS;IAGnD,YAAY,IAAuB,EAAE,OAAmC;QACpE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzB,CAAC;IAEK,SAAS;;YACX,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;gBAC7B;oBACI,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE,wBAAwB;oBACjC,OAAO,EAAE,QAAQ;oBACjB,QAAQ,EAAE,CAAC,KAAa,EAAoB,EAAE,CAC1C,IAAI,MAAM,CAAC,2DAA2D,CAAC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GED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "generator-discord",
3
3
  "displayName": "Generator-Discord",
4
- "version": "1.2.4",
4
+ "version": "1.2.5",
5
5
  "main": "./app/index.js",
6
6
  "description": "Yeoman generator for Discord.js",
7
7
  "keywords": [
@@ -14,6 +14,7 @@
14
14
  "build": "tsc",
15
15
  "watch": "tsc -w",
16
16
  "test": "vitest run",
17
+ "lint": "eslint src test --ext .ts",
17
18
  "debug": "npx --node-arg=--inspect yo discord",
18
19
  "clean": "npx rimraf app && npx rimraf node_modules"
19
20
  },
@@ -38,8 +39,11 @@
38
39
  "yeoman-generator": "^5.9.0"
39
40
  },
40
41
  "devDependencies": {
41
- "vitest": "^0.34.3",
42
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
43
+ "@typescript-eslint/parser": "^6.6.0",
44
+ "eslint": "^8.49.0",
42
45
  "typescript": "^5.2.2",
46
+ "vitest": "^0.34.4",
43
47
  "yeoman-test": "^7.4.0"
44
48
  }
45
49
  }
package/src/index.ts CHANGED
@@ -20,136 +20,136 @@ interface Answers {
20
20
 
21
21
 
22
22
  export default class DiscordGenerator extends Generator {
23
- private answers: Answers;
24
-
25
- constructor(args: string | string[], options: Generator.GeneratorOptions) {
26
- super(args, options);
27
- }
28
-
29
- async prompting(): Promise<void> {
30
- this.logo();
31
- this.answers = await this.prompt([
32
- {
33
- type: 'input',
34
- name: 'botName',
35
- message: 'Your Discord Bot name:',
36
- default: 'my-bot',
37
- validate: (input: string): boolean | string =>
38
- new RegExp("^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$").test(input)
39
- ? true
40
- : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
41
- },
42
- {
43
- type: 'list',
44
- name: 'botType',
45
- message: 'The type of Discord Bot you want to create.',
46
- choices: [
47
- {
48
- name: 'New Discord Bot (TypeScript)',
49
- value: 'typescript'
50
- },
51
- {
52
- name: 'New Discord Bot (JavaScript)',
53
- value: 'javascript'
54
- },
55
- {
56
- name: 'New Discord Bot (Python)',
57
- value: 'python'
58
- },
59
- {
60
- name: 'New Discord Bot (Rust)',
61
- value: 'rust'
62
- },
63
- ]
64
- },
65
- {
66
- type: 'input',
67
- name: 'botToken',
68
- message: 'Your Discord Bot Token. (Enter to leave blank)',
69
- default: 'your-bot-token'
70
- }
71
- ]);
72
- }
73
-
74
- logo(): void {
75
- this.log(" \x1b[36m_____ _ _ \x1b[31m_ ");
76
- this.log(" \x1b[36m| __ \\(_) | | \x1b[31m(_) ");
77
- this.log(" \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ");
78
- this.log(" \x1b[36m| | | | / __|/ __/ _ \\| '__/ _` | \x1b[33m| / __|");
79
- this.log(" \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\");
80
- this.log(" \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/");
81
- this.log(" \x1b[34m_/ | ");
82
- this.log(" \x1b[35m|__/ ");
83
- this.log("\x1b[0m");
84
- }
85
-
86
- writing(): void {
87
- this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
88
- ['.'].forEach(
89
- (path: string) => {
90
- this.fs.copy(
91
- this.templatePath(path),
92
- this.destinationPath(
93
- USER_DIR,
94
- this.answers.botName,
95
- path
96
- ),
97
- {
98
- process: (content: Buffer) => this._replaceWords(content, this.answers)
99
- }
100
- );
101
- }
102
- );
103
- }
104
-
105
- async install(): Promise<void> {
106
- this.log('');
107
- if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
108
- const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
109
- this.spawnCommandSync('npm', ['install'], options);
110
- if(this.answers.botType === 'typescript') {
111
- this.spawnCommandSync('npm', ['run', 'build'], options);
112
- }
113
- }
114
-
115
- this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
116
-
117
- }
118
-
119
- async end(): Promise<void> {
120
- const answer = await this.prompt({
121
- type: 'list',
122
- name: 'openWithCode',
123
- message: 'Do you want to open your Discord Bot with Visual Studio Code?',
124
- choices: [
125
- {
126
- name: 'open with `code`',
127
- value: true
128
- },
129
- {
130
- name: 'skip',
131
- value: false
132
- }
133
- ]
134
- });
135
- this.log('');
136
- if (answer && answer.openWithCode) {
137
- this.spawnCommand('code', [this.destinationPath(
138
- USER_DIR,
139
- this.answers.botName
140
- )]);
141
- }
142
- }
143
-
144
- _replaceWords(content: Buffer, answers: Answers): string {
145
- if(answers.botType === 'rust') {
146
- return content.toString()
147
- .replace(BOT_TOKEN, answers.botToken)
148
- .replace(BOT_NAME_RUST, answers.botName);
149
- }
150
-
151
- return content.toString()
152
- .replace(BOT_TOKEN,answers.botToken)
153
- .replace(BOT_NAME, answers.botName);
154
- }
23
+ private answers: Answers = {} as Answers;
24
+
25
+ constructor(args: string | string[], options: Generator.GeneratorOptions) {
26
+ super(args, options);
27
+ }
28
+
29
+ async prompting(): Promise<void> {
30
+ this.logo();
31
+ this.answers = await this.prompt([
32
+ {
33
+ type: 'input',
34
+ name: 'botName',
35
+ message: 'Your Discord Bot name:',
36
+ default: 'my-bot',
37
+ validate: (input: string): boolean | string =>
38
+ new RegExp('^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$').test(input)
39
+ ? true
40
+ : 'Invalid bot name. Please use only lowercase letters, numbers, and hyphens. Must start with a letter.'
41
+ },
42
+ {
43
+ type: 'list',
44
+ name: 'botType',
45
+ message: 'The type of Discord Bot you want to create.',
46
+ choices: [
47
+ {
48
+ name: 'New Discord Bot (TypeScript)',
49
+ value: 'typescript'
50
+ },
51
+ {
52
+ name: 'New Discord Bot (JavaScript)',
53
+ value: 'javascript'
54
+ },
55
+ {
56
+ name: 'New Discord Bot (Python)',
57
+ value: 'python'
58
+ },
59
+ {
60
+ name: 'New Discord Bot (Rust)',
61
+ value: 'rust'
62
+ },
63
+ ]
64
+ },
65
+ {
66
+ type: 'input',
67
+ name: 'botToken',
68
+ message: 'Your Discord Bot Token. (Enter to leave blank)',
69
+ default: 'your-bot-token'
70
+ }
71
+ ]);
72
+ }
73
+
74
+ logo(): void {
75
+ this.log(' \x1b[36m_____ _ _ \x1b[31m_ ');
76
+ this.log(' \x1b[36m| __ \\(_) | | \x1b[31m(_) ');
77
+ this.log(' \x1b[36m| | | |_ ___ ___ ___ _ __ __| | \x1b[33m_ ___ ');
78
+ this.log(' \x1b[36m| | | | / __|/ __/ _ \\| \'__/ _` | \x1b[33m| / __|');
79
+ this.log(' \x1b[36m| |__| | \\__ \\ (_| (_) | | | (_| |\x1b[37m_\x1b[32m| \\__ \\');
80
+ this.log(' \x1b[36m|_____/|_|___/\\___\\___/|_| \\__,_\x1b[37m(_) \x1b[32m|___/');
81
+ this.log(' \x1b[34m_/ | ');
82
+ this.log(' \x1b[35m|__/ ');
83
+ this.log('\x1b[0m');
84
+ }
85
+
86
+ writing(): void {
87
+ this.sourceRoot(path.join(__dirname, TEMPLATE_DIR + this.answers.botType));
88
+ ['.'].forEach(
89
+ (path: string) => {
90
+ this.fs.copy(
91
+ this.templatePath(path),
92
+ this.destinationPath(
93
+ USER_DIR,
94
+ this.answers.botName,
95
+ path
96
+ ),
97
+ {
98
+ process: (content: Buffer) => this._replaceWords(content, this.answers)
99
+ }
100
+ );
101
+ }
102
+ );
103
+ }
104
+
105
+ async install(): Promise<void> {
106
+ this.log('');
107
+ if (this.answers.botType === 'typescript' || this.answers.botType === 'javascript') {
108
+ const options = { cwd: this.destinationPath(USER_DIR, this.answers.botName) };
109
+ this.spawnCommandSync('npm', ['install'], options);
110
+ if(this.answers.botType === 'typescript') {
111
+ this.spawnCommandSync('npm', ['run', 'build'], options);
112
+ }
113
+ }
114
+
115
+ this.log('Your Discord Bot ' + this.answers.botName + ' has been created!');
116
+
117
+ }
118
+
119
+ async end(): Promise<void> {
120
+ const answer = await this.prompt({
121
+ type: 'list',
122
+ name: 'openWithCode',
123
+ message: 'Do you want to open your Discord Bot with Visual Studio Code?',
124
+ choices: [
125
+ {
126
+ name: 'open with `code`',
127
+ value: true
128
+ },
129
+ {
130
+ name: 'skip',
131
+ value: false
132
+ }
133
+ ]
134
+ });
135
+ this.log('');
136
+ if (answer && answer.openWithCode) {
137
+ this.spawnCommand('code', [this.destinationPath(
138
+ USER_DIR,
139
+ this.answers.botName
140
+ )]);
141
+ }
142
+ }
143
+
144
+ _replaceWords(content: Buffer, answers: Answers): string {
145
+ if(answers.botType === 'rust') {
146
+ return content.toString()
147
+ .replace(BOT_TOKEN, answers.botToken)
148
+ .replace(BOT_NAME_RUST, answers.botName);
149
+ }
150
+
151
+ return content.toString()
152
+ .replace(BOT_TOKEN,answers.botToken)
153
+ .replace(BOT_NAME, answers.botName);
154
+ }
155
155
  }
@@ -7,32 +7,32 @@ const prefix = '!';
7
7
 
8
8
  // Run this code when the client is ready. This event will only trigger one time after logging in
9
9
  client.once('ready', () => {
10
- console.log(`Bot is logged in as ${client.user.tag}.`);
10
+ console.log(`Bot is logged in as ${client.user.tag}.`);
11
11
  });
12
12
 
13
13
 
14
14
  // Listen for messages
15
15
  client.on('messageCreate', async message => {
16
- // Ignore messages that don't start with the prefix or are from a bot
17
- if (!message.content.startsWith(prefix) || message.author.bot) return;
18
-
19
- // Split the message into command and arguments
20
- const args = message.content.slice(prefix.length).trim().split(/ +/);
21
- const command = args.shift()?.toLowerCase();
22
-
23
- // ping - bot will reply with Pong!
24
- if (command === 'ping') {
25
- await message.reply('Pong!');
26
- }
27
- // say <message> - bot will send the message
28
- else if (command === 'say') {
29
- if (!args.length) {
30
- await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
- return;
32
- }
33
- await message.channel.send(args.join(' '));
34
- return;
35
- }
16
+ // Ignore messages that don't start with the prefix or are from a bot
17
+ if (!message.content.startsWith(prefix) || message.author.bot) return;
18
+
19
+ // Split the message into command and arguments
20
+ const args = message.content.slice(prefix.length).trim().split(/ +/);
21
+ const command = args.shift()?.toLowerCase();
22
+
23
+ // ping - bot will reply with Pong!
24
+ if (command === 'ping') {
25
+ await message.reply('Pong!');
26
+ }
27
+ // say <message> - bot will send the message
28
+ else if (command === 'say') {
29
+ if (!args.length) {
30
+ await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
+ return;
32
+ }
33
+ await message.channel.send(args.join(' '));
34
+ return;
35
+ }
36
36
  });
37
37
 
38
38
 
@@ -7,32 +7,32 @@ const prefix = '!';
7
7
 
8
8
  // Run this code when the client is ready. This event will only trigger one time after logging in
9
9
  client.once('ready', () => {
10
- console.log(`Bot is logged in as ${client.user.tag}.`);
10
+ console.log(`Bot is logged in as ${client.user!.tag}.`);
11
11
  });
12
12
 
13
13
 
14
14
  // Listen for messages
15
15
  client.on('messageCreate', async message => {
16
- // Ignore messages that don't start with the prefix or are from a bot
17
- if(!message.content.startsWith(prefix) || message.author.bot) return;
16
+ // Ignore messages that don't start with the prefix or are from a bot
17
+ if(!message.content.startsWith(prefix) || message.author.bot) return;
18
18
 
19
- // Split the message into command and arguments
20
- const args = message.content.slice(prefix.length).trim().split(/ +/);
21
- const command = args.shift()?.toLowerCase();
19
+ // Split the message into command and arguments
20
+ const args = message.content.slice(prefix.length).trim().split(/ +/);
21
+ const command = args.shift()?.toLowerCase();
22
22
 
23
- // ping - bot will reply with Pong!
24
- if(command === 'ping') {
25
- await message.reply('Pong!');
26
- }
27
- // say <message> - bot will send the message
28
- else if(command === 'say') {
29
- if(!args.length) {
30
- await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
- return;
32
- }
33
- await message.channel.send(args.join(' '));
34
- return;
35
- }
23
+ // ping - bot will reply with Pong!
24
+ if(command === 'ping') {
25
+ await message.reply('Pong!');
26
+ }
27
+ // say <message> - bot will send the message
28
+ else if(command === 'say') {
29
+ if(!args.length) {
30
+ await message.channel.send(`You didn't provide any arguments, ${message.author}!`);
31
+ return;
32
+ }
33
+ await message.channel.send(args.join(' '));
34
+ return;
35
+ }
36
36
  });
37
37
 
38
38
 
@@ -5,7 +5,7 @@
5
5
  "lib": ["ESNext"],
6
6
  "sourceMap": true,
7
7
  "outDir": "dist",
8
- "strict": false,
8
+ "strict": true,
9
9
  "noUnusedLocals": true,
10
10
  "noImplicitReturns": true,
11
11
  "moduleResolution": "node",
@@ -1,70 +1,70 @@
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'
4
+ import {EOL} from 'os';
5
5
 
6
6
  const typescriptAnswers = {
7
- botName: 'typescript-bot',
8
- botType: 'typescript',
9
- botToken: 'xxx',
10
- openWithCode: false,
11
- }
7
+ botName: 'typescript-bot',
8
+ botType: 'typescript',
9
+ botToken: 'xxx',
10
+ openWithCode: false,
11
+ };
12
12
 
13
13
  const pythonAnswers = {
14
- botName: 'python-bot',
15
- botType: 'python',
16
- botToken: 'xxxx',
17
- openWithCode: false,
18
- }
14
+ botName: 'python-bot',
15
+ botType: 'python',
16
+ botToken: 'xxxx',
17
+ openWithCode: false,
18
+ };
19
19
 
20
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
- test('Should generate rust files', async () => {
48
- const context = createHelpers({}).run(path.join(__dirname, '../app'));
49
- context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
50
- context.cleanTestDirectory(true); // clean-up test-temp
51
- await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
52
- .withAnswers({
53
- ...pythonAnswers,
54
- botType: 'rust',
55
- })
56
- .then((result) => {
57
- result.assertFile([`${pythonAnswers.botName}/Cargo.toml`]);
58
- result.assertFile([`${pythonAnswers.botName}/src/main.rs`]);
59
- });
60
- context.cleanup(); // clean-up
61
- }
62
- , 120_000);
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
+ test('Should generate rust files', async () => {
48
+ const context = createHelpers({}).run(path.join(__dirname, '../app'));
49
+ context.targetDirectory = path.join(__dirname, '../test-temp'); // generate in test-temp
50
+ context.cleanTestDirectory(true); // clean-up test-temp
51
+ await context.onGenerator(generator => generator.destinationRoot(context.targetDirectory, false))
52
+ .withAnswers({
53
+ ...pythonAnswers,
54
+ botType: 'rust',
55
+ })
56
+ .then((result) => {
57
+ result.assertFile([`${pythonAnswers.botName}/Cargo.toml`]);
58
+ result.assertFile([`${pythonAnswers.botName}/src/main.rs`]);
59
+ });
60
+ context.cleanup(); // clean-up
61
+ }
62
+ , 120_000);
63
63
  });
64
64
 
65
65
 
66
66
  function normilizeEOL(str: string) {
67
- return str.replace(/\r?\n/g, EOL);
67
+ return str.replace(/\r?\n/g, EOL);
68
68
  }
69
69
 
70
70
  // norminlize end of line