import { buildCommand, numberParser } from "npm:@stricli/core"; import express from 'npm:express'; type Flags = { readonly port: number; readonly hostname: string; readonly open: boolean; }; export const command = buildCommand({ func: (flags: Flags, _text: string) => { const port = flags.port; const hostname = flags.hostname; const open = flags.open; const app = express(); app.use(express.static(import.meta.dirname + '/../editor/dist')); app.listen(port, hostname, () => { let url: string = `http://${hostname}:${port}`; console.debug(`Express server running at ${url}`); if (open) { let o = (new Deno.Command("open", { args: [ url ]})).outputSync(); if (!o.success) { console.error("Failed to open the server URL"); } } }); }, parameters: { flags: { port: { brief: "Port to run the editor server on", kind: "parsed", parse: numberParser, default: "8066" }, hostname: { brief: "Host to run the editor server on", kind: "parsed", parse: String, default: "localhost" }, open: { brief: "Whether to open the server's URL", kind: "boolean", default: false } } }, docs: { brief: "Run an interactive editor server", }, });