* Create a CLI runner that executes commands against a running server. * Uses trpc-cli's programmatic API to avoid subprocess overhead.
(baseUrl: string, authToken?: string)
| 84 | * Uses trpc-cli's programmatic API to avoid subprocess overhead. |
| 85 | */ |
| 86 | function createCliRunner(baseUrl: string, authToken?: string) { |
| 87 | const proxiedRouter = proxifyOrpc(router(), { baseUrl, authToken }); |
| 88 | const cli = createCli({ router: proxiedRouter }); |
| 89 | |
| 90 | return async (args: string[]): Promise<unknown> => { |
| 91 | return cli |
| 92 | .run({ |
| 93 | argv: args, |
| 94 | process: { exit: () => void 0 as never }, |
| 95 | // eslint-disable-next-line @typescript-eslint/no-empty-function |
| 96 | logger: { info: () => {}, error: () => {} }, |
| 97 | }) |
| 98 | .catch((err) => { |
| 99 | // Extract the result or re-throw the actual error |
| 100 | while (err instanceof FailedToExitError) { |
| 101 | if (err.exitCode === 0) { |
| 102 | return err.cause; // This is the return value of the procedure |
| 103 | } |
| 104 | err = err.cause; // Use the underlying error |
| 105 | } |
| 106 | throw err; |
| 107 | }); |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | // --- Tests --- |
| 112 |
no test coverage detected