-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-env.js
More file actions
134 lines (114 loc) · 4.12 KB
/
Copy pathsetup-env.js
File metadata and controls
134 lines (114 loc) · 4.12 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env node
/**
* Sphira Environment Setup Script
* This script helps you set up your environment variables for development
*/
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
console.log('🚀 Welcome to Sphira Environment Setup!');
console.log('This script will help you configure your .env.local file\n');
const questions = [
{
key: 'PRIVATE_KEY',
question: 'Enter your private key (without 0x prefix) [OPTIONAL for UI testing]: ',
default: 'your_private_key_here'
},
{
key: 'NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID',
question: 'Enter your WalletConnect Project ID (get from https://cloud.walletconnect.com/) [OPTIONAL]: ',
default: 'placeholder_project_id'
},
{
key: 'SOMNIA_API_KEY',
question: 'Enter your Somnia API Key [OPTIONAL]: ',
default: 'your_api_key_here'
}
];
const envConfig = {
// Blockchain Configuration
'SOMNIA_TESTNET_RPC_URL': 'https://testnet-rpc.somnia.network',
'SOMNIA_MAINNET_RPC_URL': 'https://mainnet-rpc.somnia.network',
// Application Configuration
'NEXT_PUBLIC_API_URL': 'http://localhost:3000/api',
'NEXT_PUBLIC_APP_URL': 'http://localhost:3000',
'NEXT_PUBLIC_CHAIN_ID': '2648',
'NEXT_PUBLIC_CHAIN_NAME': 'Somnia Testnet',
'NEXT_PUBLIC_CHAIN_SYMBOL': 'SOM',
'NEXT_PUBLIC_CHAIN_DECIMALS': '18',
// Development Settings
'NODE_ENV': 'development',
'NEXT_PUBLIC_ENABLE_TESTNET': 'true',
'NEXT_PUBLIC_ENABLE_MOCK_DATA': 'true',
'NEXT_PUBLIC_ENABLE_ANALYTICS': 'false',
'REPORT_GAS': 'true',
'LOG_LEVEL': 'info',
'DEBUG': 'false',
// Feature Flags
'NEXT_PUBLIC_ENABLE_CHAT': 'true',
'NEXT_PUBLIC_ENABLE_EMERGENCY_VAULT': 'true',
'NEXT_PUBLIC_ENABLE_YIELD_FARMING': 'true',
'NEXT_PUBLIC_ENABLE_NOTIFICATIONS': 'true',
// Security
'JWT_SECRET': 'development_jwt_secret_change_in_production',
'NEXTAUTH_URL': 'http://localhost:3000',
'NEXTAUTH_SECRET': 'development_nextauth_secret'
};
async function askQuestion(question, defaultValue) {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer.trim() || defaultValue);
});
});
}
async function setupEnvironment() {
console.log('📝 Setting up your environment variables...\n');
// Ask user questions
for (const q of questions) {
const answer = await askQuestion(q.question, q.default);
envConfig[q.key] = answer;
}
// Generate .env.local content
let envContent = '# Sphira DeFi Platform - Local Environment Configuration\n';
envContent += '# Generated by setup-env.js script\n';
envContent += `# Created on: ${new Date().toISOString()}\n\n`;
envContent += '# =============================================================================\n';
envContent += '# BLOCKCHAIN NETWORK CONFIGURATION\n';
envContent += '# =============================================================================\n\n';
for (const [key, value] of Object.entries(envConfig)) {
envContent += `${key}=${value}\n`;
}
// Write to .env.local
const envPath = path.join(__dirname, '.env.local');
try {
fs.writeFileSync(envPath, envContent);
console.log('\n✅ Environment file created successfully!');
console.log(`📁 File location: ${envPath}`);
console.log('\n🎯 Next steps:');
console.log('1. Review your .env.local file');
console.log('2. Update any placeholder values with real API keys');
console.log('3. Run: npm run dev');
console.log('\n🔒 Security Note: Never commit .env.local to git!');
} catch (error) {
console.error('❌ Error creating environment file:', error.message);
}
rl.close();
}
// Check if .env.local already exists
const envPath = path.join(__dirname, '.env.local');
if (fs.existsSync(envPath)) {
rl.question('⚠️ .env.local already exists. Overwrite? (y/N): ', (answer) => {
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
setupEnvironment();
} else {
console.log('👍 Keeping existing .env.local file');
rl.close();
}
});
} else {
setupEnvironment();
}