This commit is contained in:
Chris Wanstrath 2025-09-20 19:21:16 -07:00
parent 8dc8cb65db
commit 55d81040c1

View File

@ -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<CommandResult> {
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)]
}