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

22 lines
666 B
TypeScript
Raw Normal View History

import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { promises as fsp } from 'node:fs'
2024-06-24 13:34:07 +00:00
import { fdir } from 'fdir'
2021-12-22 13:04:06 +00:00
const templatesRoot = fileURLToPath(new URL('..', import.meta.url))
2021-12-22 13:04:06 +00:00
async function main () {
2024-06-24 13:34:07 +00:00
const templates = new fdir().glob('*.js').crawl(join(templatesRoot, 'dist/templates')).sync()
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)