npm package: @scriptdb/cli
Description: CLI tool to start and manage ScriptDB server
Latest version: 1.1.3

# ScriptDB CLI

Command-line interface for ScriptDB - Database management with TypeScript scripting.

## Installation

Install from npm:
```bash
npm install -g @scriptdb/cli
# or
bun add -g @scriptdb/cli
```

Install from source:
```bash
git clone <repo>
cd scriptdb
bun install
bun run build
npm link
```

## Usage

### Server Management

Start the server in daemon mode (background):
```bash
scriptdb start -d
```

Start the server in foreground:
```bash
scriptdb start
```

Stop the server:
```bash
scriptdb stop
```

Restart the server:
```bash
scriptdb restart -d
```

Check server status:
```bash
scriptdb status
```

View server logs:
```bash
scriptdb logs
```

### Interactive Shell

Start the interactive shell (requires server to be running):
```bash
scriptdb shell
```

Shell commands:
- `.exit`, `.quit` - Exit the shell
- `.help` - Show help
- `.dbs` - List all databases
- `.use <name>` - Switch to a database
- `.create <name>` - Create a new database

Execute TypeScript code:
```bash
> const x = 1 + 1
> x
2
> [1,2,3].map(n => n * 2)
[2, 4, 6]
```

### Configuration

Configuration file: `~/.scriptdb/config.json`

Example:
```json
{
  "host": "localhost",
  "port": 1234,
  "users": [
    {
      "username": "admin",
      "password": "your-password",
      "hash": false
    }
  ],
  "folder": "databases",
  "secure": false
}
```

### Package Management

Install packages to ScriptDB:
```bash
# Install to ~/.scriptdb/packages
scriptdb add lodash
scriptdb add axios express

# Install to current directory
scriptdb add --local lodash
```

Remove packages:
```bash
# Remove from ~/.scriptdb/packages
scriptdb remove lodash

# Remove from current directory
scriptdb remove --local lodash
```

### Monitoring

View real-time logs:
```bash
scriptdb logs
```

Monitor performance (CPU, memory, uptime):
```bash
scriptdb monit
```

## Commands

| Command | Description |
|---------|-------------|
| `scriptdb start [-d]` | Start server (`-d` for daemon/PM2 mode) |
| `scriptdb stop` | Stop the running server |
| `scriptdb restart [-d]` | Restart the server |
| `scriptdb status` | Check server status and view metrics |
| `scriptdb logs` | View real-time logs |
| `scriptdb monit` | Monitor performance (CPU, memory, uptime) |
| `scriptdb shell` | Start interactive shell |
| `scriptdb add <pkg>` | Install packages to ~/.scriptdb |
| `scriptdb add --local <pkg>` | Install packages to current directory |
| `scriptdb remove <pkg>` | Remove packages from ~/.scriptdb |
| `scriptdb remove --local <pkg>` | Remove packages from current directory |

## Building

### Build for all platforms (local)

```bash
bun run build:binary
```

### Build using Docker (recommended for cross-platform)

```bash
bun run build:docker
```

This will build binaries for all platforms inside a Docker container.

### Build for specific platform

```bash
bun run build:linux-x64
bun run build:linux-arm64
bun run build:windows-x64
bun run build:darwin-x64
bun run build:darwin-arm64
bun run build:linux-x64-musl
bun run build:linux-arm64-musl
```

## Development

```bash
bun run dev
```

## Files

- Config file: `~/.scriptdb/config.json`
- Ecosystem config: `~/.scriptdb/ecosystem.config.js` (PM2)
- PM2 logs: `~/.scriptdb/pm2-*.log`
- Databases: `~/.scriptdb/databases/`
- Packages: `~/.scriptdb/packages/`

## Changelog

### 1.1.2 (2025-01-16)

**Added**
- Native `scriptdb logs` command to view real-time logs
- Native `scriptdb monit` command to monitor performance
- Native `scriptdb restart` command to restart the server
- Native `scriptdb stop` command to stop the server
- Dynamic version reading from package.json
- ESLint configuration for TypeScript linting

**Fixed**
- Fixed TypeScript module resolution errors
- Fixed test command to continue gracefully when packages have no tests
- Improved error handling and Windows compatibility

## License

MIT