0hmX/am62l-lpddr4-ti-pth-router
This code defines a hardware-oriented React/TypeScript setup for a PCB breakout circuit featuring an AM62L LPDDR4 interface, including detailed PCB component placement, routing algorithms, and validation scripts for DDR connections, via placement, and manufacturing constraints.
- Version
- 1.0.1
- License
- unset
- Stars
- 0
scripts/bundle-site-for-ohmx-box.ts
import { readFile, stat, writeFile } from "node:fs/promises"
import { resolve } from "node:path"
const distDir = resolve(import.meta.dir, "../dist")
const htmlPath = resolve(distDir, "index.html")
const viewerPath = resolve(distDir, "standalone.min.js")
const circuitPath = resolve(distDir, "index/circuit.json")
const outputPath = resolve(distDir, "ohmx-box-am62l-lpddr4.html")
const [sourceHtml, viewerJavaScript, circuitJson] = await Promise.all([
readFile(htmlPath, "utf8"),
readFile(viewerPath, "utf8"),
readFile(circuitPath, "utf8"),
])
const circuitDataUrl = `data:application/json;base64,${Buffer.from(
circuitJson,
).toString("base64")}`
const inlineViewer = viewerJavaScript.replace(/<\/script/gi, "<\\/script")
const bundledShell = sourceHtml
.replace(
/\s*<link rel="icon"[^>]*href="https:\/\/github\.com\/tscircuit\.png"[^>]*>/,
"",
)
.replace(/\s*<script src="https:\/\/cdn\.tailwindcss\.com"><\/script>/, "")
.replace("./index/circuit.json", circuitDataUrl)
const viewerScriptTag = '<script type="module" src="./standalone.min.js"></script>'
const shellWithoutViewerTag = bundledShell.replace(viewerScriptTag, "")
for (const localReference of [
'src="./',
'href="./',
'fileStaticAssetUrl":"./',
]) {
if (shellWithoutViewerTag.includes(localReference)) {
throw new Error(`Local asset reference remains: ${localReference}`)
}
}
const inlineViewerTag = `<script type="module">\n${inlineViewer}\n</script>`
const bundledHtml = bundledShell.replace(viewerScriptTag, () => inlineViewerTag)
const expectedLength =
bundledShell.length - viewerScriptTag.length + inlineViewerTag.length
if (
bundledHtml === sourceHtml ||
bundledHtml.length !== expectedLength
) {
throw new Error(
`Generated site layout changed; no assets were inlined (sourceEqual=${bundledHtml === sourceHtml}, htmlLength=${bundledHtml.length}, expectedLength=${expectedLength})`,
)
}
await writeFile(outputPath, bundledHtml)
const { size } = await stat(outputPath)
const maximumSize = 25 * 1024 * 1024
if (size > maximumSize) {
throw new Error(`Bundle is ${size} bytes, over the 25 MiB ohmx-box limit`)
}
console.log(`${outputPath} (${size} bytes)`)