project helpers

This commit is contained in:
Chris Wanstrath 2025-09-28 14:49:06 -07:00
parent 682e0c29f3
commit 9fe788a35f
4 changed files with 32 additions and 32 deletions

View File

@ -4,20 +4,13 @@ import { join, extname } from "path"
import type { CommandOutput } from "app/src/shared/types" import type { CommandOutput } from "app/src/shared/types"
import { NOSE_WWW } from "app/src/config" import { NOSE_WWW } from "app/src/config"
import { getState } from "@/session"
import { appDir } from "app/src/webapp"
import { isBinaryFile } from "app/src/utils" import { isBinaryFile } from "app/src/utils"
import { highlight } from "../lib/highlight" import { highlight } from "../lib/highlight"
import { projectName, projectDir } from "@/project"
export default async function (path: string) { export default async function (path: string) {
const state = getState() const project = projectName()
if (!state) return { error: "no state" } const root = projectDir()
const project = state.project
if (!project) return { error: "no project loaded" }
const root = appDir(project)
if (!root) return { error: "error loading project" }
let files: string[] = [] let files: string[] = []

View File

@ -1,23 +1,15 @@
import { escapeHTML } from "bun"
import { readdirSync } from "fs" import { readdirSync } from "fs"
import { join, extname } from "path" import { join, extname } from "path"
import type { CommandOutput } from "app/src/shared/types" import type { CommandOutput } from "app/src/shared/types"
import { NOSE_WWW } from "app/src/config" import { NOSE_WWW } from "app/src/config"
import { getState } from "@/session"
import { appDir } from "app/src/webapp"
import { isBinaryFile } from "app/src/utils" import { isBinaryFile } from "app/src/utils"
import { countChar } from "app/src/shared/utils" import { countChar } from "app/src/shared/utils"
import { projectName, projectDir } from "@/project"
export default async function (path: string) { export default async function (path: string) {
const state = getState() const project = projectName()
if (!state) return { error: "no state" } const root = projectDir()
const project = state.project
if (!project) return { error: "no project loaded" }
const root = appDir(project)
if (!root) return { error: "error loading project" }
let files: string[] = [] let files: string[] = []

View File

@ -1,22 +1,15 @@
import { readdirSync } from "fs" import { readdirSync } from "fs"
import { NOSE_WWW } from "app/src/config" import { NOSE_WWW } from "app/src/config"
import { getState } from "@/session" import { projectName, projectDir } from "@/project"
import { appDir } from "app/src/webapp"
export default function () { export default function () {
const state = getState() const project = projectName()
if (!state) return { error: "no state" } const root = projectDir()
const project = state.project
if (!project) return { error: "no project loaded" }
const root = appDir(project)
if (!root) return { error: "error loading project" }
let files: string[] = [] let files: string[] = []
for (const file of readdirSync(root, { withFileTypes: true })) { for (const file of readdirSync(root, { withFileTypes: true })) {
files.push(file.name) files.push(file.isDirectory() ? `${file.name}/` : file.name)
} }
if (root === NOSE_WWW) { if (root === NOSE_WWW) {

22
app/src/project.ts Normal file
View File

@ -0,0 +1,22 @@
////
// Helpers for working with projects in the CLI.
import { getState } from "./session"
import { appDir } from "./webapp"
export function projectName(): string {
const state = getState()
if (!state) throw "no state"
const project = state.project
if (!project) throw "no project loaded"
return project
}
export function projectDir(): string {
const root = appDir(projectName())
if (!root) throw "error loading project"
return root
}