Skip to content

Commit eddb483

Browse files
committed
Add CLI usage example and project structure documentation; include configuration files for CLI development
1 parent 58652a8 commit eddb483

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

examples/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ pnpm dev
148148

149149
**Complete server implementation** showing how to build a metadata-driven backend.
150150

151+
---
152+
153+
### CLI Usage Example
154+
**Path:** [`examples/cli-usage/`](./cli-usage/)
155+
**Level:** 🟢 Beginner
156+
**Protocols:** System
157+
158+
**CLI Development Workflow** - Learn how to use `@objectstack/cli` for development and debugging.
159+
160+
**What you'll learn:**
161+
- Setting up a project for CLI
162+
- `dev` vs `serve` commands
163+
- Debugging configurations for VS Code
164+
- Project structure best practices
165+
166+
**Quick Start:**
167+
```bash
168+
cd examples/cli-usage
169+
pnpm install
170+
pnpm dev
171+
```
172+
151173
**Features:**
152174
- Dynamic schema loading from plugins
153175
- Auto-generated REST APIs

examples/cli-usage/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# CLI Usage Example
2+
3+
This example demonstrates how to use the `@objectstack/cli` to develop, serve, and debug an ObjectStack project.
4+
5+
## Scripts
6+
7+
The `package.json` includes several useful scripts:
8+
9+
- `pnpm dev`: Starts the development server in watch mode.
10+
- `pnpm serve`: Starts the production server.
11+
- `pnpm build`: Compiles the project.
12+
- `pnpm doctor`: Checks for issues.
13+
- `pnpm debug`: Starts the server in debug mode (breaking at the first line).
14+
15+
## Debugging in VS Code
16+
17+
To debug this project using VS Code:
18+
19+
1. Open the Javascript Debug Terminal.
20+
2. Run `pnpm dev` or `pnpm serve`.
21+
22+
### Using Launch Configuration
23+
24+
You can also use a launch configuration. Add this to your `.vscode/launch.json`:
25+
26+
```json
27+
{
28+
"version": "0.2.0",
29+
"configurations": [
30+
{
31+
"type": "node",
32+
"request": "launch",
33+
"name": "Debug CLI Usage Example",
34+
"cwd": "${workspaceFolder}/examples/cli-usage",
35+
"runtimeExecutable": "pnpm",
36+
"runtimeArgs": ["debug"],
37+
"port": 9229
38+
}
39+
]
40+
}
41+
```
42+
43+
## Project Structure
44+
45+
- `src/project.object.ts`: Defines a simple "Project" object.
46+
- `objectstack.config.ts`: Registers the object.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineStack } from '@objectstack/spec';
2+
import { Project } from './src/project.object.js';
3+
4+
export default defineStack({
5+
objects: [
6+
Project
7+
],
8+
apps: []
9+
});

examples/cli-usage/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@examples/cli-usage",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "objectstack dev",
7+
"serve": "objectstack serve",
8+
"build": "objectstack compile",
9+
"doctor": "objectstack doctor",
10+
"debug": "node --inspect-brk node_modules/.bin/objectstack serve"
11+
},
12+
"dependencies": {
13+
"@objectstack/cli": "workspace:*",
14+
"@objectstack/spec": "workspace:*"
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ObjectSchema, Field } from '@objectstack/spec/data';
2+
3+
export const Project = ObjectSchema.create({
4+
name: 'cli_project',
5+
label: 'CLI Project',
6+
icon: 'briefcase',
7+
fields: {
8+
name: Field.text({ required: true, label: 'Project Name' }),
9+
status: Field.select(['Planned', 'In Progress', 'Completed'], { defaultValue: 'Planned' }),
10+
description: Field.textarea()
11+
}
12+
});

examples/cli-usage/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"lib": ["ES2022"],
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"outDir": "dist"
12+
},
13+
"include": ["src", "objectstack.config.ts"]
14+
}

0 commit comments

Comments
 (0)