Initial commit: Complete NodeJS-native setup

- Migrated from Python pre-commit to NodeJS-native solution
- Reorganized documentation structure
- Set up Husky + lint-staged for efficient pre-commit hooks
- Fixed Dockerfile healthcheck issue
- Added comprehensive documentation index
This commit is contained in:
William Valentin
2025-09-06 01:42:48 -07:00
commit e48adbcb00
159 changed files with 24405 additions and 0 deletions

133
scripts/setup-pre-commit.sh Executable file
View File

@@ -0,0 +1,133 @@
# Run lint-staged for file-specific checks
bunx lint-staged
# Run type checking (doesn't need file filtering)
bun run type-check
# Check for large files (similar to pre-commit check-added-large-files)
git diff --cached --name-only | while IFS= read -r file; do
if [ -f "$file" ]; then
size=$(stat -c%s "$file" 2>/dev/null || stat -f%z "$file" 2>/dev/null || echo 0)
if [ "$size" -gt 500000 ]; then # 500KB limit
echo "Error: Large file detected: $file ($(echo $size | awk '{print int($1/1024)}')KB)"
echo "Consider using Git LFS for large files."
exit 1
fi
fi
done
# Check for merge conflict markers
if git diff --cached | grep -E "^[<>=]{7}" >/dev/null; then
echo "Error: Merge conflict markers detected"
exit 1
fi
# Check for private keys (basic check)
if git diff --cached --name-only | xargs grep -l "BEGIN.*PRIVATE KEY" 2>/dev/null; then
echo "Error: Private key detected in staged files"
exit 1
fi
echo "✅ Pre-commit checks passed!"
NC='\033[0m' # No Color
echo -e "${GREEN}Setting up NodeJS-native pre-commit hooks and code formatters...${NC}"
# Check if we're in a git repository
if [ ! -d ".git" ]; then
echo -e "${RED}Error: Not a git repository. Please run this script from the project root.${NC}"
exit 1
fi
# Install dependencies
echo -e "${YELLOW}Installing dependencies...${NC}"
if command -v bun &> /dev/null; then
bun install
elif command -v npm &> /dev/null; then
npm install
else
echo -e "${RED}Error: Neither bun nor npm found. Please install one of them first.${NC}"
exit 1
fi
# Initialize Husky (NodeJS-native git hooks)
echo -e "${YELLOW}Setting up Husky git hooks...${NC}"
if command -v bun &> /dev/null; then
bunx husky init
elif command -v npm &> /dev/null; then
npx husky init
fi
# Make pre-commit hook executable
chmod +x .husky/pre-commit
# Run initial formatting
echo -e "${YELLOW}Running initial code formatting...${NC}"
if command -v bun &> /dev/null; then
bun run format
elif command -v npm &> /dev/null; then
npm run format
fi
# Run initial linting
echo -e "${YELLOW}Running initial linting...${NC}"
if command -v bun &> /dev/null; then
bun run lint:fix
elif command -v npm &> /dev/null; then
npm run lint:fix
fi
# Run initial markdown linting
echo -e "${YELLOW}Running initial markdown linting...${NC}"
if command -v bun &> /dev/null; then
bun run lint:markdown:fix || echo "Markdown linting completed with warnings"
elif command -v npm &> /dev/null; then
npm run lint:markdown:fix || echo "Markdown linting completed with warnings"
fi
# Fix EditorConfig issues
echo -e "${YELLOW}Fixing EditorConfig issues...${NC}"
if command -v bun &> /dev/null; then
bun run fix:editorconfig || echo "EditorConfig fixes completed"
elif command -v npm &> /dev/null; then
npm run fix:editorconfig || echo "EditorConfig fixes completed"
fi
echo -e "${GREEN}✅ NodeJS-native pre-commit hooks and code formatters have been set up successfully!${NC}"
echo ""
echo -e "${YELLOW}What was configured:${NC}"
echo " ✓ Husky git hooks (.husky/pre-commit)"
echo " ✓ Prettier code formatter (.prettierrc)"
echo " ✓ ESLint configuration (eslint.config.cjs)"
echo " ✓ EditorConfig (.editorconfig)"
echo " ✓ Markdownlint configuration (.markdownlint.json)"
echo " ✓ Secretlint configuration (.secretlintrc.json)"
echo " ✓ Lint-staged for efficient pre-commit formatting"
echo " ✓ Dockerfilelint for Docker file validation"
echo ""
echo -e "${YELLOW}Available commands:${NC}"
echo " • bun run format - Format all files with Prettier"
echo " • bun run lint - Run ESLint on TypeScript/JavaScript files"
echo " • bun run lint:fix - Run ESLint with auto-fix"
echo " • bun run lint:markdown - Check Markdown files"
echo " • bun run lint:markdown:fix - Fix Markdown files"
echo " • bun run lint:docker - Check Dockerfile"
echo " • bun run check:secrets - Check for secrets in files"
echo " • bun run check:editorconfig - Check EditorConfig compliance"
echo " • bun run fix:editorconfig - Fix EditorConfig issues"
echo " • bun run type-check - Run TypeScript type checking"
echo ""
echo -e "${YELLOW}What happens on commit:${NC}"
echo " 1. Lint-staged runs on changed files:"
echo " • ESLint auto-fix + Prettier formatting for JS/TS files"
echo " • Prettier formatting for JSON/YAML/MD/CSS files"
echo " • Markdownlint auto-fix for Markdown files"
echo " • Dockerfilelint for Dockerfile"
echo " • EditorConfig fixes for all files"
echo " 2. TypeScript type checking on entire project"
echo " 3. Large file detection (>500KB)"
echo " 4. Merge conflict marker detection"
echo " 5. Basic private key detection"
echo ""
echo -e "${GREEN}All commits will now be automatically checked and formatted! 🎉${NC}"
echo -e "${GREEN}This setup is 100% NodeJS-native - no Python dependencies required! 🚀${NC}"