-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
42 lines (35 loc) · 1.08 KB
/
setup.js
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
const { execSync } = require('child_process');
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('Setting up your project...');
// Install dependencies
console.log('Installing dependencies...');
execSync('npm install', { stdio: 'inherit' });
// Create .env file
console.log('\nSetting up environment variables...');
const envExample = fs.readFileSync('.env.example', 'utf8');
const envVars = envExample.split('\n').filter(line => line.trim() !== '');
const askQuestion = (question) => {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer);
});
});
};
const setupEnv = async () => {
let envContent = '';
for (const line of envVars) {
const [key] = line.split('=');
const value = await askQuestion(`Enter value for ${key}: `);
envContent += `${key}=${value}\n`;
}
fs.writeFileSync('.env', envContent);
};
setupEnv().then(() => {
console.log('\nSetup complete! You can now run your project.');
rl.close();
});