31 lines
728 B
TypeScript
31 lines
728 B
TypeScript
import { TextLineStream } from "./deps.ts";
|
|
|
|
export async function startFreshServer(options: Deno.CommandOptions) {
|
|
const serverProcess = new Deno.Command(Deno.execPath(), {
|
|
...options,
|
|
stdin: "null",
|
|
stdout: "piped",
|
|
stderr: "inherit",
|
|
}).spawn();
|
|
|
|
const decoder = new TextDecoderStream();
|
|
const lines: ReadableStream<string> = serverProcess.stdout
|
|
.pipeThrough(decoder)
|
|
.pipeThrough(new TextLineStream(), {
|
|
preventCancel: true,
|
|
});
|
|
|
|
let started = false;
|
|
for await (const line of lines) {
|
|
if (line.includes("Fresh ready")) {
|
|
started = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!started) {
|
|
throw new Error("Server didn't start up");
|
|
}
|
|
|
|
return { serverProcess, lines };
|
|
}
|