import fs from 'node:fs';
import path from 'node:path';
export function exists(caminho) {
    try {
        fs.statSync(caminho);
        return true;
    }
    catch {
        return false;
    }
}
export function readPackageJsonSync(pkgCaminho) {
    try {
        const data = fs.readFileSync(pkgCaminho, 'utf8');
        return JSON.parse(data);
    }
    catch {
        return null;
    }
}
export function findLicenseFile(dir) {
    try {
        const candidates = fs.readdirSync(dir).filter(arquivo => /^(license|licence|copying)/i.test(arquivo));
        if (!candidates.length)
            return null;
        const sorted = candidates.sort((arquivo, base) => arquivo.length - base.length);
        const file = sorted[0];
        const full = path.join(dir, file);
        try {
            const text = fs.readFileSync(full, 'utf8');
            if (text.length < 200 * 1024) {
                return {
                    file,
                    path: full,
                    text
                };
            }
        }
        catch { }
        return {
            file,
            path: full,
            text: null
        };
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=fs-utils.js.map