feat: include ignored files

This commit is contained in:
Adam
2025-08-28 10:49:40 -05:00
parent 4331d77b9e
commit aa9ab0a304
4 changed files with 24 additions and 8 deletions

View File

@@ -41,6 +41,7 @@
"gray-matter": "4.0.3",
"hono": "catalog:",
"hono-openapi": "0.4.8",
"ignore": "7.0.5",
"isomorphic-git": "1.32.1",
"jsonc-parser": "3.3.1",
"minimatch": "10.0.3",

View File

@@ -6,6 +6,7 @@ import path from "path"
import * as git from "isomorphic-git"
import { App } from "../app/app"
import fs from "fs"
import ignore from "ignore"
import { Log } from "../util/log"
export namespace File {
@@ -29,6 +30,7 @@ export namespace File {
name: z.string(),
path: z.string(),
type: z.enum(["file", "directory"]),
ignored: z.boolean(),
})
.openapi({
ref: "FileNode",
@@ -133,18 +135,29 @@ export namespace File {
}
export async function list(dir?: string) {
const ignore = [".git", ".DS_Store"]
const exclude = [".git", ".DS_Store"]
const app = App.info()
let ignored = (_: string) => false
if (app.git) {
const gitignore = Bun.file(path.join(app.path.root, ".gitignore"))
if (await gitignore.exists()) {
const ig = ignore().add(await gitignore.text())
ignored = ig.ignores.bind(ig)
}
}
const resolved = dir ? path.join(app.path.cwd, dir) : app.path.cwd
const nodes: Node[] = []
for (const entry of await fs.promises.readdir(resolved, { withFileTypes: true })) {
if (ignore.includes(entry.name)) continue
if (exclude.includes(entry.name)) continue
const fullPath = path.join(resolved, entry.name)
const relativePath = path.relative(app.path.cwd, fullPath)
const relativeToRoot = path.relative(app.path.root, fullPath)
const type = entry.isDirectory() ? "directory" : "file"
nodes.push({
name: entry.name,
path: relativePath,
type: entry.isDirectory() ? "directory" : "file",
type,
ignored: ignored(type === "directory" ? relativeToRoot + "/" : relativeToRoot),
})
}
return nodes.sort((a, b) => {