|
1 | 1 | --- |
2 | 2 | title: Command Line Interface |
3 | | -description: Guide for using the ObjectStack CLI |
| 3 | +description: Complete guide for using the ObjectStack CLI to build metadata-driven applications |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # @objectstack/cli |
7 | 7 |
|
8 | | -Command Line Interface for developing and managing ObjectStack applications. |
| 8 | +Command Line Interface for building metadata-driven applications with the ObjectStack Protocol. |
9 | 9 |
|
10 | 10 | ## Installation |
11 | 11 |
|
12 | 12 | ```bash |
13 | 13 | pnpm add -D @objectstack/cli |
14 | 14 | ``` |
15 | 15 |
|
| 16 | +The CLI is available as `objectstack` or the shorter alias `os`. |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +```bash |
| 21 | +# Initialize a new project |
| 22 | +os init my-app |
| 23 | + |
| 24 | +# Generate metadata |
| 25 | +os generate object task |
| 26 | +os generate view task |
| 27 | +os generate flow task |
| 28 | + |
| 29 | +# Validate configuration |
| 30 | +os validate |
| 31 | + |
| 32 | +# Start development server |
| 33 | +os dev |
| 34 | + |
| 35 | +# Compile for production |
| 36 | +os compile |
| 37 | +``` |
| 38 | + |
16 | 39 | ## Commands |
17 | 40 |
|
18 | 41 | ### Development |
19 | 42 |
|
20 | | -- **`os serve`**: Start the backend server. |
21 | | - - Auto-detects configuration. |
22 | | - - Auto-loads `ObjectQL` and `InMemoryDriver` if not specified. |
23 | | -- **`os dev`**: Start in development mode (with watch). |
24 | | -- **`os doctor`**: Check environment health. |
| 43 | +| Command | Alias | Description | |
| 44 | +|---------|-------|-------------| |
| 45 | +| `os init [name]` | | Initialize a new ObjectStack project in the current directory | |
| 46 | +| `os dev [package]` | | Start development mode with hot reload | |
| 47 | +| `os serve [config]` | | Start the ObjectStack server with plugin auto-detection | |
| 48 | + |
| 49 | +#### `os init` |
| 50 | + |
| 51 | +Scaffolds a new ObjectStack project with configuration, TypeScript setup, and initial metadata files. |
| 52 | + |
| 53 | +```bash |
| 54 | +os init my-app # Create with default "app" template |
| 55 | +os init my-plugin -t plugin # Create a plugin project |
| 56 | +os init blank -t empty # Minimal config only |
| 57 | +os init my-app --no-install # Skip dependency installation |
| 58 | +``` |
| 59 | + |
| 60 | +**Options:** |
| 61 | +- `-t, --template <template>` — Template: `app` (default), `plugin`, `empty` |
| 62 | +- `--no-install` — Skip automatic `pnpm install` |
| 63 | + |
| 64 | +**Templates:** |
| 65 | + |
| 66 | +| Template | What it creates | |
| 67 | +|----------|-----------------| |
| 68 | +| `app` | Full application with objects, views, barrel imports | |
| 69 | +| `plugin` | Reusable plugin package with objects | |
| 70 | +| `empty` | Minimal project with just `objectstack.config.ts` | |
| 71 | + |
| 72 | +#### `os dev` |
| 73 | + |
| 74 | +Starts development mode. When run inside a directory with `objectstack.config.ts`, it delegates to `os serve --dev`. When run from a monorepo root, it orchestrates all packages. |
| 75 | + |
| 76 | +```bash |
| 77 | +os dev # Auto-detect: single package or monorepo |
| 78 | +os dev my-package # Start specific workspace package |
| 79 | +os dev -v # Verbose output |
| 80 | +``` |
| 81 | + |
| 82 | +#### `os serve` |
| 83 | + |
| 84 | +Starts the ObjectStack server with automatic plugin discovery: |
| 85 | + |
| 86 | +- Auto-loads **ObjectQL Engine** when objects are defined |
| 87 | +- Auto-loads **InMemory Driver** in dev mode |
| 88 | +- Auto-loads **App Plugin** for metadata |
| 89 | +- Auto-loads **Hono HTTP Server** for REST APIs |
| 90 | + |
| 91 | +```bash |
| 92 | +os serve # Default: port 3000 |
| 93 | +os serve -p 4000 # Custom port |
| 94 | +os serve --dev # Development mode (pretty logs, devPlugins) |
| 95 | +os serve --no-server # Skip HTTP server (kernel only) |
| 96 | +``` |
| 97 | + |
| 98 | +**Options:** |
| 99 | +- `-p, --port <port>` — Server port (default: `3000`) |
| 100 | +- `--dev` — Development mode (loads devPlugins, pretty logging) |
| 101 | +- `--no-server` — Skip starting HTTP server plugin |
| 102 | + |
| 103 | +### Build & Validate |
| 104 | + |
| 105 | +| Command | Description | |
| 106 | +|---------|-------------| |
| 107 | +| `os compile [config]` | Compile configuration to a JSON artifact (`dist/objectstack.json`) | |
| 108 | +| `os validate [config]` | Validate configuration against the ObjectStack Protocol schema | |
| 109 | +| `os info [config]` | Display metadata summary (objects, fields, apps, agents, etc.) | |
| 110 | + |
| 111 | +#### `os compile` |
| 112 | + |
| 113 | +Bundles and validates your `objectstack.config.ts` against the `ObjectStackDefinitionSchema`, then outputs a deployable JSON artifact. |
| 114 | + |
| 115 | +```bash |
| 116 | +os compile # Default output: dist/objectstack.json |
| 117 | +os compile -o build/stack.json # Custom output path |
| 118 | +os compile --json # JSON output for CI pipelines |
| 119 | +``` |
| 120 | + |
| 121 | +**Options:** |
| 122 | +- `-o, --output <path>` — Output path (default: `dist/objectstack.json`) |
| 123 | +- `--json` — Output compile result as JSON (for CI) |
| 124 | + |
| 125 | +**Output example:** |
| 126 | +``` |
| 127 | +◆ Compile |
| 128 | +──────────────────────────────────────── |
| 129 | + → Loading configuration... |
| 130 | + Config: objectstack.config.ts |
| 131 | + Load time: 104ms |
| 132 | + → Validating protocol compliance... |
| 133 | + → Writing artifact... |
| 134 | +
|
| 135 | + ✓ Build complete (312ms) |
| 136 | +
|
| 137 | + Data: 10 Objects 217 Fields |
| 138 | + UI: 1 Apps 3 Dashboards 8 Reports 10 Actions |
| 139 | + Logic: 5 Flows 5 Agents 2 APIs |
| 140 | +
|
| 141 | + Artifact: dist/objectstack.json (48.2 KB) |
| 142 | +``` |
| 143 | + |
| 144 | +#### `os validate` |
| 145 | + |
| 146 | +Standalone schema validation with rich error output. Use to check your configuration without compiling. |
| 147 | + |
| 148 | +```bash |
| 149 | +os validate # Validate current directory |
| 150 | +os validate --strict # Warnings as errors |
| 151 | +os validate --json # JSON output for CI |
| 152 | +os validate path/to/config # Validate specific file |
| 153 | +``` |
| 154 | + |
| 155 | +**Options:** |
| 156 | +- `--strict` — Treat warnings as errors (exit code 1) |
| 157 | +- `--json` — Output results as JSON |
| 158 | + |
| 159 | +**Warnings checked:** |
| 160 | +- Missing `manifest.id` (required for deployment) |
| 161 | +- Missing `manifest.namespace` (required for multi-app hosting) |
| 162 | +- No objects defined |
| 163 | +- No apps or plugins defined |
| 164 | + |
| 165 | +#### `os info` |
| 166 | + |
| 167 | +Displays a summary of your metadata without compilation or validation: |
| 168 | + |
| 169 | +```bash |
| 170 | +os info # Show metadata summary |
| 171 | +os info --json # JSON output for tooling |
| 172 | +``` |
| 173 | + |
| 174 | +**Output example:** |
| 175 | +``` |
| 176 | +◆ Info |
| 177 | +──────────────────────────────────────── |
| 178 | +
|
| 179 | + Enterprise CRM v3.0.0 |
| 180 | + com.example.crm |
| 181 | + Namespace: crm |
| 182 | + Type: app |
| 183 | +
|
| 184 | + Data: 10 Objects 217 Fields |
| 185 | + UI: 1 Apps 3 Dashboards 8 Reports 10 Actions |
| 186 | + Logic: 5 Flows 5 Agents 2 APIs |
| 187 | +
|
| 188 | + Objects: |
| 189 | + account (16 fields, own) — Account |
| 190 | + contact (24 fields, own) — Contact |
| 191 | + ... |
| 192 | +
|
| 193 | + Loaded in 90ms |
| 194 | +``` |
25 | 195 |
|
26 | 196 | ### Scaffolding |
27 | 197 |
|
28 | | -- **`os create`**: Scaffold new projects. |
| 198 | +| Command | Alias | Description | |
| 199 | +|---------|-------|-------------| |
| 200 | +| `os generate <type> <name>` | `os g` | Generate metadata files | |
| 201 | +| `os create <type> [name]` | | Create a new package from template | |
| 202 | + |
| 203 | +#### `os generate` (alias: `os g`) |
| 204 | + |
| 205 | +Generates properly typed metadata files with barrel index management. |
| 206 | + |
| 207 | +```bash |
| 208 | +os g object customer # Generate a Customer object |
| 209 | +os g view customer # Generate a Customer list view |
| 210 | +os g action approve # Generate an action |
| 211 | +os g flow customer # Generate an automation flow |
| 212 | +os g agent support # Generate an AI agent |
| 213 | +os g dashboard sales # Generate a dashboard |
| 214 | +os g app crm # Generate an app definition |
| 215 | + |
| 216 | +os g object task -d lib/ # Override target directory |
| 217 | +os g object task --dry-run # Preview without writing |
| 218 | +``` |
| 219 | + |
| 220 | +**Available types:** |
| 221 | + |
| 222 | +| Type | Default Directory | Description | |
| 223 | +|------|------------------|-------------| |
| 224 | +| `object` | `src/objects/` | Business data object with fields | |
| 225 | +| `view` | `src/views/` | List or form view definition | |
| 226 | +| `action` | `src/actions/` | Button or batch action | |
| 227 | +| `flow` | `src/flows/` | Automation flow | |
| 228 | +| `agent` | `src/agents/` | AI agent | |
| 229 | +| `dashboard` | `src/dashboards/` | Analytics dashboard | |
| 230 | +| `app` | `src/apps/` | Application navigation | |
| 231 | + |
| 232 | +**Options:** |
| 233 | +- `-d, --dir <directory>` — Override target directory |
| 234 | +- `--dry-run` — Preview without writing files |
| 235 | + |
| 236 | +**What it does:** |
| 237 | +1. Creates a typed TypeScript file using `Data.Object`, `UI.View`, `Automation.Flow`, etc. |
| 238 | +2. Creates or updates the barrel `index.ts` in the target directory |
| 239 | +3. Shows a hint to run `objectstack validate` |
| 240 | + |
| 241 | +#### `os create` |
| 242 | + |
| 243 | +Creates new packages from built-in templates (for monorepo-level scaffolding): |
| 244 | + |
| 245 | +```bash |
| 246 | +os create plugin analytics # Create packages/plugins/plugin-analytics |
| 247 | +os create example my-app # Create examples/my-app |
| 248 | +``` |
| 249 | + |
| 250 | +### Quality |
| 251 | + |
| 252 | +| Command | Description | |
| 253 | +|---------|-------------| |
| 254 | +| `os test [files]` | Run Quality Protocol test scenarios against a running server | |
| 255 | +| `os doctor` | Check development environment health | |
| 256 | + |
| 257 | +#### `os test` |
| 258 | + |
| 259 | +Runs Quality Protocol test scenarios (JSON-based BDD) against a running ObjectStack server. |
| 260 | + |
| 261 | +```bash |
| 262 | +os test # Default: qa/*.test.json |
| 263 | +os test qa/my-test.json # Specific test file |
| 264 | +os test --url http://localhost:4000 # Custom server URL |
| 265 | +os test --token my-api-key # With authentication |
| 266 | +``` |
| 267 | + |
| 268 | +#### `os doctor` |
| 269 | + |
| 270 | +Checks your development environment and reports issues: |
| 271 | + |
| 272 | +```bash |
| 273 | +os doctor # Check health |
| 274 | +os doctor -v # Show fix suggestions for warnings |
| 275 | +``` |
| 276 | + |
| 277 | +**Checks performed:** |
| 278 | +- Node.js version (≥18 required) |
| 279 | +- pnpm installation |
| 280 | +- TypeScript availability |
| 281 | +- Dependencies installed |
| 282 | +- `@objectstack/spec` build status |
| 283 | +- Git availability |
29 | 284 |
|
30 | 285 | ## Configuration |
31 | 286 |
|
32 | | -The CLI automatically looks for `objectstack.config.ts` in the current directory to load the runtime configuration. |
| 287 | +The CLI looks for `objectstack.config.ts` (or `.js`, `.mjs`) in the current directory: |
33 | 288 |
|
34 | 289 | ```typescript |
35 | | -// objectstack.config.ts |
36 | | -export default { |
37 | | - metadata: { |
38 | | - // ... |
39 | | - }, |
40 | | - plugins: [ |
41 | | - // ... |
42 | | - ] |
43 | | -} |
| 290 | +import { defineStack } from '@objectstack/spec'; |
| 291 | +import * as objects from './src/objects'; |
| 292 | +import * as actions from './src/actions'; |
| 293 | + |
| 294 | +export default defineStack({ |
| 295 | + manifest: { |
| 296 | + id: 'com.example.my-app', |
| 297 | + namespace: 'my_app', |
| 298 | + version: '1.0.0', |
| 299 | + type: 'app', |
| 300 | + name: 'My App', |
| 301 | + description: 'My ObjectStack application', |
| 302 | + }, |
| 303 | + |
| 304 | + objects: Object.values(objects), |
| 305 | + actions: Object.values(actions), |
| 306 | +}); |
| 307 | +``` |
| 308 | + |
| 309 | +### Config File Auto-Detection |
| 310 | + |
| 311 | +The CLI searches for configuration files in this order: |
| 312 | +1. `objectstack.config.ts` |
| 313 | +2. `objectstack.config.js` |
| 314 | +3. `objectstack.config.mjs` |
| 315 | + |
| 316 | +You can also specify a path explicitly: |
| 317 | + |
| 318 | +```bash |
| 319 | +os compile path/to/my-config.ts |
| 320 | +``` |
| 321 | + |
| 322 | +## Typical Workflow |
| 323 | + |
| 324 | +```bash |
| 325 | +# 1. Create project |
| 326 | +os init my-crm |
| 327 | + |
| 328 | +# 2. Define your data model |
| 329 | +os g object account |
| 330 | +os g object contact |
| 331 | +os g object opportunity |
| 332 | + |
| 333 | +# 3. Add UI definitions |
| 334 | +os g view account |
| 335 | +os g view contact |
| 336 | +os g dashboard sales |
| 337 | + |
| 338 | +# 4. Add business logic |
| 339 | +os g flow lead-qualification |
| 340 | +os g agent sales-assistant |
| 341 | + |
| 342 | +# 5. Validate everything |
| 343 | +os validate |
| 344 | + |
| 345 | +# 6. Start development |
| 346 | +os dev |
| 347 | + |
| 348 | +# 7. Build for production |
| 349 | +os compile |
| 350 | +``` |
| 351 | + |
| 352 | +## CI/CD Integration |
| 353 | + |
| 354 | +All commands that produce output support `--json` for machine-readable output: |
| 355 | + |
| 356 | +```bash |
| 357 | +# In CI pipeline |
| 358 | +os validate --json --strict |
| 359 | +os compile --json -o dist/objectstack.json |
| 360 | +os info --json |
| 361 | +``` |
| 362 | + |
| 363 | +Example GitHub Actions step: |
| 364 | + |
| 365 | +```yaml |
| 366 | +- name: Validate ObjectStack Config |
| 367 | + run: npx objectstack validate --strict --json |
| 368 | + |
| 369 | +- name: Build ObjectStack Artifact |
| 370 | + run: npx objectstack compile --json |
44 | 371 | ``` |
0 commit comments