const fs = require('fs') const h = require('vhtml') const html = require('htm').bind(h) const renderPage = async ({path}: {path: string}): Promise => { let Component = await import(`./pages/${path}.ts`).then(i => i.default) let initialProps = await Component.getInitialProps() let renderedHTML = html`<${Component} ...${initialProps}/>` let result = ` ${initialProps.title ? initialProps.title : ''} ${renderedHTML} ` if (!fs.existsSync('dist')) fs.mkdirSync('dist') if (path == 'index') { fs.writeFileSync(`dist/${path}.html`, result) } else { if (!fs.existsSync(`dist/${path}`)) fs.mkdirSync(`dist/${path}`) fs.writeFileSync(`dist/${path}/index.html`, result) } } export default renderPage