npm package: @reditui/cli
Description: Local development CLI for REditUI - receives generated source code from Redit
Latest version: 0.1.3

# @reditui/cli

Local development CLI for REditUI - receives generated source code sent from Redit (レヂツイ).

## Installation

You can use the CLI without installation using `npx`:

```bash
npx @reditui/cli bridge
```

Or install globally:

```bash
npm install -g @reditui/cli
reditui bridge
```

## Commands

### bridge

Start the Bridge service to receive generated source code.

```bash
npx @reditui/cli bridge
```

This will start an Express-based API server on port 4545 (by default) that listens for incoming source code. The Bridge service provides a bridge between the editor and your local development environment, with drop functionality as one of its core features.

**Options:**

- `--check`: Check configuration without starting the server

```bash
npx @reditui/cli bridge --check
```

## Configuration

Create a `bridge.config.json` file in your project root:

```json
{
  "port": 4545,
  "targetDir": "./src/inbox",
  "maxPayloadMB": 50,
  "auth": {
    "enabled": false,
    "token": ""
  },
  "cors": {
    "enabled": true,
    "origin": true,
    "credentials": false
  }
}
```

### Configuration Options

- **port** (number): Port number for the API server (default: 4545)
- **targetDir** (string): Directory where received files will be saved (default: "./src/inbox")
- **maxPayloadMB** (number): Maximum payload size in MB (default: 50)
- **auth** (object): Authentication configuration
  - **enabled** (boolean): Enable bearer token authentication
  - **token** (string): Bearer token for authentication
- **cors** (object): CORS (Cross-Origin Resource Sharing) configuration
  - **enabled** (boolean): Enable CORS (default: true)
  - **origin** (string | string[] | boolean): Allowed origins. Can be:
    - `true`: Allow all origins (default, most permissive)
    - `false`: Disable CORS
    - `"https://example.com"`: Allow a specific origin
    - `["https://example.com", "https://another.com"]`: Allow multiple specific origins
  - **credentials** (boolean): Allow credentials (cookies, authorization headers) (default: false)
- **postDropHook** (string): Path to a module that exports a post-drop hook function

### Environment Variables

You can override configuration using environment variables:

- `BRIDGE_PORT`: Override port number
- `BRIDGE_TARGET_DIR`: Override target directory
- `BRIDGE_MAX_PAYLOAD_MB`: Override max payload size
- `BRIDGE_AUTH_ENABLED`: Enable/disable authentication (true/false)
- `BRIDGE_AUTH_TOKEN`: Override authentication token
- `BRIDGE_CORS_ENABLED`: Enable/disable CORS (true/false)
- `BRIDGE_CORS_ORIGIN`: Override allowed origins (use "true", "false", a URL, or comma-separated URLs)
- `BRIDGE_CORS_CREDENTIALS`: Allow credentials (true/false)

## API Endpoints

### POST /drop

Receive and extract a ZIP file containing source code (drop functionality).

**Request Body:**

```json
{
  "zipBase64": "base64-encoded-zip-content",
  "clearBeforeDrop": true,
  "subDir": "optional/subdirectory",
  "dryRun": false,
  "options": ["optional", "array", "of", "strings"]
}
```

**Response:**

```json
{
  "requestId": "uuid",
  "droppedPath": "path/to/target",
  "files": 10,
  "bytes": 12345,
  "cleared": true,
  "dryRun": false,
  "tookMs": 123,
  "hookExecuted": false
}
```

### GET /health

Check service health and configuration.

**Response:**

```json
{
  "status": "ok",
  "port": 4545,
  "targetDir": "./src/inbox"
}
```

## Post-Drop Hook

You can configure a post-drop hook to execute custom logic after files are dropped:

1. Create a JavaScript/TypeScript module that exports a `postDropHook` function:

```javascript
// hooks/post-drop.js
export async function postDropHook(options) {
  console.log('Files dropped with options:', options);
  // Your custom logic here
}
```

2. Add the hook path to your configuration:

```json
{
  "postDropHook": "./hooks/post-drop.js"
}
```

## License

MIT

## Publishing to npm

This package is published to npm registry as a scoped package `@reditui/cli`.

**📖 詳細な日本語ガイド**: [PUBLISHING.md](./PUBLISHING.md) をご覧ください

### Prerequisites

1. npm account with publish permissions for `@reditui` scope
2. `NPM_TOKEN` secret configured in GitHub repository settings

### Publishing Process

The package is automatically published to npm when a new tag is pushed:

```bash
# Update version in packages/cli/package.json first
cd packages/cli
npm version patch  # or minor, major

# Create and push a git tag
git tag cli-v0.1.1
git push origin cli-v0.1.1
```

The GitHub Actions workflow `.github/workflows/publish-cli.yml` will automatically:
1. Build the package
2. Publish to npm registry with provenance

### Manual Publishing (if needed)

```bash
cd packages/cli
npm run build
npm publish --access public
```

Note: Make sure you're logged in with `npm login` first.