@reliverse/rempts 1.7.31 → 1.7.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,6 +72,7 @@ export function defineCommand(options) {
72
72
  onCmdExit,
73
73
  onLauncherInit,
74
74
  onLauncherExit,
75
+ router: options.router,
75
76
  // Backward-compatible aliases
76
77
  setup: onCmdInit,
77
78
  cleanup: onCmdExit
@@ -427,6 +428,46 @@ export function createCli(options, legacyParserOptions) {
427
428
  });
428
429
  return;
429
430
  }
431
+ if (command.router) {
432
+ debugLog(
433
+ "Router detected in command, automatically enabling RPC mode..."
434
+ );
435
+ try {
436
+ require("tsx/cjs");
437
+ await import("tsx/esm");
438
+ debugLog("tsx loaded successfully for TypeScript support");
439
+ } catch {
440
+ debugLog("tsx not available, continuing without TypeScript support");
441
+ }
442
+ const getRouterMeta = (router) => {
443
+ if ("_def" in router && router._def && "meta" in router._def) {
444
+ return router._def.meta;
445
+ }
446
+ return void 0;
447
+ };
448
+ const routerMeta = getRouterMeta(command.router);
449
+ const rpcCli = createRpcCli({
450
+ router: command.router,
451
+ name: globalCliMeta.name || command.meta?.name || routerMeta?.name,
452
+ version: globalCliMeta.version || command.meta?.version || routerMeta?.version,
453
+ description: globalCliMeta.description || command.meta?.description || routerMeta?.description
454
+ });
455
+ debugLog(
456
+ "RPC CLI created from command router, running with argv:",
457
+ process.argv.slice(2)
458
+ );
459
+ await rpcCli.run({
460
+ argv: process.argv.slice(2),
461
+ logger: {
462
+ info: console.log,
463
+ error: console.error
464
+ },
465
+ process: {
466
+ exit: process.exit
467
+ }
468
+ });
469
+ return;
470
+ }
430
471
  if (typeof command.onLauncherInit === "function") {
431
472
  try {
432
473
  await command.onLauncherInit();
@@ -449,10 +490,10 @@ export function createCli(options, legacyParserOptions) {
449
490
  }
450
491
  const rawArgv = process.argv.slice(2);
451
492
  const autoExit = parserOptions.autoExit !== false;
452
- if (!(parserOptions.fileBased?.enable || command.commands && Object.keys(command.commands).length > 0 || command.run)) {
493
+ if (!(parserOptions.fileBased?.enable || command.commands && Object.keys(command.commands).length > 0 || command.run || command.router)) {
453
494
  relinka(
454
495
  "error",
455
- "Invalid CLI configuration: No file-based commands, subCommands, or run() handler are defined. This CLI will not do anything.\n\u2502 To fix: add file-based commands (./app), or provide at least one subCommand or a run() handler."
496
+ "Invalid CLI configuration: No file-based commands, subCommands, run() handler, or router are defined. This CLI will not do anything.\n\u2502 To fix: add file-based commands (./app), or provide at least one subCommand, a run() handler, or a router."
456
497
  );
457
498
  process.exit(1);
458
499
  }
@@ -827,7 +868,7 @@ async function runCommandWithArgs(command, argv, parserOptions, globalCliMeta, r
827
868
  if (command.run) {
828
869
  await command.run(ctx);
829
870
  } else {
830
- const isDispatcher = parserOptions.fileBased?.enable || command.commands && Object.keys(command.commands).length > 0;
871
+ const isDispatcher = parserOptions.fileBased?.enable || command.commands && Object.keys(command.commands).length > 0 || command.router;
831
872
  const noSubcommandArgInCurrentCall = !argv.some((arg) => !isFlag(arg));
832
873
  if (isDispatcher && noSubcommandArgInCurrentCall) {
833
874
  relinka("warn", "Please specify a command");
@@ -1,3 +1,4 @@
1
+ import type { AnyRouter } from "./trpc-orpc-support/trpc-compat.js";
1
2
  export type EmptyArgs = Record<string, never>;
2
3
  export interface BaseArgProps {
3
4
  description?: string;
@@ -99,6 +100,11 @@ export interface DefineCommandOptions<A extends ArgDefinitions = EmptyArgs> {
99
100
  * Called once per CLI process, after all command/run() logic is finished
100
101
  */
101
102
  onLauncherExit?: () => void | Promise<void>;
103
+ /**
104
+ * tRPC/oRPC router for RPC mode. When provided, the command will automatically
105
+ * switch to RPC mode and use the router's procedures as CLI commands.
106
+ */
107
+ router?: AnyRouter;
102
108
  }
103
109
  export interface Command<A extends ArgDefinitions = EmptyArgs> {
104
110
  meta?: CommandMeta;
@@ -136,6 +142,11 @@ export interface Command<A extends ArgDefinitions = EmptyArgs> {
136
142
  * Called once per CLI process, after all command/run() logic is finished
137
143
  */
138
144
  onLauncherExit?: () => void | Promise<void>;
145
+ /**
146
+ * tRPC/oRPC router for RPC mode. When provided, the command will automatically
147
+ * switch to RPC mode and use the router's procedures as CLI commands.
148
+ */
149
+ router?: AnyRouter;
139
150
  }
140
151
  export type InferArgTypes<A extends ArgDefinitions> = {
141
152
  [K in keyof A]: A[K] extends PositionalArgDefinition ? string : A[K] extends BooleanArgDefinition ? boolean : A[K] extends StringArgDefinition ? string : A[K] extends NumberArgDefinition ? number : A[K] extends {
package/bin/types.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface PromptOptions {
26
26
  contentVariant?: VariantName;
27
27
  hint?: string;
28
28
  placeholder?: string;
29
- validate?: (value: any) => boolean | string | Promise<boolean | string>;
29
+ validate?: (value: any) => boolean | string | undefined | Promise<boolean | string | undefined>;
30
30
  defaultColor?: ColorName;
31
31
  defaultTypography?: TypographyName;
32
32
  choices?: ChoiceOptions[];
package/package.json CHANGED
@@ -44,7 +44,7 @@
44
44
  "license": "MIT",
45
45
  "name": "@reliverse/rempts",
46
46
  "type": "module",
47
- "version": "1.7.31",
47
+ "version": "1.7.33",
48
48
  "author": "reliverse",
49
49
  "bugs": {
50
50
  "email": "blefnk@gmail.com",