errors
This commit is contained in:
parent
8dc8cb65db
commit
55d81040c1
32
src/shell.ts
32
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<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 {
|
||||
|
|
@ -41,14 +52,3 @@ function errorMessage(error: Error | any): string {
|
|||
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)]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user