/* eslint-disable no-console */ import fs from 'fs' import path from 'path' import handlebars from 'handlebars' import { salesAppCoreDir } from './directory' interface Data { [key: string]: unknown } export const compileTemplate = ( templatePath: string, data: Data, outputPath: string ) => { const templateSource = fs.readFileSync(templatePath, 'utf8') const template = handlebars.compile(templateSource) const result = template(data) const outputDir = path.dirname(outputPath) if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }) } fs.writeFileSync(outputPath, result) } const exampleData: Data = {} const indexData: Data = {} const rootDir = path.join(__dirname, '..', '..', '..', 'templates') const exampleTemplatePath = path.join(rootDir, 'Example.tsx.hbs') const indexTemplatePath = path.join(rootDir, 'index.ts.hbs') const exampleOutputPath = path.join( salesAppCoreDir, 'src', 'components', 'Example.tsx' ) const indexOutputPath = path.join(salesAppCoreDir, 'src', 'index.ts') export const runInitialStructureCompilation = () => { compileTemplate(exampleTemplatePath, exampleData, exampleOutputPath) compileTemplate(indexTemplatePath, indexData, indexOutputPath) }