import { existsSync } from 'node:fs';
import { mkdir, readdir, rename, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
export async function listDirectories(dirPath) {
    if (!existsSync(dirPath))
        return [];
    try {
        const entries = await readdir(dirPath, { withFileTypes: true });
        return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name);
    }
    catch (err) {
        if (err.code === 'ENOENT')
            return [];
        throw err;
    }
}
export async function ensureDirectoryWithGitkeep(dirPath) {
    await mkdir(dirPath, { recursive: true });
    await writeFile(join(dirPath, '.gitkeep'), '', 'utf-8');
}
export async function archiveDirectories(sourceDir, archiveDir, shouldArchive) {
    await mkdir(archiveDir, { recursive: true });
    const sourceDirs = await listDirectories(sourceDir);
    let archivedCount = 0;
    for (const dirName of sourceDirs) {
        if (!shouldArchive(dirName))
            continue;
        await rename(join(sourceDir, dirName), join(archiveDir, dirName));
        archivedCount++;
    }
    return archivedCount;
}
//# sourceMappingURL=phase-filesystem-adapter.js.map