Repository navigation
Expand file tree
/
Copy pathsetup-env.js
More file actions
234 lines (185 loc) · 7.12 KB
/
Copy pathsetup-env.js
File metadata and controls
234 lines (185 loc) · 7.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env node
// ==================================================
// 🚀 Setup Script - Configuración de Variables de Entorno
// ==================================================
import fs from "fs";
import path from "path";
import readline from "readline";
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
console.log(`
🚀 ¡Bienvenido al configurador de PREGUNTITAS!
==================================================
Este asistente te ayudará a configurar las variables de entorno
necesarias para que la aplicación funcione correctamente.
📝 Se creará un archivo .env con tu configuración.
⚡ NUEVO: Ahora incluye configuración de MercadoPago para pagos!
💰 Podrás monetizar tu aplicación de quizzes.
`);
async function askQuestion(question) {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer.trim());
});
});
}
async function setupEnvironment() {
try {
console.log("\n🔑 CONFIGURACIÓN DE OpenAI API KEY");
console.log("=======================================");
const apiKey = await askQuestion(
"1. Ingresa tu API Key de OpenAI (obtén una en https://platform.openai.com/api-keys): "
);
console.log("\n🔧 CONFIGURACIÓN DE ENTORNO");
console.log("============================");
const environment =
(await askQuestion(
"2. ¿Qué entorno estás configurando? [development/production] (default: development): "
)) || "development";
console.log("\n🧠 CONFIGURACIÓN DE IA");
console.log("========================");
const aiModel =
(await askQuestion(
"3. ¿Qué modelo de IA quieres usar? [gpt-4o-mini/gpt-4-turbo-preview/gpt-3.5-turbo] (default: gpt-4o-mini): "
)) || "gpt-4o-mini";
const maxQuestions =
(await askQuestion(
"4. ¿Máximo número de preguntas por quiz? (default: 15): "
)) || "15";
const temperature =
(await askQuestion(
"5. ¿Nivel de creatividad de la IA? (0.0 = conservador, 1.0 = creativo, default: 0.7): "
)) || "0.7";
console.log("\n📁 CONFIGURACIÓN DE ARCHIVOS");
console.log("=============================");
const maxFileSize =
(await askQuestion(
"6. ¿Tamaño máximo de archivo en MB? (default: 10): "
)) || "10";
const maxPdfPages =
(await askQuestion(
"7. ¿Máximo páginas de PDF a procesar? (default: 10): "
)) || "10";
console.log("\n💰 CONFIGURACIÓN DE MERCADOPAGO");
console.log("================================");
const mpPublicKey = await askQuestion(
"8. Ingresa tu Public Key de MercadoPago (opcional, obtén una en https://www.mercadopago.com.ar/developers/panel): "
);
const mpAccessToken = await askQuestion(
"9. Ingresa tu Access Token de MercadoPago (opcional, MANTENER SECRETO): "
);
const mpEnvironment =
(await askQuestion(
"10. ¿Entorno de MercadoPago? [sandbox/production] (default: sandbox): "
)) || "sandbox";
console.log("\n🔍 CONFIGURACIÓN DE DEBUG");
console.log("==========================");
const debugMode =
(await askQuestion(
"11. ¿Activar modo debug? [true/false] (default: true): "
)) || "true";
const debugApi =
(await askQuestion(
"12. ¿Mostrar logs de API? [true/false] (default: false): "
)) || "false";
// Crear contenido del archivo .env
const envContent = `# ==================================================
# 🚀 PREGUNTITAS - Variables de Entorno
# Generado automáticamente por setup-env.js
# ==================================================
# 🔑 OpenAI Configuration
VITE_OPENAI_API_KEY=${apiKey}
# 🔧 Environment Configuration
VITE_APP_ENV=${environment}
# 🎯 App Configuration
VITE_APP_NAME="Preguntitas"
VITE_APP_VERSION="1.0.0"
# 🧠 AI Configuration
VITE_AI_MODEL=${aiModel}
VITE_MAX_QUESTIONS=${maxQuestions}
VITE_AI_TEMPERATURE=${temperature}
# 📁 File Configuration
VITE_MAX_FILE_SIZE=${maxFileSize}
VITE_MAX_PDF_PAGES=${maxPdfPages}
# 🔍 Debug Configuration
VITE_DEBUG_MODE=${debugMode}
VITE_DEBUG_API=${debugApi}
# 🚀 Production Configuration
VITE_BASE_URL=http://localhost:3000
VITE_ENABLE_ANALYTICS=false
# 💰 MercadoPago Configuration
# Obtén tu access token desde: https://www.mercadopago.com.ar/developers/panel
# Public Key (para el frontend)
VITE_MERCADOPAGO_PUBLIC_KEY=${mpPublicKey || "tu-public-key-de-mercadopago"}
# Access Token (para el backend - MANTENER SECRETO)
MERCADOPAGO_ACCESS_TOKEN=${mpAccessToken || "tu-access-token-de-mercadopago"}
# Configuración de pagos
VITE_MERCADOPAGO_ENVIRONMENT=${mpEnvironment}
# Valores posibles: "sandbox" (pruebas) o "production" (producción)
# ==================================================
# ✅ Configuración completada en: ${new Date().toISOString()}
# ==================================================
`;
// Escribir archivo .env
fs.writeFileSync(".env", envContent);
console.log(`
✅ ¡CONFIGURACIÓN COMPLETADA!
===============================
📁 Se ha creado el archivo .env con tu configuración.
🚀 SIGUIENTES PASOS:
1. Ejecuta: npm run dev
2. Ve a http://localhost:3000
3. ¡Comienza a crear cuestionarios!
💰 MERCADOPAGO (OPCIONAL):
${mpPublicKey ? "✅ Public Key configurado" : "⚠️ Public Key no configurado"}
${
mpAccessToken
? "✅ Access Token configurado"
: "⚠️ Access Token no configurado"
}
- Para activar pagos, configura tus credenciales de MercadoPago
- Consulta MERCADOPAGO_SETUP.md para más información
⚠️ IMPORTANTE:
- El archivo .env NO se subirá a GitHub (está en .gitignore)
- Si necesitas cambiar algo, edita el archivo .env directamente
- Para recrear la configuración, ejecuta: npm run setup
- NUNCA compartas tu Access Token de MercadoPago
🎉 ¡Disfruta usando Preguntitas y empieza a generar ingresos!
`);
} catch (error) {
console.error("❌ Error durante la configuración:", error.message);
} finally {
rl.close();
}
}
// Verificar si ya existe .env
if (fs.existsSync(".env")) {
console.log(`
⚠️ ARCHIVO .env YA EXISTE
==========================
Ya tienes un archivo .env configurado.
🆕 NOVEDAD: Este script ahora incluye configuración de MercadoPago!
Si quieres agregar pagos a tu app, considera sobrescribir.
`);
rl.question(
"¿Quieres sobrescribirlo para incluir MercadoPago? [y/N]: ",
(answer) => {
if (answer.toLowerCase() === "y" || answer.toLowerCase() === "yes") {
setupEnvironment();
} else {
console.log("\n✅ Manteniendo configuración actual.");
console.log("💡 Para configurar MercadoPago manualmente:");
console.log(" 1. Consulta el archivo env.example");
console.log(" 2. Lee MERCADOPAGO_SETUP.md");
console.log(
" 3. Agrega las variables VITE_MERCADOPAGO_* a tu .env\n"
);
rl.close();
}
}
);
} else {
setupEnvironment();
}