import { readdirSync } from 'node:fs';
import { join, relative, resolve, sep } from 'node:path';
const IGNORED_DIRECTORY_NAMES = new Set([
    '.git',
    '.nuxt',
    '.output',
    'build',
    'coverage',
    'dist',
    'node_modules'
]);
const toProjectId = (root, path) => relative(root, path).split(sep).join('/');
export const scanProjects = (rootDirectory) => {
    const root = resolve(rootDirectory);
    const projects = [];
    const queue = [root];
    while (queue.length > 0) {
        const current = queue.shift();
        const entries = readdirSync(current, { withFileTypes: true });
        if (entries.some(entry => entry.isDirectory() && entry.name === '.git')) {
            if (current !== root) {
                projects.push({
                    id: toProjectId(root, current),
                    path: current
                });
            }
            continue;
        }
        for (const entry of entries) {
            if (!entry.isDirectory()) {
                continue;
            }
            if (IGNORED_DIRECTORY_NAMES.has(entry.name)) {
                continue;
            }
            queue.push(join(current, entry.name));
        }
    }
    return projects.sort((left, right) => left.id.localeCompare(right.id));
};
