start moving to new project structure

This commit is contained in:
Chris Wanstrath 2025-10-01 20:43:58 -07:00
parent 89d850b55f
commit f9792eb31c
4 changed files with 24 additions and 26 deletions

View File

@ -4,23 +4,21 @@
import { mkdirSync, writeFileSync } from "fs" import { mkdirSync, writeFileSync } from "fs"
import { join } from "path" import { join } from "path"
import { apps } from "@/webapp" import { projects } from "@/project"
import { NOSE_WWW } from "@/config" import { NOSE_DIR } from "@/config"
import { isDir } from "@/utils"
import load from "./load" import load from "./load"
export default function (project: string) { export default function (project: string) {
if (!project) throw "usage: new <project name>" if (!project) throw "usage: new <project name>"
if (apps().includes(project)) throw `${project} already exists` if (projects().includes(project)) throw `${project} already exists`
if (!isDir(NOSE_WWW)) throw `no www dir! make one in a real shell:\n$ mkdir -p ${NOSE_WWW}` const dir = join(NOSE_DIR, project, "bin")
mkdirSync(dir, { recursive: true })
mkdirSync(join(NOSE_WWW, project)) writeFileSync(join(dir, `index.ts`), `export default (c: Context) =>\n "Hello, world!"`)
writeFileSync(join(NOSE_WWW, project, `index.ts`), `export default (c: Context) =>\n "Hello, world!"`)
load(project) load(project)
return `created ${project}` return `Created ${project}`
} }

View File

@ -1,10 +1,7 @@
// Print the currently loaded project. // Print the currently loaded project.
import { sessionGet } from "@/session" import { projectName } from "@/project"
export default function () { export default function () {
const state = sessionGet() return projectName()
if (!state) return { error: "no state" }
return state?.project || "none"
} }

View File

@ -1,13 +1,10 @@
// Show the projects on this NOSEputer. // Show the projects on this NOSEputer.
import { apps } from "@/webapp" import { projects, projectName } from "@/project"
import { sessionGet } from "@/session"
export default function () { export default function () {
const state = sessionGet() const project = projectName()
if (!state) return { error: "no state" }
return <> return <>
{apps().map(app => <a href={`#load ${app}`} class={app === state.project ? "magenta" : ""}>{app}</a>)} {projects().map(app => <a href={`#load ${app}`} class={app === project ? "magenta" : ""}>{app}</a>)}
</> </>
} }

View File

@ -1,9 +1,11 @@
//// ////
// Helpers for working with projects in the CLI. // Helpers for working with projects in the CLI.
import { join } from "path"
import { readdirSync, type Dirent } from "fs" import { readdirSync, type Dirent } from "fs"
import { sessionGet } from "./session" import { sessionGet } from "./session"
import { appDir } from "./webapp" import { NOSE_DIR } from "./config"
import { isDir } from "./utils"
export function projectName(): string { export function projectName(): string {
const state = sessionGet() const state = sessionGet()
@ -15,13 +17,17 @@ export function projectName(): string {
return project return project
} }
export function projectDir(): string { export function projects(): string[] {
const root = appDir(projectName()) return readdirSync(NOSE_DIR, { withFileTypes: true }).filter(file => file.isDirectory()).map(dir => dir.name)
if (!root) throw "error loading project" }
export function projectDir(name = projectName()): string {
const root = join(NOSE_DIR, name)
if (!isDir(root))
throw `no project found at ${root}`
return root return root
} }
export function projectFiles(): Dirent[] { export function projectFiles(name = projectName()): Dirent[] {
return readdirSync(projectDir(), { recursive: true, withFileTypes: true }) return readdirSync(projectDir(name), { recursive: true, withFileTypes: true })
} }