diff --git a/src/shell.ts b/src/shell.ts index bfada13..6a95dd5 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -2,7 +2,7 @@ // runs commands and such. import type { CommandResult } from "./shared/types" -import { join, resolve } from "path" +import { join } from "path" import { NOSE_BIN } from "./config" import { isFile } from "./utils" @@ -23,14 +23,25 @@ export async function runCommand(input: string): Promise { output = errorMessage(err) } - console.log("cmd", cmd) - console.log("args", args) - return { status, output } } +async function exec(cmd: string, args: string[]): Promise<["ok" | "error", string]> { + const module = await import(commandPath(cmd) + "?t+" + Date.now()) + + if (!module || !module.default) { + return ["error", `${cmd} has no default export`] + } + + return ["ok", await module.default(...args)] +} + +function commandPath(cmd: string): string { + return join(NOSE_BIN, cmd + ".ts") +} + function commandExists(cmd: string): boolean { - return isFile(join(NOSE_BIN, cmd + ".ts")) + return isFile(commandPath(cmd)) } function errorMessage(error: Error | any): string { @@ -40,15 +51,4 @@ function errorMessage(error: Error | any): string { let msg = `${error.name}: ${error.message}` if (error.stack) msg += `\n${error.stack}` return msg -} - -async function exec(cmd: string, args: string[]): Promise<["ok" | "error", string]> { - const path = join(NOSE_BIN, cmd + ".ts") - const module = await import(path + "?t+" + Date.now()) - - if (!module || !module.default) { - return ["error", `${cmd} has no default export`] - } - - return ["ok", await module.default(...args)] } \ No newline at end of file