u
This commit is contained in:
@@ -81,3 +81,35 @@ export function listDir(dir, { seek = 0, limit = 50, recursive = false } = {}) {
|
||||
const truncated = total - (seek + sliced.length);
|
||||
return { entries: sliced, total, truncated: Math.max(0, truncated) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively walk the *files* under `dir`, honoring .gitignore rules
|
||||
* (including nested .gitignore files) plus the hardcoded node_modules rule.
|
||||
* Returns an array of { abs, rel } where `rel` is relative to ROOT_DIR using
|
||||
* forward slashes. Symlinks are skipped to avoid loops.
|
||||
*/
|
||||
export function walkFiles(dir) {
|
||||
const results = [];
|
||||
const walk = (current) => {
|
||||
// Rebuild per directory so nested .gitignore files apply to their subtree.
|
||||
const ig = buildIgnoreFilter(current);
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(current, { withFileTypes: true });
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
for (const e of entries) {
|
||||
const full = path.join(current, e.name);
|
||||
const rel = path.relative(ROOT_DIR, full).replace(/\\/g, '/');
|
||||
if (ig.ignores(e.isDirectory() ? rel + '/' : rel)) continue;
|
||||
if (e.isDirectory()) {
|
||||
walk(full);
|
||||
} else if (e.isFile()) {
|
||||
results.push({ abs: full, rel });
|
||||
}
|
||||
}
|
||||
};
|
||||
walk(dir);
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user