|
| 1 | +--- |
| 2 | +title: "ObjectUI CLI" |
| 3 | +description: "Command-line interface for building ObjectUI applications" |
| 4 | +--- |
| 5 | + |
| 6 | +# ObjectUI CLI |
| 7 | + |
| 8 | +The ObjectUI CLI (`@object-ui/cli`) is a command-line tool for scaffolding and running ObjectUI applications directly from JSON or YAML schemas. It provides a built-in development server and supports rapid prototyping without writing any code. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install -g @object-ui/cli |
| 14 | +``` |
| 15 | + |
| 16 | +Or use with npx: |
| 17 | + |
| 18 | +```bash |
| 19 | +npx @object-ui/cli --help |
| 20 | +``` |
| 21 | + |
| 22 | +## Features |
| 23 | + |
| 24 | +- 🚀 **Project Scaffolding** - Generate new ObjectUI projects from schemas |
| 25 | +- 🔥 **Built-in Dev Server** - Express + Vite development server with HMR |
| 26 | +- 📄 **JSON/YAML Support** - Write schemas in JSON or YAML format |
| 27 | +- ⚡ **Hot Module Reloading** - See changes instantly |
| 28 | +- 🎨 **Zero Configuration** - Works out of the box |
| 29 | +- 📦 **Production Builds** - Optimized builds for deployment |
| 30 | + |
| 31 | +## Commands |
| 32 | + |
| 33 | +### `objectui` (Binary Name) |
| 34 | + |
| 35 | +The main CLI binary. |
| 36 | + |
| 37 | +```bash |
| 38 | +objectui [command] [options] |
| 39 | +``` |
| 40 | + |
| 41 | +### Available Commands |
| 42 | + |
| 43 | +#### `init` - Create a New Project |
| 44 | + |
| 45 | +Initialize a new ObjectUI project from a schema. |
| 46 | + |
| 47 | +```bash |
| 48 | +objectui init <project-name> |
| 49 | +``` |
| 50 | + |
| 51 | +**Options:** |
| 52 | +- `--template <name>` - Use a specific template |
| 53 | +- `--schema <path>` - Use an existing schema file |
| 54 | + |
| 55 | +**Example:** |
| 56 | + |
| 57 | +```bash |
| 58 | +# Create a new project |
| 59 | +objectui init my-dashboard |
| 60 | + |
| 61 | +# Create from existing schema |
| 62 | +objectui init my-app --schema ./schema.json |
| 63 | +``` |
| 64 | + |
| 65 | +#### `dev` - Start Development Server |
| 66 | + |
| 67 | +Start the development server with hot module reloading. |
| 68 | + |
| 69 | +```bash |
| 70 | +objectui dev [options] |
| 71 | +``` |
| 72 | + |
| 73 | +**Options:** |
| 74 | +- `--port <number>` - Port to run on (default: 5173) |
| 75 | +- `--host` - Expose to network |
| 76 | +- `--schema <path>` - Schema file to use |
| 77 | + |
| 78 | +**Example:** |
| 79 | + |
| 80 | +```bash |
| 81 | +# Start dev server |
| 82 | +objectui dev |
| 83 | + |
| 84 | +# Custom port |
| 85 | +objectui dev --port 3000 |
| 86 | + |
| 87 | +# Specific schema |
| 88 | +objectui dev --schema ./schemas/dashboard.json |
| 89 | +``` |
| 90 | + |
| 91 | +#### `build` - Production Build |
| 92 | + |
| 93 | +Build the application for production. |
| 94 | + |
| 95 | +```bash |
| 96 | +objectui build [options] |
| 97 | +``` |
| 98 | + |
| 99 | +**Options:** |
| 100 | +- `--outDir <path>` - Output directory (default: dist) |
| 101 | +- `--minify` - Minify output |
| 102 | +- `--sourcemap` - Generate source maps |
| 103 | + |
| 104 | +**Example:** |
| 105 | + |
| 106 | +```bash |
| 107 | +# Build for production |
| 108 | +objectui build |
| 109 | + |
| 110 | +# Custom output directory |
| 111 | +objectui build --outDir ./build |
| 112 | +``` |
| 113 | + |
| 114 | +#### `preview` - Preview Production Build |
| 115 | + |
| 116 | +Preview the production build locally. |
| 117 | + |
| 118 | +```bash |
| 119 | +objectui preview [options] |
| 120 | +``` |
| 121 | + |
| 122 | +**Options:** |
| 123 | +- `--port <number>` - Port to run on (default: 4173) |
| 124 | + |
| 125 | +**Example:** |
| 126 | + |
| 127 | +```bash |
| 128 | +# Preview production build |
| 129 | +objectui preview |
| 130 | +``` |
| 131 | + |
| 132 | +## Schema File Format |
| 133 | + |
| 134 | +The CLI supports both JSON and YAML schema files. |
| 135 | + |
| 136 | +### JSON Schema Example |
| 137 | + |
| 138 | +Create a `schema.json` file: |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "type": "app", |
| 143 | + "title": "My Dashboard", |
| 144 | + "pages": [ |
| 145 | + { |
| 146 | + "path": "/", |
| 147 | + "title": "Home", |
| 148 | + "component": { |
| 149 | + "type": "div", |
| 150 | + "className": "p-8", |
| 151 | + "children": [ |
| 152 | + { |
| 153 | + "type": "heading", |
| 154 | + "level": 1, |
| 155 | + "children": "Welcome to ObjectUI" |
| 156 | + }, |
| 157 | + { |
| 158 | + "type": "bar-chart", |
| 159 | + "data": [ |
| 160 | + { "name": "Jan", "value": 400 }, |
| 161 | + { "name": "Feb", "value": 300 }, |
| 162 | + { "name": "Mar", "value": 600 } |
| 163 | + ], |
| 164 | + "dataKey": "value", |
| 165 | + "xAxisKey": "name", |
| 166 | + "height": 300 |
| 167 | + } |
| 168 | + ] |
| 169 | + } |
| 170 | + } |
| 171 | + ] |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +### YAML Schema Example |
| 176 | + |
| 177 | +Create a `schema.yaml` file: |
| 178 | + |
| 179 | +```yaml |
| 180 | +type: app |
| 181 | +title: My Dashboard |
| 182 | +pages: |
| 183 | + - path: / |
| 184 | + title: Home |
| 185 | + component: |
| 186 | + type: div |
| 187 | + className: p-8 |
| 188 | + children: |
| 189 | + - type: heading |
| 190 | + level: 1 |
| 191 | + children: Welcome to ObjectUI |
| 192 | + - type: bar-chart |
| 193 | + data: |
| 194 | + - name: Jan |
| 195 | + value: 400 |
| 196 | + - name: Feb |
| 197 | + value: 300 |
| 198 | + - name: Mar |
| 199 | + value: 600 |
| 200 | + dataKey: value |
| 201 | + xAxisKey: name |
| 202 | + height: 300 |
| 203 | +``` |
| 204 | +
|
| 205 | +## Development Server |
| 206 | +
|
| 207 | +The CLI includes a built-in development server powered by Express and Vite. |
| 208 | +
|
| 209 | +### Features |
| 210 | +
|
| 211 | +- **Hot Module Reloading** - Instant updates when you change schema files |
| 212 | +- **Error Overlay** - See errors directly in the browser |
| 213 | +- **Fast Refresh** - React Fast Refresh for component changes |
| 214 | +- **Network Access** - Share with team using `--host` flag |
| 215 | + |
| 216 | +### Server Architecture |
| 217 | + |
| 218 | +``` |
| 219 | +┌─────────────────┐ |
| 220 | +│ Express Server │ (Static file serving, API proxy) |
| 221 | +└────────┬────────┘ |
| 222 | + │ |
| 223 | +┌────────▼────────┐ |
| 224 | +│ Vite Server │ (HMR, bundling, transpiling) |
| 225 | +└────────┬────────┘ |
| 226 | + │ |
| 227 | +┌────────▼────────┐ |
| 228 | +│ React App │ (SchemaRenderer) |
| 229 | +└─────────────────┘ |
| 230 | +``` |
| 231 | +
|
| 232 | +## Configuration |
| 233 | +
|
| 234 | +The CLI can be configured via `objectui.config.js` in your project root. |
| 235 | +
|
| 236 | +```javascript |
| 237 | +// objectui.config.js |
| 238 | +export default { |
| 239 | + // Development server options |
| 240 | + server: { |
| 241 | + port: 5173, |
| 242 | + host: true, |
| 243 | + }, |
| 244 | + |
| 245 | + // Build options |
| 246 | + build: { |
| 247 | + outDir: 'dist', |
| 248 | + minify: true, |
| 249 | + sourcemap: true, |
| 250 | + }, |
| 251 | + |
| 252 | + // Schema options |
| 253 | + schema: { |
| 254 | + path: './schema.json', |
| 255 | + format: 'json', // or 'yaml' |
| 256 | + }, |
| 257 | + |
| 258 | + // Plugin options |
| 259 | + plugins: [ |
| 260 | + '@object-ui/plugin-charts', |
| 261 | + '@object-ui/plugin-kanban', |
| 262 | + ], |
| 263 | +} |
| 264 | +``` |
| 265 | + |
| 266 | +## Environment Variables |
| 267 | + |
| 268 | +The CLI supports environment variables for configuration: |
| 269 | + |
| 270 | +```bash |
| 271 | +# Port |
| 272 | +OBJECTUI_PORT=3000 |
| 273 | + |
| 274 | +# Host |
| 275 | +OBJECTUI_HOST=0.0.0.0 |
| 276 | + |
| 277 | +# Schema path |
| 278 | +OBJECTUI_SCHEMA=./schemas/app.json |
| 279 | + |
| 280 | +# Build output |
| 281 | +OBJECTUI_OUT_DIR=./build |
| 282 | +``` |
| 283 | + |
| 284 | +## Use Cases |
| 285 | + |
| 286 | +### 1. Rapid Prototyping |
| 287 | + |
| 288 | +Quickly prototype UIs by editing JSON schemas: |
| 289 | + |
| 290 | +```bash |
| 291 | +# Create project |
| 292 | +objectui init prototype |
| 293 | + |
| 294 | +# Start dev server |
| 295 | +cd prototype |
| 296 | +objectui dev |
| 297 | + |
| 298 | +# Edit schema.json and see changes instantly |
| 299 | +``` |
| 300 | + |
| 301 | +### 2. Schema-Driven Applications |
| 302 | + |
| 303 | +Build entire applications from schemas without writing code: |
| 304 | + |
| 305 | +```bash |
| 306 | +# Use complex schema |
| 307 | +objectui dev --schema ./complex-app.json |
| 308 | +``` |
| 309 | + |
| 310 | +### 3. Backend Integration |
| 311 | + |
| 312 | +Integrate with your API backend: |
| 313 | + |
| 314 | +```json |
| 315 | +{ |
| 316 | + "type": "data-table", |
| 317 | + "dataSource": { |
| 318 | + "api": "http://localhost:3000/api/users", |
| 319 | + "method": "GET" |
| 320 | + }, |
| 321 | + "columns": [...] |
| 322 | +} |
| 323 | +``` |
| 324 | + |
| 325 | +### 4. Demos and Presentations |
| 326 | + |
| 327 | +Create interactive demos without a build setup: |
| 328 | + |
| 329 | +```bash |
| 330 | +npx @object-ui/cli dev --schema ./demo.json |
| 331 | +``` |
| 332 | + |
| 333 | +## Package Information |
| 334 | + |
| 335 | +**Package Name:** `@object-ui/cli` |
| 336 | +**Version:** 0.3.1 |
| 337 | +**Binary:** `objectui` |
| 338 | +**License:** MIT |
| 339 | + |
| 340 | +## Dependencies |
| 341 | + |
| 342 | +The CLI uses: |
| 343 | + |
| 344 | +- **Express** - HTTP server |
| 345 | +- **Vite** - Build tool and dev server |
| 346 | +- **Commander** - CLI argument parsing |
| 347 | +- **Chalk** - Terminal colors |
| 348 | +- **Ora** - Loading spinners |
| 349 | + |
| 350 | +## Next Steps |
| 351 | + |
| 352 | +- **[Create Plugin](/docs/utilities/create-plugin)** - Create custom plugins |
| 353 | +- **[Schema Overview](/docs/guide/schema-overview)** - Learn the schema format |
| 354 | +- **[Plugins](/docs/plugins)** - Explore available plugins |
| 355 | +- **[Examples](https://github.com/objectstack-ai/objectui/tree/main/examples)** - See example projects |
| 356 | + |
| 357 | +## Troubleshooting |
| 358 | + |
| 359 | +### Port Already in Use |
| 360 | + |
| 361 | +```bash |
| 362 | +# Use a different port |
| 363 | +objectui dev --port 3001 |
| 364 | +``` |
| 365 | + |
| 366 | +### Schema Not Found |
| 367 | + |
| 368 | +```bash |
| 369 | +# Specify schema path |
| 370 | +objectui dev --schema ./path/to/schema.json |
| 371 | +``` |
| 372 | + |
| 373 | +### Module Not Found |
| 374 | + |
| 375 | +Make sure all required plugins are installed: |
| 376 | + |
| 377 | +```bash |
| 378 | +# Install missing plugins |
| 379 | +npm install @object-ui/plugin-charts @object-ui/plugin-kanban |
| 380 | +``` |
| 381 | + |
| 382 | +## Need Help? |
| 383 | + |
| 384 | +- [GitHub Issues](https://github.com/objectstack-ai/objectui/issues) |
| 385 | +- [Documentation](https://www.objectui.org) |
| 386 | +- [Examples](https://github.com/objectstack-ai/objectui/tree/main/examples) |
0 commit comments