@icarusmx/creta 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/creta.js +88 -4
- package/package.json +1 -1
package/bin/creta.js
CHANGED
|
@@ -15,15 +15,23 @@ console.log("Retomemos desde donde nos quedamos: hagamos tu portafolio.\n")
|
|
|
15
15
|
if (!command) {
|
|
16
16
|
console.log("Comandos disponibles:")
|
|
17
17
|
console.log(" creta portafolio - Crea tu portafolio personal (reto completo)")
|
|
18
|
-
console.log(" creta portafolio-1 -
|
|
19
|
-
console.log(" creta portafolio-2 -
|
|
20
|
-
console.log(" creta portafolio-3 -
|
|
18
|
+
console.log(" creta portafolio-1 - Desbloquea nivel 1 (navbar) 🔓")
|
|
19
|
+
console.log(" creta portafolio-2 - Desbloquea nivel 2 (navbar + hero) 🔓")
|
|
20
|
+
console.log(" creta portafolio-3 - Desbloquea nivel 3 (solución completa) 🔓")
|
|
21
|
+
console.log("\n💡 Tip: Si estás dentro de un proyecto existente, los comandos")
|
|
22
|
+
console.log(" portafolio-1/2/3 actualizarán tus archivos directamente")
|
|
21
23
|
process.exit(0)
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
if (command.startsWith('portafolio')) {
|
|
25
27
|
const level = command === 'portafolio' ? 0 : parseInt(command.split('-')[1]) || 0
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
// Check if we're in an existing Creta project
|
|
30
|
+
if (level > 0 && isInCretaProject()) {
|
|
31
|
+
await unstuckProject(level)
|
|
32
|
+
} else {
|
|
33
|
+
await createPortfolioProject(level)
|
|
34
|
+
}
|
|
27
35
|
} else {
|
|
28
36
|
console.log(`Comando no reconocido: ${command}`)
|
|
29
37
|
process.exit(1)
|
|
@@ -221,3 +229,79 @@ function getLevelDescription(level) {
|
|
|
221
229
|
}
|
|
222
230
|
return descriptions[level] || 'nivel desconocido'
|
|
223
231
|
}
|
|
232
|
+
|
|
233
|
+
function isInCretaProject() {
|
|
234
|
+
// Check if we're in a Creta project by looking for key files
|
|
235
|
+
const currentDir = process.cwd()
|
|
236
|
+
const packageJsonPath = path.join(currentDir, 'package.json')
|
|
237
|
+
const layoutPath = path.join(currentDir, 'src/routes/+layout.svelte')
|
|
238
|
+
const pagePath = path.join(currentDir, 'src/routes/+page.svelte')
|
|
239
|
+
|
|
240
|
+
// Must have package.json and SvelteKit structure
|
|
241
|
+
if (!fs.existsSync(packageJsonPath) || !fs.existsSync(layoutPath) || !fs.existsSync(pagePath)) {
|
|
242
|
+
return false
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Check if layout contains Creta comments
|
|
246
|
+
try {
|
|
247
|
+
const layoutContent = fs.readFileSync(layoutPath, 'utf8')
|
|
248
|
+
return layoutContent.includes('RETO CRETA') || layoutContent.includes('🧭 RETO 1: NAVBAR')
|
|
249
|
+
} catch (error) {
|
|
250
|
+
return false
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function unstuckProject(level) {
|
|
255
|
+
console.log(`\n🔓 ¡Te ayudo a desbloquear el nivel ${level}!`)
|
|
256
|
+
console.log(`📚 Agregando código para: ${getLevelDescription(level)}`)
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
const currentDir = process.cwd()
|
|
260
|
+
const layoutPath = path.join(currentDir, 'src/routes/+layout.svelte')
|
|
261
|
+
const pagePath = path.join(currentDir, 'src/routes/+page.svelte')
|
|
262
|
+
|
|
263
|
+
// Get student name from package.json title if possible
|
|
264
|
+
let studentName = 'Tu nombre'
|
|
265
|
+
try {
|
|
266
|
+
const packageJsonPath = path.join(currentDir, 'package.json')
|
|
267
|
+
const packageContent = fs.readFileSync(packageJsonPath, 'utf8')
|
|
268
|
+
const packageJson = JSON.parse(packageContent)
|
|
269
|
+
if (packageJson.name && packageJson.name.includes('-portafolio')) {
|
|
270
|
+
studentName = packageJson.name.replace('-portafolio', '').split('-').map(word =>
|
|
271
|
+
word.charAt(0).toUpperCase() + word.slice(1)
|
|
272
|
+
).join(' ')
|
|
273
|
+
}
|
|
274
|
+
} catch (error) {
|
|
275
|
+
// Use default if can't parse
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Apply modifications to existing files
|
|
279
|
+
if (fs.existsSync(layoutPath)) {
|
|
280
|
+
let layoutContent = fs.readFileSync(layoutPath, 'utf8')
|
|
281
|
+
layoutContent = applyLayoutModifications(layoutContent, level)
|
|
282
|
+
// Replace placeholders in layout
|
|
283
|
+
layoutContent = layoutContent.replace(/\{\{STUDENT_NAME\}\}/g, studentName)
|
|
284
|
+
layoutContent = layoutContent.replace(/\{\{PROJECT_NAME\}\}/g, `${studentName.toLowerCase().replace(/\s+/g, '-')}-portafolio`)
|
|
285
|
+
fs.writeFileSync(layoutPath, layoutContent)
|
|
286
|
+
console.log(`✅ Actualizado: src/routes/+layout.svelte`)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (fs.existsSync(pagePath)) {
|
|
290
|
+
let pageContent = fs.readFileSync(pagePath, 'utf8')
|
|
291
|
+
pageContent = applyPageModifications(pageContent, level)
|
|
292
|
+
// Replace placeholders in page
|
|
293
|
+
pageContent = pageContent.replace(/\{\{STUDENT_NAME\}\}/g, studentName)
|
|
294
|
+
pageContent = pageContent.replace(/\{\{PROJECT_NAME\}\}/g, `${studentName.toLowerCase().replace(/\s+/g, '-')}-portafolio`)
|
|
295
|
+
fs.writeFileSync(pagePath, pageContent)
|
|
296
|
+
console.log(`✅ Actualizado: src/routes/+page.svelte`)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
console.log(`\n🎉 ¡Listo! Ahora tienes el código del nivel ${level}`)
|
|
300
|
+
console.log(`💡 Revisa los archivos actualizados para ver qué se agregó`)
|
|
301
|
+
console.log(`🚀 Continúa con: npm run dev`)
|
|
302
|
+
|
|
303
|
+
} catch (error) {
|
|
304
|
+
console.error('Error al actualizar el proyecto:', error.message)
|
|
305
|
+
process.exit(1)
|
|
306
|
+
}
|
|
307
|
+
}
|