"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 WebpackTypeScriptTemplate 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.ts');
                    await fs_extra_1.default.remove(path_1.default.resolve(directory, 'forge.config.js'));
                },
            },
            {
                title: 'Preparing TypeScript files and configuration',
                task: async () => {
                    const filePath = (fileName) => path_1.default.join(directory, 'src', fileName);
                    // Copy Webpack files
                    await this.copyTemplateFile(directory, 'webpack.main.config.ts');
                    await this.copyTemplateFile(directory, 'webpack.renderer.config.ts');
                    await this.copyTemplateFile(directory, 'webpack.rules.ts');
                    await this.copyTemplateFile(directory, 'webpack.plugins.ts');
                    await this.updateFileByLine(path_1.default.resolve(directory, 'src', 'index.html'), (line) => {
                        if (line.includes('link rel="stylesheet"'))
                            return '';
                        return line;
                    });
                    // Copy tsconfig with a small set of presets
                    await this.copyTemplateFile(directory, 'tsconfig.json');
                    // Copy eslint config with recommended settings
                    await this.copyTemplateFile(directory, '.eslintrc.json');
                    // Remove index.js and replace with index.ts
                    await fs_extra_1.default.remove(filePath('index.js'));
                    await this.copyTemplateFile(path_1.default.join(directory, 'src'), 'index.ts');
                    await this.copyTemplateFile(path_1.default.join(directory, 'src'), 'renderer.ts');
                    // Remove preload.js and replace with preload.ts
                    await fs_extra_1.default.remove(filePath('preload.js'));
                    await this.copyTemplateFile(path_1.default.join(directory, 'src'), 'preload.ts');
                    // update package.json
                    const packageJSONPath = path_1.default.resolve(directory, 'package.json');
                    const packageJSON = await fs_extra_1.default.readJson(packageJSONPath);
                    packageJSON.main = '.webpack/main';
                    // Configure scripts for TS template
                    packageJSON.scripts.lint = 'eslint --ext .ts,.tsx .';
                    await fs_extra_1.default.writeJson(packageJSONPath, packageJSON, {
                        spaces: 2,
                    });
                },
            },
        ];
    }
}
exports.default = new WebpackTypeScriptTemplate();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2VicGFja1R5cGVTY3JpcHRUZW1wbGF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9XZWJwYWNrVHlwZVNjcmlwdFRlbXBsYXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsZ0RBQXdCO0FBR3hCLGlFQUE2RDtBQUM3RCx3REFBMEI7QUFFMUIsTUFBTSx5QkFBMEIsU0FBUSw0QkFBWTtJQUFwRDs7UUFDUyxnQkFBVyxHQUFHLGNBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxFQUFFLElBQUksRUFBRSxNQUFNLENBQUMsQ0FBQztJQTBEN0QsQ0FBQztJQXhEQyxLQUFLLENBQUMsa0JBQWtCLENBQUMsU0FBaUIsRUFBRSxPQUE0QjtRQUN0RSxNQUFNLFVBQVUsR0FBRyxNQUFNLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxTQUFTLEVBQUUsT0FBTyxDQUFDLENBQUM7UUFDdEUsT0FBTztZQUNMLEdBQUcsVUFBVTtZQUNiO2dCQUNFLEtBQUssRUFBRSxnQ0FBZ0M7Z0JBQ3ZDLElBQUksRUFBRSxLQUFLLElBQUksRUFBRTtvQkFDZixNQUFNLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxTQUFTLEVBQUUsaUJBQWlCLENBQUMsQ0FBQztvQkFDMUQsTUFBTSxrQkFBRSxDQUFDLE1BQU0sQ0FBQyxjQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsRUFBRS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