diff --git a/nose/bin/ls.ts b/nose/bin/ls.ts index 66e7929..e5cf97a 100644 --- a/nose/bin/ls.ts +++ b/nose/bin/ls.ts @@ -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`)) } diff --git a/src/commands.ts b/src/commands.ts index e7e2eba..7237fe2 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -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 { - 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 { diff --git a/src/config.ts b/src/config.ts index f7d677e..cb1dcf9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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") \ No newline at end of file +export const NOSE_DIR = resolve(join(homedir, "nose")) +export const NOSE_BIN = join(NOSE_DIR, "bin") +export const NOSE_WWW = join(NOSE_DIR, "www") \ No newline at end of file diff --git a/src/server.tsx b/src/server.tsx index ec796fa..4ba0bfe 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -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, diff --git a/src/shell.ts b/src/shell.ts index 8bbc8b5..9a0c460 100644 --- a/src/shell.ts +++ b/src/shell.ts @@ -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 } diff --git a/src/webapp.ts b/src/webapp.ts index 3967cff..5796f0c 100644 --- a/src/webapp.ts +++ b/src/webapp.ts @@ -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 @@ -23,10 +23,7 @@ export async function serveApp(c: Context, subdomain: string): Promise 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 { 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)