slightly better logging

This commit is contained in:
Chris Wanstrath 2025-10-10 16:00:38 -07:00
parent 6361316f14
commit 9c2550150b
4 changed files with 14 additions and 8 deletions

View File

@ -237,9 +237,6 @@ if (process.env.NODE_ENV === "production") {
}
await initNoseDir()
initCommands()
await initWebapps()
initSneakers()
console.log(color.cyan(NOSE_ICON))
console.log(color.blue(" BUN_BIN:"), color.yellow(tilde(BUN_BIN)))
@ -248,6 +245,10 @@ console.log(color.blue(" NOSE_DATA:"), color.yellow(tilde(NOSE_DATA)))
console.log(color.blue(" NOSE_DIR:"), color.yellow(tilde(NOSE_DIR)))
console.log(color.blue("NOSE_ROOT_BIN:"), color.yellow(tilde(NOSE_ROOT_BIN)))
initCommands()
await initWebapps()
initSneakers()
export default {
port: process.env.PORT || 3000,
hostname: "0.0.0.0",

View File

@ -9,7 +9,7 @@ import { sendAll } from "../websocket"
import { expectDir } from "../utils"
import { NOSE_DIR, BUN_BIN } from "../config"
import { isFile } from "../utils"
import { apps, isApp, appDir, isStaticApp } from "./utils"
import { apps, isApp, appDir, isStaticApp, webappLog } from "./utils"
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
export type App = Hono | Handler
@ -80,7 +80,7 @@ function serveStatic(path: string): Response {
async function shutdown() {
for (const [name, { port, proc }] of processes) {
console.log(`Shutting down ${name}`)
webappLog(name, "Shutting down")
try { proc.kill() } catch { }
}
process.exit(0)
@ -90,7 +90,7 @@ async function restartApp(name: string) {
if (restarting.has(name)) return
restarting.add(name)
console.log(`[child:${name}]`, "restarting")
webappLog(name, "restarting")
const existing = processes.get(name)
if (existing) {
try { existing.proc.kill() } catch { }

View File

@ -1,5 +1,6 @@
import { join } from "path"
import { readdirSync } from "fs"
import color from "kleur"
import type { Child } from "hono/jsx"
import { NOSE_DIR } from "../config"
import { isFile, isDir } from "../utils"
@ -50,4 +51,8 @@ export function isStaticApp(name: string): boolean {
export function appDir(name: string): string | undefined {
if (isApp(name))
return join(NOSE_DIR, name)
}
export function webappLog(appName: string, msg: string) {
console.log(color.green(`[webapp:${appName}]`), msg)
}

View File

@ -2,7 +2,7 @@
// This is the child process that runs a single webapp.
import { Hono } from "hono"
import { appPath, toResponse } from "./utils"
import { appPath, toResponse, webappLog } from "./utils"
const appName = Bun.argv[2]
if (!appName) {
@ -23,4 +23,4 @@ app.all("*", async c => toResponse(await handler(c)))
const port = Number(process.env.PORT || 4000)
Bun.serve({ port, fetch: app.fetch })
console.log(`[child:${appName}] listening on localhost:${port}`)
webappLog(appName, `listening on localhost:${port}`)