mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
Dependencies and build for dev's toolchain (released solid-start, nitro 3.0.260903-beta, @typescript/native, no nitro patch), the textjs package, link preview cards (script/og.ts, with the source frames it crops) and the server-bundle guard in the build. Middleware (redirects for /go, /zen, /black, /enterprise, /pricing, /models, /teams, /download, /products, plus dev's iOS pairing, server-action sanitizing and /auth, /workspace), robots.txt, humans.txt, security.txt, llms.txt (ours), sitemaps with the V2 docs at /v2/sitemap.xml, Markdown twins, link preview cards, the site header (our nav including Enterprise), footer, settings, search, voice, i18n in 18 locales with RTL, and the 404 arcade. Docs stay on dev's proxy: docsBase is /v2/docs. consoleMarketingEnabled is kept for dev's test. Zen is renamed OpenCode Models in our copy. Middleware sends heavy media to the CDN (src/lib/media.ts). Vite keeps one environments block. The mono font is OpenTUI Mono (Anomaly's, SIL OFL 1.1): the files and licence are in src/asset/fonts, built by script/opentui-mono.py. The legal library has the Privacy Policy and the Terms only; the legal drafts are not in this branch.
78 lines
3.5 KiB
TypeScript
78 lines
3.5 KiB
TypeScript
// Builds the Text.js console apps that window.opencode loads on demand into the site's
|
|
// public/textjs/, with a manifest.json that maps each app to its hashed entry file.
|
|
//
|
|
// - picker: opencode.install.pick(), from src/picker.tsx.
|
|
// - lite: opencode.try(), OpenCode Lite. Its source is the opencode-console app in
|
|
// anomalyco/textjs (MIT), which isn't published to npm; it is downloaded at the pinned commit into
|
|
// .upstream/. If the download fails the build still writes the picker, and try() falls back to a
|
|
// link to textjs.org/opencode.
|
|
import { mkdir, rm } from "node:fs/promises"
|
|
import path from "node:path"
|
|
|
|
const commit = "760efedde45eb77b786db4c1658a0dd9126f079e"
|
|
const root = path.resolve(import.meta.dir, "..")
|
|
const upstream = path.join(root, ".upstream")
|
|
const out = path.resolve(root, "../app/public/textjs")
|
|
|
|
const lite = await fetchUpstream().then(
|
|
() => true,
|
|
(error) => {
|
|
console.warn(`textjs: OpenCode Lite skipped, couldn't fetch anomalyco/textjs@${commit.slice(0, 7)}: ${error}`)
|
|
return false
|
|
},
|
|
)
|
|
await rm(out, { recursive: true, force: true })
|
|
const result = await Bun.build({
|
|
entrypoints: [path.join(root, "src/picker.tsx"), ...(lite ? [path.join(root, "src/lite.tsx")] : [])],
|
|
outdir: out,
|
|
target: "browser",
|
|
format: "esm",
|
|
splitting: true,
|
|
minify: true,
|
|
naming: { entry: "[name]-[hash].[ext]", chunk: "chunk-[hash].[ext]" },
|
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
})
|
|
if (!result.success) throw new AggregateError(result.logs, "textjs build failed")
|
|
const entries = result.outputs.filter((output) => output.kind === "entry-point")
|
|
const manifest = Object.fromEntries(
|
|
entries.map((entry) => [path.basename(entry.path).split("-")[0], path.basename(entry.path)]),
|
|
)
|
|
await Bun.write(path.join(out, "manifest.json"), JSON.stringify(manifest))
|
|
// What each app downloads: its entry plus every chunk it imports statically.
|
|
const sizes = new Map(
|
|
await Promise.all(
|
|
result.outputs.map(async (output) => {
|
|
const text = await Bun.file(output.path).text()
|
|
const imports = [...text.matchAll(/from"\.\/([\w-]+\.js)"/g)].map((match) => match[1])
|
|
return [path.basename(output.path), { bytes: text.length, gzip: Bun.gzipSync(text).length, imports }] as const
|
|
}),
|
|
),
|
|
)
|
|
const closure = (file: string, seen = new Set<string>()): Set<string> => {
|
|
if (seen.has(file)) return seen
|
|
seen.add(file)
|
|
sizes.get(file)?.imports.forEach((next) => closure(next, seen))
|
|
return seen
|
|
}
|
|
for (const [name, file] of Object.entries(manifest)) {
|
|
const files = [...closure(file)]
|
|
const kb = (key: "bytes" | "gzip") =>
|
|
(files.reduce((sum, f) => sum + (sizes.get(f)?.[key] ?? 0), 0) / 1024).toFixed(1)
|
|
console.log(`textjs: ${name} ${kb("bytes")} KB, ${kb("gzip")} KB gzip (${files.length} files)`)
|
|
}
|
|
|
|
async function fetchUpstream() {
|
|
const marker = path.join(upstream, "COMMIT")
|
|
if ((await Bun.file(marker).exists()) && (await Bun.file(marker).text()) === commit) return
|
|
const response = await fetch(`https://codeload.github.com/anomalyco/textjs/tar.gz/${commit}`)
|
|
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
await rm(upstream, { recursive: true, force: true })
|
|
await mkdir(upstream, { recursive: true })
|
|
const archive = path.join(upstream, "textjs.tar.gz")
|
|
await Bun.write(archive, response)
|
|
const folder = `textjs-${commit}/apps/opencode-console`
|
|
const tar = Bun.spawnSync(["tar", "-xzf", archive, "-C", upstream, "--strip-components=2", folder])
|
|
if (tar.exitCode !== 0) throw new Error(tar.stderr.toString())
|
|
await rm(archive)
|
|
await Bun.write(marker, commit)
|
|
}
|