-
-
Notifications
You must be signed in to change notification settings - Fork 803
/
Copy pathsetup.ts
88 lines (77 loc) · 2.73 KB
/
setup.ts
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
import dotenv from 'dotenv';
import fs from 'fs';
import inquirer from 'inquirer';
import { checkEnvFile } from './src/setup/checkEnvFile/checkEnvFile';
import { validateRecaptcha } from './src/setup/validateRecaptcha/validateRecaptcha';
import askAndSetDockerOption from './src/setup/askAndSetDockerOption/askAndSetDockerOption';
import updateEnvFile from './src/setup/updateEnvFile/updateEnvFile';
import askAndUpdatePort from './src/setup/askAndUpdatePort/askAndUpdatePort';
import { askAndUpdateTalawaApiUrl } from './src/setup/askForDocker/askForDocker';
// Ask and set up reCAPTCHA
const askAndSetRecaptcha = async (): Promise<void> => {
try {
const { shouldUseRecaptcha } = await inquirer.prompt({
type: 'confirm',
name: 'shouldUseRecaptcha',
message: 'Would you like to set up reCAPTCHA?',
default: true,
});
if (shouldUseRecaptcha) {
const { recaptchaSiteKeyInput } = await inquirer.prompt([
{
type: 'input',
name: 'recaptchaSiteKeyInput',
message: 'Enter your reCAPTCHA site key:',
validate: (input: string): boolean | string => {
return (
validateRecaptcha(input) ||
'Invalid reCAPTCHA site key. Please try again.'
);
},
},
]);
updateEnvFile('REACT_APP_RECAPTCHA_SITE_KEY', recaptchaSiteKeyInput);
}
} catch (error) {
console.error('Error setting up reCAPTCHA:', error);
throw new Error(`Failed to set up reCAPTCHA: ${(error as Error).message}`);
}
};
// Ask and set up logging errors in the console
const askAndSetLogErrors = async (): Promise<void> => {
const { shouldLogErrors } = await inquirer.prompt({
type: 'confirm',
name: 'shouldLogErrors',
message:
'Would you like to log Compiletime and Runtime errors in the console?',
default: true,
});
if (shouldLogErrors) {
updateEnvFile('ALLOW_LOGS', 'YES');
}
};
// Main function to run the setup process
export async function main(): Promise<void> {
try {
console.log('Welcome to the Talawa Admin setup! 🚀');
checkEnvFile();
await askAndSetDockerOption();
const envConfig = dotenv.parse(fs.readFileSync('.env', 'utf8'));
const useDocker = envConfig.USE_DOCKER === 'YES';
// Only run these commands if Docker is NOT used
if (!useDocker) {
await askAndUpdatePort();
await askAndUpdateTalawaApiUrl();
}
await askAndSetRecaptcha();
await askAndSetLogErrors();
console.log(
'\nCongratulations! Talawa Admin has been successfully set up! 🥂🎉',
);
} catch (error) {
console.error('\n❌ Setup failed:', error);
console.log('\nPlease try again or contact support if the issue persists.');
process.exit(1);
}
}
main();