|
| 1 | +# CLI Guide |
| 2 | + |
| 3 | +The ObjectQL CLI (`@objectql/cli`) is an essential tool for development, automating tasks like type generation and database migrations. |
| 4 | + |
| 5 | +## 1. Installation |
| 6 | + |
| 7 | +The CLI is typically installed as a dev dependency in your project. |
| 8 | + |
| 9 | +```bash |
| 10 | +npm install -D @objectql/cli |
| 11 | +``` |
| 12 | + |
| 13 | +You can then run it via `npx objectql` or add scripts to your `package.json`. |
| 14 | + |
| 15 | +## 2. Core Commands |
| 16 | + |
| 17 | +### 2.1 `init` (Create Project) |
| 18 | + |
| 19 | +Create a new ObjectQL project from a starter template. |
| 20 | + |
| 21 | +```bash |
| 22 | +npx objectql init [options] |
| 23 | +``` |
| 24 | + |
| 25 | +**Options:** |
| 26 | + |
| 27 | +| Option | Alias | Default | Description | |
| 28 | +| :--- | :--- | :--- | :--- | |
| 29 | +| `--template <template>` | `-t` | `basic` | Template to use (`basic`, `express-api`, `enterprise`). | |
| 30 | +| `--name <name>` | `-n` | - | Project name. | |
| 31 | +| `--dir <path>` | `-d` | - | Target directory. | |
| 32 | +| `--skip-install` | | `false` | Skip dependency installation. | |
| 33 | +| `--skip-git` | | `false` | Skip git initialization. | |
| 34 | + |
| 35 | +**Example:** |
| 36 | + |
| 37 | +```bash |
| 38 | +npx objectql init -t express-api -n my-app |
| 39 | +``` |
| 40 | + |
| 41 | +### 2.2 `generate` (Type Generation) |
| 42 | + |
| 43 | +Scans your `*.object.yml` files and generates TypeScript interfaces. This is crucial for maintaining type safety in your Hooks and Actions. |
| 44 | +**Alias**: `g` |
| 45 | + |
| 46 | +```bash |
| 47 | +npx objectql generate [options] |
| 48 | +``` |
| 49 | + |
| 50 | +**Options:** |
| 51 | + |
| 52 | +| Option | Alias | Default | Description | |
| 53 | +| :--- | :--- | :--- | :--- | |
| 54 | +| `--source <path>` | `-s` | `.` | Root directory to search for object files. | |
| 55 | +| `--output <path>` | `-o` | `./src/generated` | Directory where `.ts` files will be generated. | |
| 56 | + |
| 57 | +**Example:** |
| 58 | + |
| 59 | +```bash |
| 60 | +# Generate types from /src/objects to /src/types |
| 61 | +npx objectql generate --source ./src/objects --output ./src/types |
| 62 | +``` |
| 63 | + |
| 64 | +### 2.3 `new` (Scaffold Metadata) |
| 65 | + |
| 66 | +Generate a new metadata file (Object, View, Form, etc.) in the project. |
| 67 | + |
| 68 | +```bash |
| 69 | +npx objectql new <type> <name> [options] |
| 70 | +``` |
| 71 | + |
| 72 | +**Arguments:** |
| 73 | +* `<type>`: The type of metadata to generate (e.g., `object`, `view`, `page`). |
| 74 | +* `<name>`: The name of the file/entity. |
| 75 | + |
| 76 | +**Options:** |
| 77 | + |
| 78 | +| Option | Alias | Default | Description | |
| 79 | +| :--- | :--- | :--- | :--- | |
| 80 | +| `--dir <path>` | `-d` | `.` | Output directory. | |
| 81 | + |
| 82 | +**Example:** |
| 83 | +```bash |
| 84 | +npx objectql new object customer |
| 85 | +``` |
| 86 | + |
| 87 | +## 3. Development Tools |
| 88 | + |
| 89 | +### 3.1 `serve` (Dev Server) |
| 90 | + |
| 91 | +Start a standalone development server. |
| 92 | +**Alias**: `s` |
| 93 | + |
| 94 | +```bash |
| 95 | +npx objectql serve [options] |
| 96 | +``` |
| 97 | + |
| 98 | +**Options:** |
| 99 | + |
| 100 | +| Option | Alias | Default | Description | |
| 101 | +| :--- | :--- | :--- | :--- | |
| 102 | +| `--port <number>` | `-p` | `3000` | Port to listen on. | |
| 103 | +| `--dir <path>` | `-d` | `.` | Directory containing schema. | |
| 104 | + |
| 105 | +### 3.2 `studio` (Admin UI) |
| 106 | + |
| 107 | +Starts the web-based admin studio to browse data and view schema. |
| 108 | +**Alias**: `ui` |
| 109 | + |
| 110 | +```bash |
| 111 | +npx objectql studio [options] |
| 112 | +``` |
| 113 | + |
| 114 | +**Options:** |
| 115 | + |
| 116 | +| Option | Alias | Default | Description | |
| 117 | +| :--- | :--- | :--- | :--- | |
| 118 | +| `--port <number>` | `-p` | `3000` | Port to listen on. | |
| 119 | +| `--dir <path>` | `-d` | `.` | Directory containing schema. | |
| 120 | +| `--no-open` | | `false` | Do not open the browser automatically. | |
| 121 | + |
| 122 | +### 3.3 `repl` (Interactive Shell) |
| 123 | + |
| 124 | +Starts an interactive terminal similar to the MongoDB shell, allowing you to directly query your database using the ObjectQL API. |
| 125 | +**Alias**: `r` |
| 126 | + |
| 127 | +```bash |
| 128 | +npx objectql repl [options] |
| 129 | +``` |
| 130 | + |
| 131 | +**Options:** |
| 132 | + |
| 133 | +| Option | Alias | Default | Description | |
| 134 | +| :--- | :--- | :--- | :--- | |
| 135 | +| `--config <path>` | `-c` | - | Path to `objectql.config.ts/js`. | |
| 136 | + |
| 137 | +**Example Session:** |
| 138 | + |
| 139 | +```javascript |
| 140 | +objectql> await tasks.find({ status: 'todo' }) |
| 141 | +[ { id: 1, title: 'Fix bug', status: 'todo' } ] |
| 142 | +``` |
| 143 | + |
| 144 | +## 4. Internationalization (i18n) |
| 145 | + |
| 146 | +Tools for managing translations. |
| 147 | + |
| 148 | +### 4.1 `i18n extract` |
| 149 | + |
| 150 | +Extract translatable strings from metadata files into JSON. |
| 151 | + |
| 152 | +```bash |
| 153 | +npx objectql i18n extract [options] |
| 154 | +``` |
| 155 | + |
| 156 | +**Options:** |
| 157 | + |
| 158 | +| Option | Alias | Default | Description | |
| 159 | +| :--- | :--- | :--- | :--- | |
| 160 | +| `--source <path>` | `-s` | `.` | Source directory to scan. | |
| 161 | +| `--output <path>` | `-o` | `./src/i18n` | Output directory for translation files. | |
| 162 | +| `--lang <lang>` | `-l` | `en` | Language code. | |
| 163 | + |
| 164 | +### 4.2 `i18n init` |
| 165 | + |
| 166 | +Initialize i18n structure for a new language. |
| 167 | + |
| 168 | +```bash |
| 169 | +npx objectql i18n init <lang> [options] |
| 170 | +``` |
| 171 | + |
| 172 | +**Options:** |
| 173 | + |
| 174 | +| Option | Alias | Default | Description | |
| 175 | +| :--- | :--- | :--- | :--- | |
| 176 | +| `--base-dir <path>` | `-b` | `./src/i18n` | Base i18n directory. | |
| 177 | + |
| 178 | +### 4.3 `i18n validate` |
| 179 | + |
| 180 | +Validate translation completeness against a base language. |
| 181 | + |
| 182 | +```bash |
| 183 | +npx objectql i18n validate <lang> [options] |
| 184 | +``` |
| 185 | + |
| 186 | +**Options:** |
| 187 | + |
| 188 | +| Option | Alias | Default | Description | |
| 189 | +| :--- | :--- | :--- | :--- | |
| 190 | +| `--base-dir <path>` | `-b` | `./src/i18n` | Base i18n directory. | |
| 191 | +| `--base-lang <lang>` | | `en` | Base language to compare against. | |
| 192 | + |
| 193 | +## 5. Database Migration |
| 194 | + |
| 195 | +Manage database schema changes. |
| 196 | + |
| 197 | +### 5.1 `migrate` |
| 198 | + |
| 199 | +Run pending database migrations. |
| 200 | + |
| 201 | +```bash |
| 202 | +npx objectql migrate [options] |
| 203 | +``` |
| 204 | + |
| 205 | +**Options:** |
| 206 | + |
| 207 | +| Option | Alias | Default | Description | |
| 208 | +| :--- | :--- | :--- | :--- | |
| 209 | +| `--config <path>` | `-c` | - | Path to `objectql.config.ts/js`. | |
| 210 | +| `--dir <path>` | `-d` | `./migrations` | Migrations directory. | |
| 211 | + |
| 212 | +### 5.2 `migrate create` |
| 213 | + |
| 214 | +Create a new migration file. |
| 215 | + |
| 216 | +```bash |
| 217 | +npx objectql migrate create <name> [options] |
| 218 | +``` |
| 219 | + |
| 220 | +**Options:** |
| 221 | + |
| 222 | +| Option | Alias | Default | Description | |
| 223 | +| :--- | :--- | :--- | :--- | |
| 224 | +| `--dir <path>` | `-d` | `./migrations` | Migrations directory. | |
| 225 | + |
| 226 | +### 5.3 `migrate status` |
| 227 | + |
| 228 | +Show the status of migrations (applied/pending). |
| 229 | + |
| 230 | +```bash |
| 231 | +npx objectql migrate status [options] |
| 232 | +``` |
| 233 | + |
| 234 | +**Options:** |
| 235 | + |
| 236 | +| Option | Alias | Default | Description | |
| 237 | +| :--- | :--- | :--- | :--- | |
| 238 | +| `--config <path>` | `-c` | - | Path to `objectql.config.ts/js`. | |
| 239 | +| `--dir <path>` | `-d` | `./migrations` | Migrations directory. | |
| 240 | + |
| 241 | +## 6. Integration with Workflow |
| 242 | + |
| 243 | +We recommend adding the CLI commands to your lifecycle scripts. |
| 244 | + |
| 245 | +**package.json:** |
| 246 | + |
| 247 | +```json |
| 248 | +{ |
| 249 | + "scripts": { |
| 250 | + "codegen": "objectql generate -s ./src -o ./src/generated", |
| 251 | + "build": "npm run codegen && tsc", |
| 252 | + "dev": "npm run codegen && ts-node src/index.ts", |
| 253 | + "studio": "objectql studio" |
| 254 | + } |
| 255 | +} |
| 256 | +``` |
| 257 | + |
| 258 | +This ensures that whenever you build or start your app, your TypeScript types are perfectly synced with your YAML definitions. |
0 commit comments