### 1. Verify Netlify CLI Authentication
Check if the user is logged into Netlify:
```bash
npx netlify status
```
**Expected output patterns**:
✅ Authenticated: Shows logged-in user email and site link status
❌ Not authenticated: "Not logged into any site" or authentication error
**If not authenticated**, guide the user:
```bash
npx netlify login
```
This opens a browser window for OAuth authentication. Wait for user to complete login, then verify with `netlify status` again.
**Alternative: API Key authentication**
If browser authentication isn't available, users can set:
```bash
export NETLIFY_AUTH_TOKEN=your_token_here
```
Tokens can be generated at: https://app.netlify.com/user/applications#personal-access-tokens
### 2. Detect Site Link Status
From `netlify status` output, determine:
**Linked**: Site already connected to Netlify (shows site name/URL)
**Not linked**: Need to link or create site
### 3. Link to Existing Site or Create New
**If already linked** → Skip to step 4
**If not linked**, attempt to link by Git remote:
```bash
# Check if project is Git-based
git remote show origin
# If Git-based, extract remote URL
# Format: https://github.com/username/repo or git@github.com:username/repo.git
# Try to link by Git remote
npx netlify link --git-remote-url <REMOTE_URL>
```
**If link fails** (site doesn't exist on Netlify):
```bash
# Create new site interactively
npx netlify init
```
This guides user through:
1. Choosing team/account
2. Setting site name
3. Configuring build settings
4. Creating netlify.toml if needed
### 4. Verify Dependencies
Before deploying, ensure project dependencies are installed:
```bash
# For npm projects
npm install
# For other package managers, detect and use appropriate command
# yarn install, pnpm install, etc.
```
### 5. Deploy to Netlify
Choose deployment type based on context:
**Preview/Draft Deploy** (default for existing sites):
```bash
npx netlify deploy
```
This creates a deploy preview with a unique URL for testing.
**Production Deploy** (for new sites or explicit production deployments):
```bash
npx netlify deploy --prod
```
This deploys to the live production URL.
**Deployment process**:
1. CLI detects build settings (from netlify.toml or prompts user)
2. Builds the project locally
3. Uploads built assets to Netlify
4. Returns deployment URL
### 6. Report Results
After deployment, report to user:
**Deploy URL**: Unique URL for this deployment
**Site URL**: Production URL (if production deploy)
**Deploy logs**: Link to Netlify dashboard for logs
**Next steps**: Suggest `netlify open` to view site or dashboard