Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Mar 13, 2024
1 parent 8754937 commit 3a1eead
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 335 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ coverage
create-frog/templates
node_modules
site/dist
src/dev/ui
tsconfig.*.tsbuildinfo
tsconfig.tsbuildinfo
38 changes: 2 additions & 36 deletions .scripts/postbuild.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
import { resolve, extname } from 'node:path'
import { resolve } from 'node:path'
import glob from 'fast-glob'
import { copy, rename, remove } from 'fs-extra'
import { copy, rename } from 'fs-extra'

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

async function inlineDevtoolsStaticFiles() {
const assetPaths = [
...(await glob('./src/dev/ui/assets/*')),
'./src/dev/ui/index.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}`)
}

const entryPath = './src/_lib/dev/client_.js'
let entry = await Bun.file(entryPath).text()
entry = entry.replace('_jsx(_Fragment, {})', content.join(', '))

await Bun.write('./src/_lib/dev/client_.js', entry)

const renameClientPaths = await glob('./src/_lib/dev/client_.*')
for (const path of renameClientPaths)
await rename(path, path.replace('client_', 'client'))

await remove('./src/dev/ui')
}

async function rewriteHonoJsx() {
const files = await glob('./src/_lib/**/*.js')
for (const file of files) {
Expand Down
1 change: 1 addition & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dev": "node --import tsx ../src/cli/index.ts"
},
"dependencies": {
"@hono/node-server": "^1.8.2",
"frog": "workspace:*",
"hono": "^4"
},
Expand Down
3 changes: 2 additions & 1 deletion playground/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button, Frog, TextInput } from 'frog'
import * as hubs from 'frog/hubs'
import { devtools } from 'frog/dev'
import { serveStatic } from '@hono/node-server/serve-static'

import { app as middlewareApp } from './middleware.js'
import { app as neynarApp } from './neynar.js'
Expand Down Expand Up @@ -234,4 +235,4 @@ app.route('/routing', routingApp)
app.route('/transaction', transactionApp)
app.route('/todos', todoApp)

devtools(app)
devtools(app, { serveStatic })
59 changes: 42 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3a1eead

Please sign in to comment.