@icarusmx/creta 1.4.5 → 1.4.6
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.
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Bash Scripts - Automatización con scripts de shell
|
|
2
|
+
export const BASH_SCRIPTS = {
|
|
3
|
+
id: 'bash-scripts',
|
|
4
|
+
|
|
5
|
+
intro: {
|
|
6
|
+
definition: 'Un script es una secuencia de comandos guardados en un archivo que se pueden ejecutar como un programa.',
|
|
7
|
+
explanation: 'Los bash scripts te permiten automatizar tareas repetitivas y crear herramientas personalizadas.',
|
|
8
|
+
detail: 'Comenzaremos con "Salgamos de este laberinto." y terminaremos construyendo un script de deployment automático.'
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
steps: [
|
|
12
|
+
{
|
|
13
|
+
type: 'command-intro',
|
|
14
|
+
command: 'echo',
|
|
15
|
+
description: 'Primer concepto: echo',
|
|
16
|
+
explanation: 'echo imprime texto en la terminal.',
|
|
17
|
+
example: 'echo "Salgamos de este laberinto."',
|
|
18
|
+
instruction: 'Este es el comando más simple. Pruébalo en tu terminal.'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: 'command-intro',
|
|
22
|
+
command: '#!/bin/bash',
|
|
23
|
+
description: 'El shebang',
|
|
24
|
+
explanation: 'La primera línea de un script debe indicar qué intérprete usar.',
|
|
25
|
+
example: '#!/bin/bash\necho "Salgamos de este laberinto."',
|
|
26
|
+
instruction: 'Siempre comienza tus scripts con #!/bin/bash en la primera línea.'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'command-intro',
|
|
30
|
+
command: 'nano script.sh',
|
|
31
|
+
description: 'Crear un archivo de script',
|
|
32
|
+
explanation: 'Usa cualquier editor de texto para crear archivos .sh',
|
|
33
|
+
example: 'nano deploy.sh\n# O usa: code deploy.sh',
|
|
34
|
+
instruction: 'Los scripts son archivos de texto. La extensión .sh es convencional para bash scripts.'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'command-intro',
|
|
38
|
+
command: 'chmod +x',
|
|
39
|
+
description: 'Hacer ejecutable un script',
|
|
40
|
+
explanation: 'chmod +x le da permisos de ejecución a un archivo.',
|
|
41
|
+
example: 'chmod +x deploy.sh\n./deploy.sh',
|
|
42
|
+
instruction: 'Después de chmod +x puedes ejecutar el script con ./nombre-script.sh'
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'command-intro',
|
|
46
|
+
command: 'VARIABLE="valor"',
|
|
47
|
+
description: 'Variables en bash',
|
|
48
|
+
explanation: 'Puedes guardar valores en variables para reutilizarlos.',
|
|
49
|
+
example: 'MENSAJE="Salgamos de este laberinto."\necho $MENSAJE',
|
|
50
|
+
instruction: 'Define con NOMBRE="valor" y usa con $NOMBRE. Sin espacios alrededor del ='
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'command-intro',
|
|
54
|
+
command: '$(comando)',
|
|
55
|
+
description: 'Sustitución de comandos',
|
|
56
|
+
explanation: 'Puedes guardar la salida de un comando en una variable.',
|
|
57
|
+
example: 'VERSION=$(node -p "require(\'./package.json\').version")\necho "Versión actual: $VERSION"',
|
|
58
|
+
instruction: 'Todo lo que esté dentro de $() se ejecuta y su resultado se guarda.'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'command-intro',
|
|
62
|
+
command: 'IFS',
|
|
63
|
+
description: 'Dividir strings (Internal Field Separator)',
|
|
64
|
+
explanation: 'IFS te permite dividir un string en partes usando un delimitador.',
|
|
65
|
+
example: 'VERSION="1.2.3"\nIFS=\'.\' read -r -a PARTS <<< "$VERSION"\necho ${PARTS[2]} # imprime: 3',
|
|
66
|
+
instruction: 'Muy útil para manipular versiones semánticas (major.minor.patch).'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'command-intro',
|
|
70
|
+
command: '$((expresión))',
|
|
71
|
+
description: 'Aritmética en bash',
|
|
72
|
+
explanation: 'Usa $(( )) para hacer operaciones matemáticas.',
|
|
73
|
+
example: 'PATCH=3\nNEW_PATCH=$((PATCH + 1))\necho $NEW_PATCH # imprime: 4',
|
|
74
|
+
instruction: 'Funciona para sumar, restar, multiplicar y dividir números enteros.'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
type: 'command-intro',
|
|
78
|
+
command: 'sed',
|
|
79
|
+
description: 'Reemplazar texto en archivos',
|
|
80
|
+
explanation: 'sed permite buscar y reemplazar texto dentro de archivos.',
|
|
81
|
+
example: 'sed -i \'\' "s/viejo/nuevo/" archivo.txt',
|
|
82
|
+
instruction: 'En macOS usa -i \'\'. En Linux solo -i. Formato: s/buscar/reemplazar/'
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: 'command-intro',
|
|
86
|
+
command: 'if [ $? -eq 0 ]',
|
|
87
|
+
description: 'Condicionales y códigos de salida',
|
|
88
|
+
explanation: '$? contiene el código de salida del último comando. 0 significa éxito.',
|
|
89
|
+
example: 'npm publish\nif [ $? -eq 0 ]; then\n echo "✅ Éxito"\nelse\n echo "❌ Error"\nfi',
|
|
90
|
+
instruction: 'Usa if/then/else/fi para tomar decisiones basadas en resultados.'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: 'code',
|
|
94
|
+
title: 'Script completo: deploy-patch.sh',
|
|
95
|
+
code: `#!/bin/bash
|
|
96
|
+
|
|
97
|
+
# Obtener versión actual del package.json
|
|
98
|
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
99
|
+
|
|
100
|
+
# Dividir la versión en partes (major.minor.patch)
|
|
101
|
+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
|
|
102
|
+
MAJOR="\${VERSION_PARTS[0]}"
|
|
103
|
+
MINOR="\${VERSION_PARTS[1]}"
|
|
104
|
+
PATCH="\${VERSION_PARTS[2]}"
|
|
105
|
+
|
|
106
|
+
# Incrementar el número de patch
|
|
107
|
+
NEW_PATCH=$((PATCH + 1))
|
|
108
|
+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
|
|
109
|
+
|
|
110
|
+
echo "📦 Bumping version: $CURRENT_VERSION → $NEW_VERSION"
|
|
111
|
+
|
|
112
|
+
# Actualizar package.json con la nueva versión
|
|
113
|
+
sed -i '' "s/\\"version\\": \\"$CURRENT_VERSION\\"/\\"version\\": \\"$NEW_NEW\\"/" package.json
|
|
114
|
+
|
|
115
|
+
echo "🚀 Publishing to npm..."
|
|
116
|
+
npm publish
|
|
117
|
+
|
|
118
|
+
# Verificar si el publish fue exitoso
|
|
119
|
+
if [ $? -eq 0 ]; then
|
|
120
|
+
echo "✅ Successfully published @icarusmx/creta@$NEW_VERSION"
|
|
121
|
+
else
|
|
122
|
+
echo "❌ Publish failed, reverting version..."
|
|
123
|
+
sed -i '' "s/\\"version\\": \\"$NEW_VERSION\\"/\\"version\\": \\"$CURRENT_VERSION\\"/" package.json
|
|
124
|
+
exit 1
|
|
125
|
+
fi`,
|
|
126
|
+
after: [
|
|
127
|
+
'',
|
|
128
|
+
'Este script automatiza:',
|
|
129
|
+
'1. Leer la versión actual',
|
|
130
|
+
'2. Incrementar el patch',
|
|
131
|
+
'3. Actualizar package.json',
|
|
132
|
+
'4. Publicar a npm',
|
|
133
|
+
'5. Revertir si falla'
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'maze-completion',
|
|
138
|
+
message: 'Bash Scripts completado! Ya puedes automatizar tareas.',
|
|
139
|
+
unlocked: 'Ahora puedes crear tus propias herramientas de automatización.'
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
package/lib/data/menus.js
CHANGED
|
@@ -7,7 +7,8 @@ export const SINTAXIS_MENU_CONFIG = {
|
|
|
7
7
|
description: 'Aprende los comandos fundamentales de terminal y git.',
|
|
8
8
|
options: [
|
|
9
9
|
{ id: 'terminal-basico', title: '1. Terminal básico', description: 'ls, cd, mkdir' },
|
|
10
|
-
{ id: 'git-basico', title: '2. Git básico', description: 'init, status, add, commit' }
|
|
10
|
+
{ id: 'git-basico', title: '2. Git básico', description: 'init, status, add, commit' },
|
|
11
|
+
{ id: 'bash-scripts', title: '3. Bash Scripts', description: 'variables, sed, condicionales' }
|
|
11
12
|
]
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -3,6 +3,7 @@ import { SINTAXIS_MENU_CONFIG } from '../data/menus.js'
|
|
|
3
3
|
import { LessonBuilder } from '../builders/LessonBuilder.js'
|
|
4
4
|
import { TERMINAL_BASICO } from '../data/lessons/sintaxis/terminal-basico.js'
|
|
5
5
|
import { GIT_BASICO } from '../data/lessons/sintaxis/git-basico.js'
|
|
6
|
+
import { BASH_SCRIPTS } from '../data/lessons/sintaxis/bash-scripts.js'
|
|
6
7
|
import { clearConsole } from '../utils/output.js'
|
|
7
8
|
import { createPromptInterface } from '../utils/input.js'
|
|
8
9
|
import { UserState } from '../utils/user-state.js'
|
|
@@ -10,7 +11,8 @@ import { UNLOCK_CONFIG } from '../data/progression.js'
|
|
|
10
11
|
|
|
11
12
|
const LESSONS_BY_ID = new Map([
|
|
12
13
|
['terminal-basico', TERMINAL_BASICO],
|
|
13
|
-
['git-basico', GIT_BASICO]
|
|
14
|
+
['git-basico', GIT_BASICO],
|
|
15
|
+
['bash-scripts', BASH_SCRIPTS]
|
|
14
16
|
])
|
|
15
17
|
|
|
16
18
|
function waitForEnter(message = '\nPresiona Enter para continuar...') {
|