You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"@reliverse/rempts is a modern, type-safe toolkit for building delightful cli experiences. it's fast, flexible, and made for developer happiness. file-based commands keep things simple.",
Copy file name to clipboardExpand all lines: README.md
+213Lines changed: 213 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1210,6 +1210,219 @@ mycli --tags desktop
1210
1210
1211
1211
The validation happens after type casting, so for example with numbers, the input will first be converted to a number and then checked against the allowed list.
1212
1212
1213
+
## Typed Commands System
1214
+
1215
+
The typed commands system provides TypeScript intellisense and type safety for rempts launcher usage while maintaining dynamic code execution.
1216
+
1217
+
- 🎯 **TypeScript Intellisense**: Full autocomplete for command names and arguments
1218
+
- 🔒 **Type Safety**: Compile-time checking for argument types and required fields
1219
+
- ⚡ **Dynamic Execution**: Commands are still loaded and executed dynamically
1220
+
- 📝 **Automatic Sync**: Utility script to keep types in sync with actual command definitions
1221
+
1222
+
### Usage
1223
+
1224
+
#### Basic Usage
1225
+
1226
+
```typescript
1227
+
import { callCmd } from"~/app/cmds";
1228
+
1229
+
// Simple command with typed arguments
1230
+
awaitcallCmd("pub", { dev: true });
1231
+
1232
+
// Command with multiple arguments
1233
+
awaitcallCmd("check", {
1234
+
directory: "src",
1235
+
checks: "missing-deps,file-extensions",
1236
+
strict: true,
1237
+
json: false
1238
+
});
1239
+
1240
+
// Command with no arguments
1241
+
awaitcallCmd("update");
1242
+
1243
+
// Generators with typed arguments
1244
+
awaitcallCmd("rempts", {
1245
+
init: "new-cmd another-cmd",
1246
+
overwrite: true,
1247
+
outFile: "src/app/cmds.ts"
1248
+
});
1249
+
```
1250
+
1251
+
#### Advanced Usage
1252
+
1253
+
```typescript
1254
+
import { getTypedCmd } from"~/app/cmds";
1255
+
1256
+
// Get command instance for more control
1257
+
const { command, run } =awaitgetTypedCmd("magic");
When you type `callCmd("`, TypeScript will show all available commands.
1274
+
1275
+
##### 2. Argument Intellisense
1276
+
1277
+
When you type the arguments object, you get full autocomplete for:
1278
+
1279
+
- Argument names
1280
+
- Argument types
1281
+
- Required vs optional fields
1282
+
1283
+
##### 3. Type Validation
1284
+
1285
+
```typescript
1286
+
// ✅ Correct usage
1287
+
awaitcallCmd("create", {
1288
+
mode: "files", // Only "template" | "files" allowed
1289
+
multiple: true// boolean
1290
+
});
1291
+
1292
+
// ❌ TypeScript errors
1293
+
awaitcallCmd("create", {
1294
+
mode: "invalid", // Error: not assignable to type
1295
+
multiple: "yes"// Error: string not assignable to boolean
1296
+
});
1297
+
```
1298
+
1299
+
##### 4. Required Field Checking
1300
+
1301
+
```typescript
1302
+
// ✅ Required field provided
1303
+
awaitcallCmd("magic", {
1304
+
targets: ["dist-npm"] // Required field
1305
+
});
1306
+
1307
+
// ❌ TypeScript error: missing required field 'targets'
1308
+
awaitcallCmd("magic", {
1309
+
concurrency: 4
1310
+
});
1311
+
```
1312
+
1313
+
### Maintaining the System
1314
+
1315
+
#### Adding New Commands
1316
+
1317
+
1. Create your command in `src/app/<command-name>/cmd.ts` using `defineCommand` and `defineArgs`
1318
+
2. Run the generator: `dler rempts --overwrite`
1319
+
3. The `CommandArgsMap` interface in `src/app/cmds.ts` will be automatically updated
1320
+
1321
+
#### Manual Updates
1322
+
1323
+
The `CommandArgsMap` interface is auto-generated. If you need custom types, you can add manual type assertions (it is more recommended to edit your command file instead and regenerate the types):
0 commit comments