|
| 1 | +# LT CLI Tool Reference |
| 2 | + |
| 3 | +## Overview |
| 4 | +The LT CLI is a globally installed code generation tool for TypeScript projects with server modules and objects. It provides commands for creating and modifying backend structures. |
| 5 | + |
| 6 | +## Available Commands |
| 7 | + |
| 8 | +### Create New Fullstack Workspace |
| 9 | +**Command:** `lt fullstack init` (alias: `lt full init`) |
| 10 | + |
| 11 | +**Purpose:** Creates a complete fullstack workspace with frontend (Angular/Nuxt), backend (NestJS), and proper project structure. |
| 12 | + |
| 13 | +**Usage:** |
| 14 | +```bash |
| 15 | +# Interactive mode (prompts for all inputs) |
| 16 | +lt fullstack init |
| 17 | + |
| 18 | +# Non-interactive mode with CLI arguments |
| 19 | +lt fullstack init --name <WorkspaceName> --frontend <angular|nuxt> --git <true|false> --git-link <GitURL> |
| 20 | +``` |
| 21 | + |
| 22 | +**Arguments:** |
| 23 | +- `--name` - Workspace name |
| 24 | +- `--frontend` - Frontend framework: "angular" or "nuxt" |
| 25 | +- `--git` - Initialize git repository: "true" or "false" |
| 26 | +- `--git-link` - Git repository URL (required when --git is true) |
| 27 | + |
| 28 | +**Examples:** |
| 29 | +```bash |
| 30 | +# Create workspace with Angular frontend, no git |
| 31 | +lt fullstack init --name MyApp --frontend angular --git false |
| 32 | + |
| 33 | +# Create workspace with Nuxt frontend and git repository |
| 34 | +lt fullstack init --name MyProject --frontend nuxt --git true --git-link https://github.com/user/my-project.git |
| 35 | + |
| 36 | +# Interactive mode (will prompt for inputs) |
| 37 | +lt fullstack init |
| 38 | +``` |
| 39 | + |
| 40 | +**What it creates:** |
| 41 | +- Clones the lt-monorepo template from GitHub |
| 42 | +- Sets up chosen frontend framework (Angular from ng-base-starter or Nuxt using create-nuxt-base) |
| 43 | +- Integrates NestJS server starter from nest-server-starter |
| 44 | +- Creates proper workspace structure with `/projects/app` and `/projects/api` |
| 45 | +- Configures meta.json and environment files |
| 46 | +- Replaces secret keys and project-specific configurations |
| 47 | +- Optionally initializes git repository with dev branch and pushes to remote |
| 48 | +- Installs all packages and runs initialization scripts |
| 49 | + |
| 50 | +### Create New Server Module |
| 51 | +**Command:** `lt server module` (alias: `lt server m`) |
| 52 | + |
| 53 | +**Purpose:** Creates a complete new server module with all necessary files (model, service, controller, resolver, inputs, outputs). |
| 54 | + |
| 55 | +**Usage:** |
| 56 | +```bash |
| 57 | +# Interactive mode (prompts for all inputs) |
| 58 | +lt server module |
| 59 | + |
| 60 | +# Non-interactive mode with CLI arguments |
| 61 | +lt server module --name <ModuleName> --controller <Rest|GraphQL|Both> [property-flags] |
| 62 | +``` |
| 63 | + |
| 64 | +**Arguments:** |
| 65 | +- `--name` - Module name (required) |
| 66 | +- `--controller` - Controller type: "Rest", "GraphQL", or "Both" (required) |
| 67 | +- `--skipLint` - Skip lint fix prompt (optional) |
| 68 | +- Property arguments (same as add-property command): |
| 69 | + - `--prop-name-X` - Property name (X = index: 0, 1, 2...) |
| 70 | + - `--prop-type-X` - Property type |
| 71 | + - `--prop-nullable-X` - "true" or "false" (default: false) |
| 72 | + - `--prop-array-X` - "true" or "false" (default: false) |
| 73 | + - `--prop-enum-X` - Enum type name |
| 74 | + - `--prop-schema-X` - Schema/object type name |
| 75 | + - `--prop-reference-X` - Reference type name for ObjectId properties |
| 76 | + |
| 77 | +**Examples:** |
| 78 | +```bash |
| 79 | +# Create User module with REST controller only |
| 80 | +lt server module --name User --controller Rest |
| 81 | + |
| 82 | +# Create Post module with both REST and GraphQL, with properties |
| 83 | +lt server module --name Post --controller Both \ |
| 84 | + --prop-name-0 title --prop-type-0 string \ |
| 85 | + --prop-name-1 content --prop-type-1 string --prop-nullable-1 true \ |
| 86 | + --prop-name-2 author --prop-type-2 ObjectId --prop-reference-2 User |
| 87 | + |
| 88 | +# Create Product module with GraphQL only and enum property |
| 89 | +lt server module --name Product --controller GraphQL \ |
| 90 | + --prop-name-0 status --prop-enum-0 ProductStatusEnum \ |
| 91 | + --prop-name-1 price --prop-type-1 number |
| 92 | + |
| 93 | +# Skip lint fix prompt |
| 94 | +lt server module --name Category --controller Both --skipLint |
| 95 | +``` |
| 96 | + |
| 97 | +**What it creates:** |
| 98 | +- `<module-name>.model.ts` - MongoDB schema with Mongoose decorators |
| 99 | +- `<module-name>.service.ts` - Business logic service |
| 100 | +- `<module-name>.controller.ts` - REST controller (if Rest or Both) |
| 101 | +- `<module-name>.resolver.ts` - GraphQL resolver (if GraphQL or Both) |
| 102 | +- `<module-name>.module.ts` - NestJS module configuration |
| 103 | +- `inputs/<module-name>.input.ts` - Input DTO for updates |
| 104 | +- `inputs/<module-name>-create.input.ts` - Input DTO for creation |
| 105 | +- `outputs/find-and-count-<module-name>s-result.output.ts` - Output DTO for pagination |
| 106 | +- Automatically integrates the module into `server.module.ts` |
| 107 | + |
| 108 | +### Add Properties to Modules/Objects |
| 109 | +**Command:** `lt server addProp` (alias: `lt server ap`) |
| 110 | + |
| 111 | +**Purpose:** Adds properties to existing modules or objects, updating model files, input files, and create input files automatically with UnifiedField decorators. |
| 112 | + |
| 113 | +**Usage:** |
| 114 | +```bash |
| 115 | +# Interactive mode (prompts for all inputs) |
| 116 | +lt server addProp |
| 117 | + |
| 118 | +# Non-interactive mode with CLI arguments |
| 119 | +lt server addProp --type <Module|Object> --element <name> [property-flags] |
| 120 | +``` |
| 121 | + |
| 122 | +**Arguments:** |
| 123 | +- `--type` - "Module" or "Object" (required) |
| 124 | +- `--element` - Name of the module/object to modify (required) |
| 125 | +- Property definitions (multiple properties supported): |
| 126 | + - `--prop-name-X` - Property name (X = index: 0, 1, 2...) |
| 127 | + - `--prop-type-X` - Property type (string, number, boolean, ObjectId, Json, etc.) |
| 128 | + - `--prop-nullable-X` - "true" or "false" (default: false) |
| 129 | + - `--prop-array-X` - "true" or "false" (default: false) |
| 130 | + - `--prop-enum-X` - Enum type name (e.g., "UserStatusEnum") |
| 131 | + - `--prop-schema-X` - Schema/object type name |
| 132 | + - `--prop-reference-X` - Reference type name for ObjectId properties |
| 133 | + |
| 134 | +**Examples:** |
| 135 | +```bash |
| 136 | +# Add email and age properties to User module |
| 137 | +lt server addProp --type Module --element User \ |
| 138 | + --prop-name-0 email --prop-type-0 string \ |
| 139 | + --prop-name-1 age --prop-type-1 number --prop-nullable-1 true |
| 140 | + |
| 141 | +# Add bio to Profile object |
| 142 | +lt server addProp --type Object --element Profile \ |
| 143 | + --prop-name-0 bio --prop-type-0 string --prop-nullable-0 true |
| 144 | + |
| 145 | +# Add array of tags to Post module |
| 146 | +lt server addProp --type Module --element Post \ |
| 147 | + --prop-name-0 tags --prop-type-0 string --prop-array-0 true |
| 148 | + |
| 149 | +# Add enum property to User module |
| 150 | +lt server addProp --type Module --element User \ |
| 151 | + --prop-name-0 status --prop-enum-0 UserStatusEnum |
| 152 | + |
| 153 | +# Add ObjectId reference to Post module |
| 154 | +lt server addProp --type Module --element Post \ |
| 155 | + --prop-name-0 author --prop-type-0 ObjectId --prop-reference-0 User |
| 156 | + |
| 157 | +# Add schema/object property to User module |
| 158 | +lt server addProp --type Module --element User \ |
| 159 | + --prop-name-0 profile --prop-schema-0 UserProfile |
| 160 | + |
| 161 | +# Add JSON field for metadata |
| 162 | +lt server addProp --type Module --element Product \ |
| 163 | + --prop-name-0 metadata --prop-type-0 Json --prop-nullable-0 true |
| 164 | +``` |
| 165 | + |
| 166 | +**What it does:** |
| 167 | +- Adds properties to `.model.ts` with `@Prop()` and `@UnifiedField()` decorators |
| 168 | +- Updates `.input.ts` with `@UnifiedField()` decorator for updates |
| 169 | +- Updates `-create.input.ts` with `@UnifiedField()` decorator for creation |
| 170 | +- Handles TypeScript typing with proper generics and suffixes |
| 171 | +- Automatically handles references (ObjectId → Reference for model, ReferenceInput for input) |
| 172 | +- Supports `useDefineForClassFields` TypeScript configuration |
| 173 | +- Prompts for lint fix after completion |
| 174 | +- Can cascade to create referenced modules/objects if they don't exist |
| 175 | + |
| 176 | +### Create New Server Object |
| 177 | +**Command:** `lt server object` (alias: `lt server o`) |
| 178 | + |
| 179 | +**Purpose:** Creates a new server object (shared data structure) with input DTOs for use across modules. |
| 180 | + |
| 181 | +**Usage:** |
| 182 | +```bash |
| 183 | +# Interactive mode (prompts for all inputs) |
| 184 | +lt server object |
| 185 | + |
| 186 | +# Non-interactive mode with CLI arguments |
| 187 | +lt server object --name <ObjectName> [property-flags] |
| 188 | +``` |
| 189 | + |
| 190 | +**Arguments:** |
| 191 | +- `--name` - Object name (required) |
| 192 | +- `--skipLint` - Skip lint fix prompt (optional) |
| 193 | +- Property definitions (multiple properties supported): |
| 194 | + - `--prop-name-X` - Property name (X = index: 0, 1, 2...) |
| 195 | + - `--prop-type-X` - Property type (string, number, boolean, ObjectId, Json, etc.) |
| 196 | + - `--prop-nullable-X` - "true" or "false" (default: false) |
| 197 | + - `--prop-array-X` - "true" or "false" (default: false) |
| 198 | + - `--prop-enum-X` - Enum type name (e.g., "StatusEnum") |
| 199 | + - `--prop-schema-X` - Schema/object type name |
| 200 | + - `--prop-reference-X` - Reference type name for ObjectId properties |
| 201 | + |
| 202 | +**Examples:** |
| 203 | +```bash |
| 204 | +# Create basic Address object |
| 205 | +lt server object --name Address |
| 206 | + |
| 207 | +# Create UserProfile object with properties |
| 208 | +lt server object --name UserProfile \ |
| 209 | + --prop-name-0 firstName --prop-type-0 string \ |
| 210 | + --prop-name-1 lastName --prop-type-1 string \ |
| 211 | + --prop-name-2 bio --prop-type-2 string --prop-nullable-2 true |
| 212 | + |
| 213 | +# Create Contact object with array and reference |
| 214 | +lt server object --name Contact \ |
| 215 | + --prop-name-0 emails --prop-type-0 string --prop-array-0 true \ |
| 216 | + --prop-name-1 owner --prop-type-1 ObjectId --prop-reference-1 User |
| 217 | + |
| 218 | +# Create Settings object with enum and JSON |
| 219 | +lt server object --name Settings \ |
| 220 | + --prop-name-0 theme --prop-enum-0 ThemeEnum \ |
| 221 | + --prop-name-1 preferences --prop-type-1 Json --prop-nullable-1 true |
| 222 | + |
| 223 | +# Skip lint fix |
| 224 | +lt server object --name Metadata --skipLint \ |
| 225 | + --prop-name-0 tags --prop-type-0 string --prop-array-0 true |
| 226 | +``` |
| 227 | + |
| 228 | +**What it creates:** |
| 229 | +- `<object-name>.object.ts` - Object class with UnifiedField decorators |
| 230 | +- `<object-name>.input.ts` - Input DTO for updates with validation |
| 231 | +- `<object-name>-create.input.ts` - Input DTO for creation with validation |
| 232 | +- All files in `src/server/common/objects/<object-name>/` directory |
| 233 | + |
| 234 | +**What it does:** |
| 235 | +- Creates reusable data structures that can be embedded in modules |
| 236 | +- Adds properties with `@UnifiedField()` decorators for GraphQL/REST APIs |
| 237 | +- Generates proper TypeScript typing with generics and suffixes |
| 238 | +- Supports `useDefineForClassFields` TypeScript configuration |
| 239 | +- Handles references (ObjectId → Reference for object, ReferenceInput for input) |
| 240 | +- Can cascade to create referenced modules/objects if they don't exist |
| 241 | +- Prompts for lint fix after completion (unless --skipLint is used) |
| 242 | + |
| 243 | +## Project Structure Requirements |
| 244 | +The LT CLI expects this file structure in your project: |
| 245 | +``` |
| 246 | +src/ |
| 247 | + server/ |
| 248 | + modules/ |
| 249 | + <ModuleName>/ |
| 250 | + <ModuleName>.model.ts |
| 251 | + inputs/ |
| 252 | + <ModuleName>.input.ts |
| 253 | + <ModuleName>-create.input.ts |
| 254 | + common/ |
| 255 | + objects/ |
| 256 | + <ObjectName>/ |
| 257 | + <ObjectName>.object.ts |
| 258 | + <ObjectName>.input.ts |
| 259 | + <ObjectName>-create.input.ts |
| 260 | +``` |
| 261 | + |
| 262 | +## Property Types Supported |
| 263 | +- **Primitive:** string, number, boolean, bigint, null, undefined, etc. |
| 264 | +- **Complex:** ObjectId (for references), JSON, custom schemas |
| 265 | +- **Arrays:** Any type can be an array with `--prop-array-X true` |
| 266 | +- **Nullable:** Any type can be nullable with `--prop-nullable-X true` |
| 267 | +- **Enums:** Custom enum references |
| 268 | + |
| 269 | +## What the Tool Does |
| 270 | +1. Parses arguments or runs interactive prompts |
| 271 | +2. Locates target files (model, input, create-input) |
| 272 | +3. Adds properties with proper TypeScript decorators (@Prop, @UnifiedField) |
| 273 | +4. Updates all relevant files maintaining proper structure |
| 274 | +5. Formats code automatically |
| 275 | +6. Optionally runs lint fixes |
| 276 | +7. Handles cascading references and objects |
| 277 | + |
| 278 | +## Usage Notes |
| 279 | +- **IMPORTANT:** Run commands from anywhere within your project directory |
| 280 | +- The CLI will locate the nearest `src/` directory above your current location and work from there |
| 281 | +- The CLI automatically handles TypeScript decorators and proper formatting with ts-morph |
| 282 | +- It maintains existing code structure and adds new properties appropriately |
| 283 | +- Interactive mode provides validation and helps with complex property types |
| 284 | +- CLI mode is better for automation and scripting scenarios |
| 285 | +- Both commands support cascading creation of referenced modules/objects |
| 286 | +- The module command automatically integrates new modules into `server.module.ts` |
| 287 | +- All commands offer optional lint fixing after completion |
| 288 | +- Always backup your code before running, as it modifies files directly |
| 289 | +- For fullstack init: Requires git to be installed and accessible via CLI |
| 290 | +- Commands use proper kebab-case for file naming and PascalCase for class names |
0 commit comments