From c5bffe9d0c71342d8e96d2a066d645cfbabc32f9 Mon Sep 17 00:00:00 2001 From: Max Koon Date: Mon, 28 Oct 2024 09:07:10 -0400 Subject: [PATCH] feat: async functions --- packages/cli/package.json | 2 +- packages/cli/src/index.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 198cfcb..89c82cb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@koons/cli", - "version": "0.1.3", + "version": "0.1.4", "main": "./dist/index.js", "module": "./dist/index.mjs", "types": "./dist/index.d.ts", diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 57c9c2d..22fa5c5 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -23,7 +23,7 @@ class CommandBuilder { return new CommandBuilder>(this); } - fn(fn: (input: { input: T }) => void): BuildCommand { + fn(fn: (input: { input: T }) => Promise): BuildCommand { return { _type: "command", input: this.schema, @@ -41,7 +41,7 @@ interface BuildCommand { _type: "command"; input?: ZodSchema; description?: string; - fn: (input: { input: T }) => void; + fn: (input: { input: T }) => Promise; } export type Commands = { @@ -51,7 +51,7 @@ export type Commands = { export type CLI = BuildCommand | Commands; -function next(input: CLI, current: string | undefined, args: string[]) { +async function next(input: CLI, current: string | undefined, args: string[]) { if (!current) return commands(input); if (input._type == "cli") { @@ -75,10 +75,10 @@ function next(input: CLI, current: string | undefined, args: string[]) { return acc; }, {} as Record); - handler.fn({ input: obj }); + await handler.fn({ input: obj }); return; } else { - handler.fn({ input: {} }); + await handler.fn({ input: {} }); return; } } else { @@ -91,12 +91,12 @@ function next(input: CLI, current: string | undefined, args: string[]) { } } -export function run(input: CLI) { +export async function run(input: CLI) { const args = process.argv.slice(2); const current = args[0]; const commands = input; - next(commands, current, args); + await next(commands, current, args); } export const router = (commands: Commands["commands"]): Commands => {