Skip to content

Commit e4f289c

Browse files
authored
Merge pull request #33 from muke78/huskyScriptImprovement
refactor: Mejoramiento de flujos en scripts de husky
2 parents 78ace6c + 07f0324 commit e4f289c

4 files changed

Lines changed: 24 additions & 26 deletions

File tree

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ if ! echo "$commit_msg" | grep -Eq "$commit_regex"; then
3232
exit 1
3333
fi
3434

35-
echo "✅ Mensaje válido. ¡Buen trabajo! 🚀"
35+
echo "✅ Mensaje válido. ¡Buen trabajo! 🚀"

.husky/pre-commit

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#!/bin/sh
22

3-
echo "🔍 Verificando archivos antes del commit..."
4-
5-
# Formatear código con Prettier
6-
echo "🚀 Ejecutando Prettier..."
7-
if ! yarn prettier . --write; then
8-
echo "❌ Error al ejecutar Prettier."
9-
exit 1
10-
fi
3+
# Cargar NVM (necesario en entornos donde Husky no hereda el PATH completo)
4+
export NVM_DIR="$HOME/.nvm"
5+
# Esto carga nvm
6+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
7+
# Esto carga nvm para bash >=0.4.0
8+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
119

12-
# Agregar los archivos modificados después del formateo
13-
git add .
14-
15-
# Verificar que el código esté actualizado antes del push
16-
echo "🔄 Verificando que tu código esté actualizado..."
17-
if ! git pull; then
18-
echo "❌ Error al actualizar el código. Revisa los conflictos."
19-
exit 1
20-
fi
10+
echo "🔍 Verificando archivos antes del commit..."
11+
echo "📦 Formateando código con Prettier..."
2112

22-
echo "✅ Todo listo para el commit. 🎉"
13+
yarn prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write || exit 1

.husky/pre_push

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
#!/bin/sh
22

3-
Ejecutar pruebas con yarn
4-
echo "🧪 Ejecutando tests..."
5-
if ! yarn test; then
6-
echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
7-
exit 1
8-
fi
3+
BRANCH=$(git symbolic-ref --short HEAD)
4+
5+
if [ "$BRANCH" = "staging" ]; then
6+
echo "📍 Estás en la rama 'staging'. Ejecutando pruebas..."
7+
echo "🧪 Ejecutando tests..."
8+
9+
if ! npm test; then
10+
echo "❌ Tests fallaron. Corrige los errores antes de hacer commit."
11+
exit 1
12+
fi
13+
else
14+
echo "🚫 No estás en la rama 'staging'. No se ejecutan los tests."
15+
fi

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start": "node server.js",
88
"dev": "node --watch server.js",
9-
"format": "prettier . --write",
9+
"format": "prettier 'src/**/*.{js,ts,jsx,tsx,json}' server.js package.json --write",
1010
"prepare": "husky",
1111
"test": "jest",
1212
"test:watch": "jest --watchAll"

0 commit comments

Comments
 (0)