loom serve -> loom dev + minor improvements

This commit is contained in:
EatThePooh 2025-10-16 10:50:11 +07:00
parent 67d13d8634
commit 58c98dce92
2 changed files with 58 additions and 1 deletions

56
platform/loom/cli/dev.ts Normal file
View file

@ -0,0 +1,56 @@
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",
},
});

View file

@ -1,9 +1,10 @@
import { buildApplication, buildRouteMap, run } from 'npm:@stricli/core';
import { command as serve } from './cli/serve.ts';
import { command as dev } from './cli/dev.ts';
import process from 'node:process';
const root = buildRouteMap({
routes: { serve },
routes: { dev },
docs: {
brief: "Grimu-R weaving companion CLI"
}