Skip to content

Instantly share code, notes, and snippets.

@alamenai
Created August 14, 2023 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamenai/08c96b685117e177264264d27ea43a22 to your computer and use it in GitHub Desktop.
Save alamenai/08c96b685117e177264264d27ea43a22 to your computer and use it in GitHub Desktop.
Husky scripts example
#!/bin/sh
# This hook enforces that commit messages start with a capitalized verb.
# ANSI color codes for formatting
RED='\033[0;31m'
NC='\033[0m' # No Color
commit_msg="$1"
error_msg="${RED}error: Commit message must start with a capitalized verb${NC}"
# Use regex to check if the message starts with a capitalized verb
if ! grep -qE "^[A-Z][a-z]+ " "$commit_msg"; then
echo "$error_msg" >&2
exit 1
fi
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Run linting and lint-staged checks
npm run lint && npx lint-staged
# Run Cypress tests without opening the launchpad
npm run cypress-run-component
#!/bin/sh
# This hook prevents pushing if the build fails.
# ANSI color codes for formatting
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Run your build command (replace with your actual build command)
build_command= npm run build
if ! $build_command; then
echo "${RED}error: Build failed. Fix the build issues before pushing.${NC}" >&2
exit 1
else
echo -e "${GREEN}Build succeeded. Processing and Pushing...${NC}" >&2
echo # This line adds an empty line
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment