"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runInitialStructureCompilation = exports.compileTemplate = void 0;
/* eslint-disable no-console */
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const handlebars_1 = __importDefault(require("handlebars"));
const package_1 = require("./package");
const getTemplatePath = () => {
    return path_1.default.join(__dirname, '..', '..', '..', 'templates');
};
const compileTemplate = ({ name, data, outputPath }) => {
    const templatePath = path_1.default.join(getTemplatePath(), name);
    const templateSource = fs_extra_1.default.readFileSync(templatePath, 'utf8');
    const template = handlebars_1.default.compile(templateSource);
    const result = template(data);
    const outputDir = path_1.default.dirname(outputPath);
    if (!fs_extra_1.default.existsSync(outputDir)) {
        fs_extra_1.default.mkdirSync(outputDir, { recursive: true });
    }
    fs_extra_1.default.writeFileSync(outputPath, result);
};
exports.compileTemplate = compileTemplate;
const runInitialStructureCompilation = (targetDir) => {
    const templates = [
        {
            name: 'Example.tsx.hbs',
            outputPath: path_1.default.join(targetDir, 'src', 'components', 'Example.tsx'),
        },
        {
            name: 'Example.css.hbs',
            outputPath: path_1.default.join(targetDir, 'src', 'components', 'Example.css'),
        },
        {
            name: 'index.ts.hbs',
            outputPath: path_1.default.join(targetDir, 'src', 'index.ts'),
            data: {
                packageName: package_1.packageName,
            },
        },
        {
            name: '.gitignore.hbs',
            outputPath: path_1.default.join(targetDir, '.gitignore'),
        },
        {
            name: 'package.json.hbs',
            outputPath: path_1.default.join(targetDir, 'package.json'),
        },
        {
            name: 'tsconfig.json.hbs',
            outputPath: path_1.default.join(targetDir, 'tsconfig.json'),
        },
    ];
    for (const template of templates) {
        (0, exports.compileTemplate)(template);
    }
};
exports.runInitialStructureCompilation = runInitialStructureCompilation;
//# sourceMappingURL=createInitialStructure.js.map