# Development Workflow Setup

Quick setup guide to get the Laravel development workflow with code quality tools running on your machine.

## 📋 Prerequisites

Before starting, ensure you have:

- **PHP 8.1+** with Composer installed
- **Node.js 16+** with npm installed  
- **Git** configured on your machine
- **Laravel project** already cloned/downloaded

## 🚀 Quick Setup (5 minutes)

### Step 1: Install Dependencies
Make sure your project has these files already created/copied 
```
.husky/commit-msg 
.husky/pre-commit 
.husky/pre-push 
commands/pre-commit 
commands/pre-push 
.editorconfig
.eslintignore
.eslintrc.js
•gitignore
•prettierignore 
.prettierrc 
commitlint.config.cjs
DEVELOPMENT-WORKFLOW.md 
package-lock.json 
package.json
pint.json
SETUP.md
```

Make sure you have `laravle/plnt` exist in `composer.json`, if not exist run this command

```bash
composer require laravel/pint --dev
```
Check package.json for `husky`, `lint-staged prettier`, `eslint`, `eslint-plugin-vue@next`, `eslint-config-airbnb-base`, `@commitlint/{cli,config-conventional}`, if not exist then run these commands selectively

```bash
npm install --save-dev husky lint-staged prettier
npm install --save-dev eslint eslint-plugin-vue@next
npx install-peerdeps --dev eslint-config-airbnb-base
npm install --save-dev @commitlint/{cli,config-conventional}
```

Run these commands to make sure all dependencies in PHP, Node.js are installed

```bash
# Install PHP dependencies (Laravel Pint is already included)
composer install

# Install Node.js dependencies (ESLint, Prettier, Husky, etc.)
npm install
```

### Step 2: Initialize Git Hooks

```bash
# Setup Husky git hooks
npx husky init
```

### Step 3: Verify Installation

```bash
# Check if hooks are installed
ls -la .husky/

# Should show:
# pre-commit
# pre-push  
# commit-msg
```

## ✅ Test Your Setup

### Test PHP Formatting

```bash
# Check PHP code style (dry run)
npm run pint:check

# Fix PHP code style
npm run pint
```

### Test JavaScript Linting

```bash
# Check JavaScript files
npm run lint:check

# Fix JavaScript files  
npm run lint
```

### Test Git Hooks

```bash
# Create a test branch (any name works now)
git checkout -b test-setup

# Try to commit (hooks will run automatically)
git add .
git commit -m "feat: test development workflow setup"

# If successful, you'll see:
# ✅ Running pre-commit checks...
# ✅ Branch name 'test-setup' is valid
# ✅ Pre-commit checks passed!
# ✅ [lint-staged output]
```

## 🎯 What You Should See

### ✅ Successful Hook Run
```bash
✅ Running pre-commit checks...
✅ Branch name 'test-setup' is valid  
✅ Pre-commit checks passed!
✅ Running lint-staged...
✅ Laravel Pint formatting files...
✅ ESLint checking files...
✅ Prettier formatting files...
✅ Commit successful!
```

### ✅ What You'll See Now
All branches are allowed, so you won't see branch-related errors anymore!

## 🛠️ Available Commands

After setup, you can use these commands:

```bash
# PHP (Laravel Pint)
npm run pint           # Fix PHP code style
npm run pint:check     # Check PHP code style (dry run)

# JavaScript (ESLint + Prettier)  
npm run lint           # Fix JavaScript issues
npm run lint:check     # Check JavaScript (dry run)
npm run format         # Format with Prettier
npm run format:check   # Check Prettier formatting

# Git Hooks
npx husky init        # Reinstall git hooks
```

## 🎯 Branch Naming (Optional)

For better organization, consider using this pattern:
```
type/description-with-hyphens
```

**Suggested examples:**
- `feature/user-authentication`
- `fix/login-validation-bug`  
- `chore/update-dependencies`
- `docs/setup-instructions`

> **Note**: Branch naming is now optional - you can use any branch name you prefer.

## 🆘 Troubleshooting

### Git Hooks Not Running

```bash
# Reinstall hooks
rm -rf .husky
npx husky init
chmod +x .husky/pre-commit .husky/pre-push .husky/commit-msg
```

### "Command not found" Errors

```bash
# Make sure dependencies are installed
npm install
composer install

# Make sure hooks are executable
chmod +x .husky/pre-commit .husky/pre-push .husky/commit-msg
chmod +x commands/pre-commit commands/pre-push
```

### PHP Pint Issues

```bash
# Check if vendor/bin/pint exists
ls -la vendor/bin/pint

# If missing, reinstall Laravel Pint
composer require laravel/pint --dev
```

### ESLint Issues

```bash
# Check ESLint configuration
npx eslint --print-config resources/js/app.js

# Reinstall if needed
npm install eslint eslint-config-airbnb-base eslint-plugin-import --save-dev
```

### Commitlint Issues

```bash
# If you see module loading errors, ensure commitlint.config.cjs exists
ls -la commitlint.config.cjs

# Reinstall commitlint if needed
npm install @commitlint/cli @commitlint/config-conventional --save-dev
```

## 🎯 Branch Freedom

You can now **commit and push directly** to any branch including:
- `main`
- `master`
- `develop` 
- `staging`
- `production`

> **Note**: While direct commits are allowed, consider using feature branches for better collaboration.

## ✋ Emergency Bypass

**Only use in emergencies:**
```bash
git commit --no-verify -m "emergency fix"
git push --no-verify
```

⚠️ **Warning**: This bypasses all quality checks!

## 📚 Next Steps

After successful setup:

1. **Read the full guide**: Check `DEVELOPMENT-WORKFLOW.md` for detailed workflow information
2. **Create your first feature branch**: `git checkout -b feature/your-feature-name`
3. **Make some changes** and test the commit process
4. **Share with your team**: Have them follow this same setup process

## 🎉 Setup Complete!

Your development workflow is now active! Every commit will automatically:

- ✅ Validate branch names
- ✅ Format PHP code with Laravel Pint
- ✅ Lint JavaScript with ESLint  
- ✅ Format code with Prettier
- ✅ Validate commit messages

**Happy coding with consistent, high-quality code!** 🚀 


**Commit Conventional Message**
git commit -m "feat: add new user registration page"
git commit -m "fix: prevent crash when phone number is null"
git commit -m "docs: update API authentication section"
git commit -m "style: format all blade files using pint"
git commit -m "refactor: split dashboard logic into service class"
git commit -m "perf: cache subscription query for better speed"
git commit -m "test: add test case for profile update API"
git commit -m "build: bump Laravel version to 11"
git commit -m "ci: add GitHub action for running tests"
git commit -m "chore: remove unused images from public folder"
git commit -m "revert: fix login flow regression"
