Compare commits
2 Commits
c411678db2
...
da28a739df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da28a739df | ||
|
|
a6bdd6bb29 |
|
|
@ -13,7 +13,10 @@ export default async function () {
|
||||||
if (/up to date/.test(out)) {
|
if (/up to date/.test(out)) {
|
||||||
return "Up to date."
|
return "Up to date."
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => process.exit(), 1000)
|
setTimeout(() => process.exit(), 500)
|
||||||
return "Restarting in 1 second..."
|
return {
|
||||||
|
text: "Reloading in 3 seconds...",
|
||||||
|
script: `setTimeout(() => (window as any).location = window.location, 3000)`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// The scrollback shows your history of interacting with the shell.
|
// The scrollback shows your history of interacting with the shell.
|
||||||
// input, output, etc
|
// input, output, etc
|
||||||
|
|
||||||
import { scrollback, $, $$ } from "./dom.js"
|
import { scrollback, $$ } from "./dom.js"
|
||||||
import { randomId } from "../shared/utils.js"
|
import { randomId } from "../shared/utils.js"
|
||||||
import type { CommandOutput } from "../shared/types.js"
|
import type { CommandOutput } from "../shared/types.js"
|
||||||
|
|
||||||
|
|
@ -123,6 +123,12 @@ function processOutput(output: CommandOutput): ["html" | "text", string] {
|
||||||
} else if ("html" in output) {
|
} else if ("html" in output) {
|
||||||
html = true
|
html = true
|
||||||
content = output.html
|
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!)
|
||||||
} else {
|
} else {
|
||||||
content = JSON.stringify(output)
|
content = JSON.stringify(output)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ export type MessageType = "error" | "input" | "output" | "commands" | "save-file
|
||||||
| "game:start"
|
| "game:start"
|
||||||
| "stream:start" | "stream:end" | "stream:append" | "stream:replace"
|
| "stream:start" | "stream:end" | "stream:append" | "stream:replace"
|
||||||
|
|
||||||
export type CommandOutput = string | string[] | { html: string } | { game: string }
|
export type CommandOutput = string | string[]
|
||||||
|
| { text: string, script?: string }
|
||||||
|
| { html: string, script?: string }
|
||||||
|
| { script: string }
|
||||||
|
| { game: string }
|
||||||
|
|
||||||
export type CommandResult = {
|
export type CommandResult = {
|
||||||
status: "ok" | "error"
|
status: "ok" | "error"
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,11 @@ export function processExecOutput(output: string | any): ["ok" | "error", Comman
|
||||||
} else if (typeof output === "object") {
|
} else if (typeof output === "object") {
|
||||||
if (output.error) {
|
if (output.error) {
|
||||||
return ["error", output.error]
|
return ["error", output.error]
|
||||||
} else if (output.tag && output.props && output.children) {
|
} else if (isJSX(output)) {
|
||||||
return ["ok", { html: output.toString() }]
|
return ["ok", { html: output.toString() }]
|
||||||
|
} else if (output.html && isJSX(output.html)) {
|
||||||
|
output.html = output.html.toString()
|
||||||
|
return ["ok", output]
|
||||||
} else {
|
} else {
|
||||||
return ["ok", output]
|
return ["ok", output]
|
||||||
}
|
}
|
||||||
|
|
@ -78,3 +81,7 @@ function errorMessage(error: Error | any): string {
|
||||||
if (error.stack) msg += `\n${error.stack}`
|
if (error.stack) msg += `\n${error.stack}`
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isJSX(obj: any): boolean {
|
||||||
|
return 'tag' in obj && 'props' in obj && 'children' in obj
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user