Skip to content

Commit

Permalink
refactor: static files
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Mar 7, 2024
1 parent 8bbe117 commit e66164e
Show file tree
Hide file tree
Showing 18 changed files with 509 additions and 822 deletions.
41 changes: 1 addition & 40 deletions .scripts/postbuild.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,10 @@
import { resolve, extname } from 'node:path'
import { resolve } from 'node:path'
import glob from 'fast-glob'
import { copy, rename } from 'fs-extra'

// await inlineDevtoolsStaticFiles()
await rewriteHonoJsx()
await prepareTemplates()

async function inlineDevtoolsStaticFiles() {
const assetPaths = [
...(await glob('./src/_lib/dev/static/assets/*')),
'./src/_lib/dev/static/entry-client.js',
]
const content: string[] = []
for (const asset of assetPaths) {
const file = await Bun.file(asset).text()
const escaped = file.trim().replace(/"/g, '\\"')

const extension = extname(asset)
if (extension === '.css')
content.push(`_jsx("style", { children: "${escaped}" })`)
else if (extension === '.js')
content.push(
`_jsx("script", { children: html("${escaped}"), type: "module" })`,
)
else throw new Error(`Unknown asset type: ${extension}`)
}

console.log(content)

const entryPath = './src/_lib/dev/entry-server.js'
const entry = await Bun.file(entryPath).text()

// const escapedJs = js.trim().replace(/"/g, '\\"')
// const script = `_jsx("script", { children: html(\"${escapedJs}\"), type: "module", crossorigin: "" })`
//
// // https://regexr.com/7t4ee
// const scriptRegex = /, _jsx\(\"script\".*?\}\)/
// const content = `import { html } from 'hono/html'\n${entry.replace(
// scriptRegex,
// `, ${style}, ${script}`,
// )}`
//
// await Bun.write('./src/_lib/dev/entry-server.js', content)
}

async function rewriteHonoJsx() {
const files = await glob('./src/_lib/**/*.js')
for (const file of files) {
Expand Down
Loading

0 comments on commit e66164e

Please sign in to comment.