run scripts from the backend

This commit is contained in:
Chris Wanstrath 2025-09-29 18:28:52 -07:00
parent a6bdd6bb29
commit da28a739df
3 changed files with 12 additions and 4 deletions

View File

@ -13,7 +13,10 @@ export default async function () {
if (/up to date/.test(out)) {
return "Up to date."
} else {
setTimeout(() => process.exit(), 1000)
return "Restarting in 1 second..."
setTimeout(() => process.exit(), 500)
return {
text: "Reloading in 3 seconds...",
script: `setTimeout(() => (window as any).location = window.location, 3000)`
}
}
}

View File

@ -124,8 +124,11 @@ function processOutput(output: CommandOutput): ["html" | "text", string] {
html = true
content = output.html
if (output.script) eval(output.script)
} else if ("text" in output) {
content = output.text
if (output.script) eval(output.script)
} else if ("script" in output) {
eval(output.script)
eval(output.script!)
} else {
content = JSON.stringify(output)
}

View File

@ -10,7 +10,9 @@ export type MessageType = "error" | "input" | "output" | "commands" | "save-file
| "stream:start" | "stream:end" | "stream:append" | "stream:replace"
export type CommandOutput = string | string[]
| { html: string, script?: string } | { script: string }
| { text: string, script?: string }
| { html: string, script?: string }
| { script: string }
| { game: string }
export type CommandResult = {