mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
One site/cloudflare.config.ts defines the production Worker hex (anoma.ly/hex, bucket hex-production-files) and the dev Worker hex-dev (dev.anoma.ly/hex, bucket hex-dev-files), deployed only from CI with cf deploy --prebuilt --mode. The Worker serves the site and the release bucket; apps, scripts, the release workflow, and docs use https://anoma.ly/hex/files. Staging releases publish to the dev bucket; stable releases deploy the production site.
27 lines
1.4 KiB
TypeScript
27 lines
1.4 KiB
TypeScript
// Puts the server-rendered Mac page into the built index.html, so the copy and
|
|
// the download button are in the HTML before JavaScript runs; main.tsx hydrates
|
|
// it. Stamps the release version into the JSON-LD and this mode's origin into
|
|
// every absolute URL.
|
|
import { getWorkerAssetsDir } from "@cloudflare/build-output-utils"
|
|
import { readFileSync, rmSync, writeFileSync } from "node:fs"
|
|
import { join, resolve } from "node:path"
|
|
import { parseArgs } from "node:util"
|
|
import { render } from "../dist-server/prerender.js"
|
|
import { originForMode } from "../src/base"
|
|
import { MAC_VERSION } from "../src/release"
|
|
|
|
const { values } = parseArgs({ options: { mode: { type: "string" } } })
|
|
const origin = originForMode(values.mode)
|
|
const root = resolve(import.meta.dirname, "..")
|
|
const assets = getWorkerAssetsDir(root)
|
|
|
|
const index = join(assets, "index.html")
|
|
const html = readFileSync(index, "utf8")
|
|
const marker = '<div id="root"></div>'
|
|
if (!html.includes(marker)) throw new Error(`index.html has no ${marker}`)
|
|
writeFileSync(index, html.replace(marker, `<div id="root">${render()}</div>`).replaceAll("__HEX_VERSION__", MAC_VERSION))
|
|
for (const name of ["index.html", "llms.txt", "robots.txt", "sitemap.xml"]) {
|
|
const path = join(assets, name)
|
|
writeFileSync(path, readFileSync(path, "utf8").replaceAll("__ORIGIN__", origin))
|
|
}
|
|
rmSync(join(root, "dist-server"), { recursive: true, force: true })
|