"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.copyBundleSafe = copyBundleSafe;
const child_process_1 = require("child_process");
const fs_extra_1 = __importDefault(require("fs-extra"));
const logger_1 = require("./logger");
const logger = logger_1.Logger.getInstance("fs.helper");
/**
 * Safely copies a directory or file, preserving symlinks on macOS.
 *
 * On macOS, uses the native `cp -R` command which properly preserves symlinks
 * within .app bundles (critical for Electron Framework's versioned symlink structure).
 *
 * On Windows/other platforms, uses `fse.cpSync` which handles symlinks correctly
 * since Windows doesn't use the same symlink structure for app bundles.
 *
 * @param src - Source path to copy from
 * @param dest - Destination path to copy to
 * @throws Error if the copy operation fails
 */
function copyBundleSafe(src, dest) {
    if (process.platform === "darwin") {
        logger.debug(`Using cp -R to preserve symlinks: ${src} -> ${dest}`);
        try {
            (0, child_process_1.execSync)(`cp -R "${src}" "${dest}"`, { stdio: "pipe" });
        }
        catch (error) {
            throw new Error(`Failed to copy bundle with cp -R: ${error}`);
        }
    }
    else {
        logger.debug(`Using fse.cpSync: ${src} -> ${dest}`);
        fs_extra_1.default.cpSync(src, dest, { recursive: true });
    }
}
//# sourceMappingURL=fs.helper.js.map