no NOSE_SYS_WWW

This commit is contained in:
Chris Wanstrath 2025-09-21 11:34:04 -07:00
parent 9a938ee769
commit d52341049f
6 changed files with 20 additions and 39 deletions

View File

@ -1,5 +1,5 @@
import { readdirSync } from "fs"
import { NOSE_USR, NOSE_USR_WWW } from "@/config"
import { NOSE_DIR, NOSE_WWW } from "@/config"
import { Thread } from "@/shell"
import { appPath } from "@/webapp"
@ -19,7 +19,7 @@ export default function () {
files.push(file.name)
}
if (root === NOSE_USR_WWW) {
if (root === NOSE_WWW) {
files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
}

View File

@ -1,6 +1,6 @@
import { Glob } from "bun"
import { watch } from "fs"
import { NOSE_SYS_BIN, NOSE_USR_BIN } from "./config"
import { NOSE_SYS_BIN, NOSE_BIN } from "./config"
import { sendAll } from "./websocket"
import { expectDir } from "./utils"
@ -8,13 +8,13 @@ const sysCmdWatcher = watch(NOSE_SYS_BIN, async (event, filename) =>
sendAll({ type: "commands", data: await commands() })
)
expectDir(NOSE_USR_BIN)
const usrCmdWatcher = watch(NOSE_USR_BIN, async (event, filename) => {
expectDir(NOSE_BIN)
const usrCmdWatcher = watch(NOSE_BIN, async (event, filename) => {
sendAll({ type: "commands", data: await commands() })
})
export async function commands(): Promise<string[]> {
return (await findCommands(NOSE_SYS_BIN)).concat(await findCommands(NOSE_USR_BIN))
return (await findCommands(NOSE_SYS_BIN)).concat(await findCommands(NOSE_BIN))
}
export async function findCommands(path: string): Promise<string[]> {

View File

@ -4,9 +4,8 @@ export const NOSE_ICON = ` ͡° ͜ʖ ͡°`
export const NOSE_SYS = resolve("./nose")
export const NOSE_SYS_BIN = join(NOSE_SYS, "bin")
export const NOSE_SYS_WWW = join(NOSE_SYS, "www")
const homedir = process.platform === "darwin" ? `/Users/${process.env.USER}` : `/home/${process.env.USER}`
export const NOSE_USR = resolve(join(homedir, "nose"))
export const NOSE_USR_BIN = join(NOSE_USR, "bin")
export const NOSE_USR_WWW = join(NOSE_USR, "www")
export const NOSE_DIR = resolve(join(homedir, "nose"))
export const NOSE_BIN = join(NOSE_DIR, "bin")
export const NOSE_WWW = join(NOSE_DIR, "www")

View File

@ -4,7 +4,7 @@ import { prettyJSON } from "hono/pretty-json"
import color from "kleur"
import type { Message } from "./shared/types"
import { NOSE_ICON, NOSE_USR_BIN, NOSE_USR_WWW } from "./config"
import { NOSE_ICON, NOSE_BIN, NOSE_WWW } from "./config"
import { transpile, isFile, tilde } from "./utils"
import { apps, serveApp, publishDNS } from "./webapp"
import { runCommand } from "./shell"
@ -148,8 +148,8 @@ if (process.env.BUN_HOT) {
//
console.log(color.cyan(NOSE_ICON))
console.log(color.blue("NOSE_USR_BIN:"), color.yellow(tilde(NOSE_USR_BIN)))
console.log(color.blue("NOSE_USR_WWW:"), color.yellow(tilde(NOSE_USR_WWW)))
console.log(color.blue("NOSE_BIN:"), color.yellow(tilde(NOSE_BIN)))
console.log(color.blue("NOSE_WWW:"), color.yellow(tilde(NOSE_WWW)))
export default {
port: process.env.PORT || 3000,

View File

@ -3,7 +3,7 @@
import type { CommandResult } from "./shared/types"
import { join } from "path"
import { NOSE_SYS_BIN, NOSE_USR_BIN } from "./config"
import { NOSE_SYS_BIN, NOSE_BIN } from "./config"
import { isFile } from "./utils"
import { AsyncLocalStorage } from "async_hooks"
@ -58,7 +58,7 @@ async function exec(cmd: string, args: string[]): Promise<["ok" | "error", strin
function commandPath(cmd: string): string | undefined {
const sysPath = join(NOSE_SYS_BIN, cmd + ".ts")
const usrPath = join(NOSE_USR_BIN, cmd + ".ts")
const usrPath = join(NOSE_BIN, cmd + ".ts")
return (isFile(sysPath) && sysPath) || (isFile(usrPath) && usrPath) || undefined
}

View File

@ -3,7 +3,7 @@ import type { Child } from "hono/jsx"
import { renderToString } from "hono/jsx/dom/server"
import { join, dirname } from "path"
import { readdirSync, watch } from "fs"
import { NOSE_USR_WWW, NOSE_SYS_WWW } from "./config"
import { NOSE_WWW } from "./config"
import { expectDir, isFile } from "./utils"
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
@ -23,10 +23,7 @@ export async function serveApp(c: Context, subdomain: string): Promise<Response>
export function apps(): string[] {
const apps: string[] = []
for (const entry of readdirSync(NOSE_SYS_WWW))
apps.push(entry.replace(/\.tsx?/, ""))
for (const entry of readdirSync(NOSE_USR_WWW))
for (const entry of readdirSync(NOSE_WWW))
apps.push(entry.replace(/\.tsx?/, ""))
return apps.sort()
@ -39,7 +36,7 @@ export function appPath(name: string): string | undefined {
join(name, "index.ts"),
join(name, "index.tsx")
]
.map(path => [join(NOSE_SYS_WWW, path), join(NOSE_USR_WWW, path)])
.map(path => join(NOSE_WWW, path))
.flat()
.filter(path => isFile(path))[0]
@ -59,12 +56,7 @@ async function findApp(name: string): Promise<App | undefined> {
let app
for (const path of paths) {
app = await loadApp(join(NOSE_SYS_WWW, path))
if (app) return app
}
for (const path of paths) {
app = await loadApp(join(NOSE_USR_WWW, path))
app = await loadApp(join(NOSE_WWW, path))
if (app) return app
}
@ -126,20 +118,10 @@ function publishAppDNS(app: string) {
return dnsEntries[app]
}
const sysAppWatcher = watch(NOSE_SYS_WWW, (event, filename) => {
const www = apps()
www.forEach(publishAppDNS)
for (const name in dnsEntries)
if (!www.includes(name)) {
dnsEntries[name].kill("SIGTERM")
delete dnsEntries[name]
}
})
// exit process with error if no WWW dir
expectDir(NOSE_USR_WWW)
expectDir(NOSE_WWW)
const usrAppWatcher = watch(NOSE_USR_WWW, (event, filename) => {
const wwwWatcher = watch(NOSE_WWW, (event, filename) => {
const www = apps()
www.forEach(publishAppDNS)
for (const name in dnsEntries)