"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findTemplate = void 0;
const debug_1 = __importDefault(require("debug"));
const resolve_package_1 = __importDefault(require("resolve-package"));
const d = (0, debug_1.default)('electron-forge:init:find-template');
const findTemplate = async (dir, template) => {
    let templateModulePath;
    const resolveTemplateTypes = [
        ['global', `electron-forge-template-${template}`],
        ['global', `@electron-forge/template-${template}`],
        ['local', `electron-forge-template-${template}`],
        ['local', `@electron-forge/template-${template}`],
        ['local', template],
    ];
    let foundTemplate = false;
    for (const [templateType, moduleName] of resolveTemplateTypes) {
        try {
            d(`Trying ${templateType} template: ${moduleName}`);
            if (templateType === 'global') {
                templateModulePath = await (0, resolve_package_1.default)(moduleName);
            }
            else {
                // local
                templateModulePath = require.resolve(moduleName);
            }
            foundTemplate = true;
            break;
        }
        catch (err) {
            d(`Error: ${err instanceof Error ? err.message : err}`);
        }
    }
    if (!foundTemplate) {
        throw new Error(`Failed to locate custom template: "${template}".`);
    }
    d(`found template module at: ${templateModulePath}`);
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const templateModule = require(templateModulePath);
    return templateModule.default || templateModule;
};
exports.findTemplate = findTemplate;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmluZC10ZW1wbGF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcGkvaW5pdC1zY3JpcHRzL2ZpbmQtdGVtcGxhdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQ0Esa0RBQTBCO0FBQzFCLHNFQUE2QztBQUk3QyxNQUFNLENBQUMsR0FBRyxJQUFBLGVBQUssRUFBQyxtQ0FBbUMsQ0FBQyxDQUFDO0FBRTlDLE1BQU0sWUFBWSxHQUFHLEtBQUssRUFBRSxHQUFXLEVBQUUs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