controversial
This commit is contained in:
parent
66b4552def
commit
7ab885d658
27
nose/bin/ls.ts
Normal file
27
nose/bin/ls.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { readdirSync } from "fs"
|
||||||
|
import { NOSE_USR, NOSE_USR_WWW } from "@/config"
|
||||||
|
import { Thread } from "@/shell"
|
||||||
|
import { appPath } from "@/webapp"
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
const state = Thread.getStore()
|
||||||
|
if (!state) return "error: no state"
|
||||||
|
|
||||||
|
const project = state.project
|
||||||
|
if (!project) return "no project loaded"
|
||||||
|
|
||||||
|
const root = appPath(project)
|
||||||
|
if (!root) return "error loading project"
|
||||||
|
|
||||||
|
let files: string[] = []
|
||||||
|
|
||||||
|
for (const file of readdirSync(root, { withFileTypes: true })) {
|
||||||
|
files.push(file.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root === NOSE_USR_WWW) {
|
||||||
|
files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
|
||||||
|
}
|
||||||
|
|
||||||
|
return `* project: ${project}\n` + files.join(" ")
|
||||||
|
}
|
||||||
|
|
@ -97,4 +97,8 @@
|
||||||
|
|
||||||
#scrollback .input .content {
|
#scrollback .input .content {
|
||||||
margin-left: var(--cli-status-width);
|
margin-left: var(--cli-status-width);
|
||||||
|
}
|
||||||
|
|
||||||
|
#scrollback .output {
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +119,7 @@ app.get("/apps", c => {
|
||||||
app.get("/", c => c.html(<Layout><Terminal /></Layout>))
|
app.get("/", c => c.html(<Layout><Terminal /></Layout>))
|
||||||
|
|
||||||
//
|
//
|
||||||
// hot mode cleanup
|
// hot reload mode cleanup
|
||||||
//
|
//
|
||||||
|
|
||||||
if (process.env.BUN_HOT) {
|
if (process.env.BUN_HOT) {
|
||||||
|
|
@ -143,7 +143,6 @@ if (process.env.BUN_HOT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// server start
|
// server start
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { type Context, Hono } from "hono"
|
import { type Context, Hono } from "hono"
|
||||||
import type { Child } from "hono/jsx"
|
import type { Child } from "hono/jsx"
|
||||||
import { renderToString } from "hono/jsx/dom/server"
|
import { renderToString } from "hono/jsx/dom/server"
|
||||||
import { join } from "path"
|
import { join, dirname } from "path"
|
||||||
import { readdirSync, watch } from "fs"
|
import { readdirSync, watch } from "fs"
|
||||||
import { NOSE_USR_WWW, NOSE_SYS_WWW } from "./config"
|
import { NOSE_USR_WWW, NOSE_SYS_WWW } from "./config"
|
||||||
import { expectDir } from "./utils"
|
import { expectDir, isFile } from "./utils"
|
||||||
|
|
||||||
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
|
export type Handler = (r: Context) => string | Child | Response | Promise<Response>
|
||||||
export type App = Hono | Handler
|
export type App = Hono | Handler
|
||||||
|
|
@ -32,6 +32,22 @@ export function apps(): string[] {
|
||||||
return apps.sort()
|
return apps.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function appPath(name: string): string | undefined {
|
||||||
|
const path = [
|
||||||
|
`${name}.ts`,
|
||||||
|
`${name}.tsx`,
|
||||||
|
join(name, "index.ts"),
|
||||||
|
join(name, "index.tsx")
|
||||||
|
]
|
||||||
|
.map(path => [join(NOSE_SYS_WWW, path), join(NOSE_USR_WWW, path)])
|
||||||
|
.flat()
|
||||||
|
.filter(path => isFile(path))[0]
|
||||||
|
|
||||||
|
if (!path) return
|
||||||
|
|
||||||
|
return dirname(path)
|
||||||
|
}
|
||||||
|
|
||||||
async function findApp(name: string): Promise<App | undefined> {
|
async function findApp(name: string): Promise<App | undefined> {
|
||||||
const paths = [
|
const paths = [
|
||||||
`${name}.ts`,
|
`${name}.ts`,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user