forked from AnswerOverflow/AnswerOverflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
executable file
·90 lines (73 loc) · 2.69 KB
/
setup.ts
File metadata and controls
executable file
·90 lines (73 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { $ } from 'bun';
// Check if .env file exists, if it does, exit the script
import * as fs from 'fs';
import * as Bun from 'bun';
if (fs.existsSync('.env')) {
console.error(
'An .env file already exists. Please delete it and run this script again.',
);
process.exit(0);
}
// Step 1: Prompt the user for Discord bot credentials
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function askQuestion(query: string): Promise<string> {
return new Promise((resolve) => rl.question(query, resolve));
}
console.log(
'We need to create a Discord bot to run the application, we will walk you through the process.',
);
console.log(
'Start at https://discord.com/developers/applications and create a new application. Search on the page for Application ID',
);
const NEXT_PUBLIC_DISCORD_CLIENT_ID = await askQuestion(
'Enter your Discord Application ID: ',
);
console.clear();
console.log(
`Now go to https://discord.com/developers/applications/${NEXT_PUBLIC_DISCORD_CLIENT_ID}/oauth2 and click on 'Reset Secret' to get your Client Secret.`,
);
const DISCORD_CLIENT_SECRET = await askQuestion(
'Enter your Discord Client Secret: ',
);
console.clear();
console.log(
`Now go to https://discord.com/developers/applications/${NEXT_PUBLIC_DISCORD_CLIENT_ID}/bot and click on 'Reset Token' to get your Bot Token.`,
);
const DISCORD_BOT_TOKEN = await askQuestion('Enter your Discord Bot Token: ');
console.clear();
// Step 1: Create .env file with the provided Discord bot token, secret, and client ID
console.log('Creating .env file...');
await Bun.write(
'.env',
`DISCORD_TOKEN=${DISCORD_BOT_TOKEN}\nDISCORD_CLIENT_SECRET=${DISCORD_CLIENT_SECRET}\nNEXT_PUBLIC_DISCORD_CLIENT_ID=${NEXT_PUBLIC_DISCORD_CLIENT_ID}\n`,
);
console.log('.env file created successfully with your provided credentials.');
console.clear();
// Step 2: Run bun install
console.log('Running bun install...');
await $`bun i`;
// Step 3: Start bun dev:dbs in the background in a new terminal
console.log('Starting bun dev:dbs in the background...');
const { spawn } = require('child_process');
spawn('bun', ['dev:dbs'], {
detached: true,
stdio: 'ignore',
});
// wait for 5 seconds to ensure the dbs are up and running
await new Promise((resolve) => setTimeout(resolve, 30000));
// Step 4: Change directory to packages/core, push and seed database
console.log('Changing directory to packages/core...');
process.chdir('packages/core');
console.log('Pushing database schema...');
await $`bun db:push`;
console.log('Wiping database...');
await $`bun db:wipe`;
console.log('Seeding database...');
await $`bun db:seed`;
console.log('Script execution completed.');
rl.close();
process.exit(0);