"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const template_base_1 = require("@electron-forge/template-base");
const fs_extra_1 = __importDefault(require("fs-extra"));
class WebpackTemplate extends template_base_1.BaseTemplate {
    constructor() {
        super(...arguments);
        this.templateDir = path_1.default.resolve(__dirname, '..', 'tmpl');
    }
    async initializeTemplate(directory, options) {
        const superTasks = await super.initializeTemplate(directory, options);
        return [
            ...superTasks,
            {
                title: 'Setting up Forge configuration',
                task: async () => {
                    await this.copyTemplateFile(directory, 'forge.config.js');
                },
            },
            {
                title: 'Setting up webpack configuration',
                task: async () => {
                    await this.copyTemplateFile(directory, 'webpack.main.config.js');
                    await this.copyTemplateFile(directory, 'webpack.renderer.config.js');
                    await this.copyTemplateFile(directory, 'webpack.rules.js');
                    await this.copyTemplateFile(path_1.default.join(directory, 'src'), 'renderer.js');
                    await this.copyTemplateFile(path_1.default.join(directory, 'src'), 'preload.js');
                    await this.updateFileByLine(path_1.default.resolve(directory, 'src', 'index.js'), (line) => {
                        if (line.includes('mainWindow.loadFile'))
                            return '  mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);';
                        if (line.includes('preload: '))
                            return '      preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,';
                        return line;
                    }, path_1.default.resolve(directory, 'src', 'main.js'));
                    await this.updateFileByLine(path_1.default.resolve(directory, 'src', 'index.html'), (line) => {
                        if (line.includes('link rel="stylesheet"'))
                            return '';
                        return line;
                    });
                    // update package.json entry point
                    const pjPath = path_1.default.resolve(directory, 'package.json');
                    const currentPJ = await fs_extra_1.default.readJson(pjPath);
                    currentPJ.main = '.webpack/main';
                    await fs_extra_1.default.writeJson(pjPath, currentPJ, {
                        spaces: 2,
                    });
                },
            },
        ];
    }
}
exports.default = new WebpackTemplate();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJ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