"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadBundleDirectoryRecursive = uploadBundleDirectoryRecursive;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
/**
 * Upload all files under bundleDirectory into the session /mnt/data folder, preserving relative paths.
 */
async function uploadBundleDirectoryRecursive(client, bundleDirectory) {
    if (!node_fs_1.default.existsSync(bundleDirectory)) {
        throw new Error(`Bundle directory not found: ${bundleDirectory}`);
    }
    const uploaded = [];
    const walk = async (currentDir, relativePrefix) => {
        const entries = node_fs_1.default.readdirSync(currentDir, { withFileTypes: true });
        for (const entry of entries) {
            const absolutePath = node_path_1.default.join(currentDir, entry.name);
            const relativePath = relativePrefix ? `${relativePrefix}/${entry.name}` : entry.name;
            if (entry.isDirectory()) {
                if (entry.name === 'node_modules') {
                    continue;
                }
                await walk(absolutePath, relativePath);
                continue;
            }
            if (!entry.isFile()) {
                continue;
            }
            const content = node_fs_1.default.readFileSync(absolutePath);
            await client.uploadFile(relativePath.replace(/\\/g, '/'), content);
            uploaded.push(relativePath);
        }
    };
    await walk(bundleDirectory, '');
    if (uploaded.length === 0) {
        throw new Error(`No files found in bundle directory: ${bundleDirectory}`);
    }
    return uploaded;
}
//# sourceMappingURL=uploadBundleRecursive.js.map