Nuxt/packages/ui-templates/lib/prerender.ts

21 lines
597 B
TypeScript
Raw Normal View History

import { join, resolve } from 'node:path'
import { promises as fsp } from 'node:fs'
import { globby } from 'globby'
2021-12-22 13:04:06 +00:00
const r = (...path: string[]) => resolve(join(__dirname, '..', ...path))
async function main () {
const templates = await globby(r('dist/templates/*.js'))
2021-12-22 13:04:06 +00:00
for (const file of templates) {
const { template } = await import(file)
const updated = template({
// messages: {},
name: '{{ name }}', // TODO
2021-12-22 13:04:06 +00:00
})
await fsp.mkdir(file.replace('.js', ''))
await fsp.writeFile(file.replace('.js', '/index.html'), updated)
2021-12-22 13:04:06 +00:00
}
}
main().catch(console.error)