This commit is contained in:
seb
2026-09-22 19:21:14 +02:00
parent d74ca40076
commit eb885621c7
5 changed files with 276 additions and 5 deletions

View File

@@ -47,9 +47,11 @@ export function buildIgnoreFilter(dir) {
* Returns { entries: Array<{path,type,size}>, total, truncated }
* - type: 'd' for directory, 'f' for file
* - size: file size in bytes (null for directories)
* Dot-directories (names starting with '.', e.g. .git) are skipped unless
* `includeDotDirs` is true.
* All paths are relative to ROOT_DIR and use forward slashes.
*/
export function listDir(dir, { seek = 0, limit = 50, recursive = false } = {}) {
export function listDir(dir, { seek = 0, limit = 50, recursive = false, includeDotDirs = false } = {}) {
const ig = buildIgnoreFilter(dir);
const allEntries = [];
@@ -61,6 +63,8 @@ export function listDir(dir, { seek = 0, limit = 50, recursive = false } = {}) {
return;
}
for (const e of entries) {
// Skip dot-directories (e.g. .git) by default.
if (e.isDirectory() && e.name.startsWith('.') && !includeDotDirs) continue;
const full = path.join(current, e.name);
const rel = path.relative(ROOT_DIR, full).replace(/\\/g, '/');
if (ig.ignores(e.isDirectory() ? rel + '/' : rel)) continue;