"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadFile = loadFile;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const { copyFile, rename, symlink, unlink } = fs_1.default.promises;
const { COPYFILE_EXCL } = fs_1.default.constants;
async function loadFile({ src, destDir, mode, subDir = '', force = false, }) {
    if (mode === 'inPlace') {
        return;
    }
    const dest = path_1.default.join(destDir, subDir, path_1.default.basename(src));
    if (force) {
        try {
            await unlink(dest);
        }
        catch (e) {
            if (e.code !== 'ENOENT') {
                throw e;
            }
        }
    }
    if (mode === 'copy') {
        return copyFile(src, dest, force ? 0 : COPYFILE_EXCL);
    }
    if (mode === 'move') {
        return rename(src, dest);
    }
    if (mode === 'symlink') {
        return symlink(path_1.default.resolve(src), dest);
    }
    return undefined;
}
