34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import * as path from 'node:path';
|
|
import * as fs from 'node:fs';
|
|
import * as fsPromises from 'node:fs/promises';
|
|
import * as smartpath from '@push.rocks/smartpath';
|
|
import * as smartfile from '@push.rocks/smartfile';
|
|
import * as smartrequest from '@push.rocks/smartrequest';
|
|
import * as smartstream from '@push.rocks/smartstream';
|
|
|
|
export { path, fs, fsPromises, smartpath, smartfile, smartrequest, smartstream };
|
|
|
|
/**
|
|
* List files in a directory recursively, returning relative paths
|
|
*/
|
|
export async function listFileTree(dirPath: string, _pattern: string = '**/*'): Promise<string[]> {
|
|
const results: string[] = [];
|
|
|
|
async function walkDir(currentPath: string, relativePath: string = '') {
|
|
const entries = await fsPromises.readdir(currentPath, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const entryRelPath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
const entryFullPath = path.join(currentPath, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
await walkDir(entryFullPath, entryRelPath);
|
|
} else if (entry.isFile()) {
|
|
results.push(entryRelPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
await walkDir(dirPath);
|
|
return results;
|
|
}
|