import { log } from "../../deps.js";
import { digestDir } from "./utils.js";
export function listSyncCodebases(options) {
    const res = [];
    const nb_codebase = options?.codebases?.length ?? 0;
    if (nb_codebase > 0) {
        log.info(`Found ${nb_codebase} codebases: ${options?.codebases?.map((c) => c.relative_path).join(", ")}`);
    }
    for (const codebase of options?.codebases ?? []) {
        let _digest = undefined;
        let alreadyPrinted = false;
        const getDigest = async (forceTar) => {
            if (_digest == undefined || forceTar) {
                _digest = await digestDir(codebase.relative_path, JSON.stringify(codebase));
                if (forceTar || (Array.isArray(codebase.assets) && codebase.assets.length > 0)) {
                    _digest += ".tar";
                }
                if (!alreadyPrinted) {
                    alreadyPrinted = true;
                    log.info(`Codebase ${codebase.relative_path}, digest: ${_digest}`);
                }
                return _digest;
            }
            return _digest;
        };
        res.push({ ...codebase, getDigest });
    }
    return res;
}
