# Automated Frontend Deployment

Stop manually uploading files! Use these scripts instead.

---

## Option 1: Semi-Automatic (Recommended)

**Script:** `deploy-frontend.bat`

This script:
1. Cleans old build
2. Runs `npm run build`
3. Creates a ZIP file: `frontend-deploy.zip`
4. Opens the folder for you

**How to use:**
1. Double-click `deploy-frontend.bat`
2. Wait for build to complete
3. Upload `frontend-deploy.zip` to cPanel
4. Extract in `public_html/frontend/`

**Pros:** Safe, you control the upload
**Cons:** Still need to manually upload the ZIP

---

## Option 2: Fully Automatic (FTP)

**Script:** `deploy-frontend-auto.bat`

This script does everything automatically via FTP!

### Setup (One Time Only):

1. Right-click `deploy-frontend-auto.bat` → **Edit**
2. Update these lines (around line 11-14):

```batch
set FTP_HOST=ftp.herataria.nova.af
set FTP_USER=your_cpanel_username
set FTP_PASS=your_cpanel_password
set FTP_REMOTE_PATH=/public_html/frontend
```

3. Save and close

### Usage:

Just double-click `deploy-frontend-auto.bat`!

It will:
1. ✅ Clean old build
2. ✅ Run `npm run build`
3. ✅ Upload files via FTP
4. ✅ Deploy to server

Done in one click! 🎉

---

## Option 3: Git Deployment (Professional)

For the most professional setup, use Git + GitHub Actions:

### Step 1: Create GitHub Repository

1. Create a new private repository on GitHub
2. Push your code:

```bash
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/yourusername/aria-herat-erp.git
git push -u origin main
```

### Step 2: Setup Server

In cPanel Terminal or SSH:

```bash
cd /home/sahelshi
git clone https://github.com/yourusername/aria-herat-erp.git repo
```

### Step 3: Create Deployment Script on Server

Create file: `/home/sahelshi/deploy.sh`

```bash
#!/bin/bash
cd /home/sahelshi/repo
git pull origin main
cd frontend
npm install
npm run build
rm -rf /home/sahelshi/public_html/frontend/*
cp -r dist/spa/* /home/sahelshi/public_html/frontend/
echo "Frontend deployed!"
```

Make it executable:
```bash
chmod +x /home/sahelshi/deploy.sh
```

### Step 4: Deploy

Whenever you make changes:

```bash
git add .
git commit -m "Update frontend"
git push
```

Then on server (via SSH):
```bash
/home/sahelshi/deploy.sh
```

---

## Option 4: Rsync (Fast Sync)

If you have SSH access, use rsync for fast uploads:

**Script:** `deploy-rsync.bat`

```batch
@echo off
cd frontend
rmdir /s /q dist
npm run build
rsync -avz --delete dist/spa/ sahelshi@herataria.nova.af:/home/sahelshi/public_html/frontend/
echo Done!
pause
```

**Requirements:** 
- Install rsync on Windows: https://www.itefix.net/cwrsync
- Setup SSH key authentication

**Pros:** Very fast, only uploads changed files
**Cons:** Requires SSH setup

---

## Comparison

| Method | Speed | Difficulty | Automation |
|--------|-------|------------|------------|
| Manual Upload | Slow | Easy | ❌ None |
| deploy-frontend.bat | Medium | Easy | 🟡 Semi |
| deploy-frontend-auto.bat | Fast | Easy | ✅ Full |
| Git Deployment | Fast | Medium | ✅ Full |
| Rsync | Very Fast | Hard | ✅ Full |

---

## Recommendation

**For you:** Start with `deploy-frontend.bat` (semi-automatic)

Once comfortable, move to `deploy-frontend-auto.bat` (fully automatic)

---

## Quick Start

1. Double-click `deploy-frontend.bat`
2. Wait for ZIP to be created
3. Upload to cPanel
4. Extract
5. Done!

No more manual file selection! 🚀

---

## Troubleshooting

### Build fails
- Check Node.js is installed
- Run `npm install` in frontend folder
- Check for errors in console

### FTP fails (auto script)
- Verify FTP credentials
- Check FTP_HOST is correct
- Try FTP in FileZilla first to test

### Files not updating
- Clear browser cache (Ctrl+Shift+Delete)
- Check files were actually uploaded
- Verify you're in the right directory

---

## Future: CI/CD Pipeline

For ultimate automation, set up GitHub Actions:

1. Push code to GitHub
2. GitHub automatically builds
3. GitHub automatically deploys to server
4. Zero manual work!

Let me know if you want help setting this up!
