# CLI Commands

## fluxlay login

Authenticate with your Fluxlay account via device authorization.

```bash
fluxlay login
```

Opens a browser window for sign-in. Displays a user code for verification. The session is saved locally after approval.

## fluxlay logout

Remove the saved session.

```bash
fluxlay logout
```

## fluxlay whoami

Display the currently authenticated user.

```bash
fluxlay whoami
```

## fluxlay dev

Start a development server for live wallpaper preview.

```bash
fluxlay dev [dir]
```

| Argument | Description       | Default                 |
| -------- | ----------------- | ----------------------- |
| `dir`    | Project directory | `.` (current directory) |

**Behavior:**

1. Validates `fluxlay.yaml`.
2. Finds an available port starting from 3000.
3. Starts a Vite dev server.
4. Writes `dev.json` to the app data directory.
5. The desktop app detects the dev server and renders with HMR.

## fluxlay build

Build the wallpaper into an encrypted `.fluxlay` package.

```bash
fluxlay build [dir] [-o <name>]
```

| Argument / Option     | Description       | Default             |
| --------------------- | ----------------- | ------------------- |
| `dir`                 | Project directory | `.`                 |
| `-o, --output <name>` | Output file name  | `wallpaper.fluxlay` |

**Requires:** Active login session and a `kind` field in `fluxlay.yaml`.

Behavior branches by `kind`:

- `kind: web` → Runs Vite build and packages `dist/`.
- `kind: video` / `kind: image` → Packages the single media file specified by `source`.

## fluxlay publish

Build and publish the wallpaper to the Fluxlay store.

```bash
fluxlay publish [dir]
```

| Argument | Description       | Default |
| -------- | ----------------- | ------- |
| `dir`    | Project directory | `.`     |

**Requires:** Active login session, completed onboarding.

**Behavior:**

1. Validates `fluxlay.yaml` (the `kind` field is required).
2. Generates a content encryption key.
3. Registers the version with the API.
4. Builds the bundle based on `kind`:
   - `web`: Packages the Vite build output (`dist/`).
   - `video` / `image`: Packages the media file specified by `source` as `media.<ext>` (Vite build is skipped).
5. Encrypts and uploads.
6. Confirms with the API.

For `kind: video` / `kind: image` wallpapers, HTML is not bundled — the desktop app generates it dynamically at delivery time.
