All files / backend/dist/services/workspace folder-helper.js

5.26% Statements 1/19
0% Branches 0/8
0% Functions 0/3
5.26% Lines 1/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                                                    1x        
/**
 * Folder Helper
 *
 * Utilities for building folder tree structures.
 */
import fs from 'fs-extra';
import path from 'path';
/**
 * Build a single level of the folder tree recursively
 */
async function buildTreeLevel(treeLevel, filePath, options = {}) {
    const files = await fs.readdir(filePath);
    const promises = [];
    for (const file of files) {
        const fullFilePath = path.join(filePath, file);
        promises.push(fs.lstat(fullFilePath).then(async (stat) => {
            // Apply filter if provided
            if (options.includeFunc !== undefined) {
                if (!options.includeFunc(fullFilePath, stat)) {
                    return;
                }
            }
            if (stat.isDirectory()) {
                const obj = { name: file, files: [] };
                treeLevel.push(obj);
                return buildTreeLevel(obj.files, fullFilePath, options);
            }
            else {
                const obj = { name: file };
                treeLevel.push(obj);
            }
        }));
    }
    await Promise.all(promises);
}
/**
 * Get a folder tree structure asynchronously
 * @param filePath - Root path to build tree from
 * @param options - Optional filter function
 * @returns Tree structure as array of TreeNode objects
 */
export async function getFolderTreeAsync(filePath, options = {}) {
    const treeRoot = [];
    await buildTreeLevel(treeRoot, filePath, options);
    return treeRoot;
}
/**
 * Legacy object-based interface for backward compatibility
 * @deprecated Use named exports instead
 */
export const folderHelper = {
    getFolderTreeAsync,
};
export default folderHelper;