"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MakerSquirrel = void 0;
const path_1 = __importDefault(require("path"));
const maker_base_1 = require("@electron-forge/maker-base");
const electron_winstaller_1 = require("electron-winstaller");
const fs_extra_1 = __importDefault(require("fs-extra"));
class MakerSquirrel extends maker_base_1.MakerBase {
    constructor() {
        super(...arguments);
        this.name = 'squirrel';
        this.defaultPlatforms = ['win32'];
    }
    isSupportedOnCurrentPlatform() {
        return this.isInstalled('electron-winstaller') && !process.env.DISABLE_SQUIRREL_TEST;
    }
    async make({ dir, makeDir, targetArch, packageJSON, appName, forgeConfig }) {
        const outPath = path_1.default.resolve(makeDir, `squirrel.windows/${targetArch}`);
        await this.ensureDirectory(outPath);
        const winstallerConfig = {
            name: typeof packageJSON.name === 'string' ? packageJSON.name.replace(/-/g, '_') : undefined,
            title: appName,
            noMsi: true,
            exe: `${forgeConfig.packagerConfig.executableName || appName}.exe`,
            setupExe: `${appName}-${packageJSON.version} Setup.exe`,
            ...this.config,
            appDirectory: dir,
            outputDirectory: outPath,
        };
        await (0, electron_winstaller_1.createWindowsInstaller)(winstallerConfig);
        const nupkgVersion = (0, electron_winstaller_1.convertVersion)(packageJSON.version);
        const artifacts = [
            path_1.default.resolve(outPath, 'RELEASES'),
            path_1.default.resolve(outPath, winstallerConfig.setupExe || `${appName}Setup.exe`),
            path_1.default.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-full.nupkg`),
        ];
        const deltaPath = path_1.default.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-delta.nupkg`);
        if ((winstallerConfig.remoteReleases && !winstallerConfig.noDelta) || (await fs_extra_1.default.pathExists(deltaPath))) {
            artifacts.push(deltaPath);
        }
        const msiPath = path_1.default.resolve(outPath, winstallerConfig.setupMsi || `${appName}Setup.msi`);
        if (!winstallerConfig.noMsi && (await fs_extra_1.default.pathExists(msiPath))) {
            artifacts.push(msiPath);
        }
        return artifacts;
    }
}
exports.default = MakerSquirrel;
exports.MakerSquirrel = MakerSquirrel;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFrZXJTcXVpcnJlbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9NYWtlclNxdWlycmVsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLGdEQUF3QjtBQUV4QiwyREFBcUU7QUFFckUsNkRBQW1IO0FBQ25ILHdEQUEwQjtBQUkxQixNQUFxQixhQUFjLFNBQVEsc0JBQThCO0lBQXpFOztRQUNFLFNBQUksR0FBRyxVQUFVLENBQUM7UUFFbEIscUJBQWdCLEdBQW9CLENBQUMsT0FBTyxDQUFDLENBQUM7SUF3Q2hELENBQUM7SUF0Q0MsNEJBQTRCO1FBQzFCLE9BQU8sSUFBSSxDQUFDLFdBQVcsQ0FBQyxxQkFBcUIsQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxxQkFBcUIsQ0FBQztJQUN2RixDQUFDO0lBRUQsS0FBSyxDQUFDLElBQUksQ0FBQyxFQUFFLEdBQUcsRUFBRSxPQUFPLEVBQUUsVUFBVSxFQUFFLFdBQVcsRUFBRSxPQUFPLEVBQUUsV0FBVyxFQUFnQjtRQUN0RixNQUFNLE9BQU8sR0FBRyxjQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxvQkFBb0IsVUFBVSxFQUFFLENBQUMsQ0FBQztRQUN4RSxNQUFNLElBQUksQ0FBQyxlQUFlLENBQUMsT0FBTyxDQUFDLENBQUM7UUFFcEMsTUFBTSxnQkFBZ0IsR0FBOEI7WUFDbEQsSUFBSSxFQUFFLE9BQU8sV0FBVyxDQUFDLElBQUksS0FBSyxRQUFRLENBQUMsQ0FBQyxDQUFDLFdBQVcsQ0FBQyxJQUFJLENBQUMsT0FBTyx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