Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"vercel-build": "cosmos-export",
"repomix:lib": "repomix --ignore 'testing/**,**/TwoRouteHighDensitySolver/**,**/RouteStitchingSolver/**,solvers/CapacitySegmentPointOptimizer/CapacitySegmentPointOptimizer.ts' lib",
"bug-report": "bun run scripts/download-bug-report.ts",
"bug-report-with-test": "bun run scripts/create-bug-report-test.ts"
"bug-report-with-test": "bun run scripts/create-bug-report-test.ts",
"bake-cache": "bun run scripts/bake-cache.ts"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
47 changes: 47 additions & 0 deletions scripts/bake-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { mkdir, writeFile } from "node:fs/promises"
import { dirname, resolve } from "node:path"
import keyboard4 from "../examples/legacy/assets/keyboard4.json"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enable JSON module import for keyboard4 cache script

The new script imports ../examples/legacy/assets/keyboard4.json, but the repository’s tsconfig.json excludes examples/legacy/assets/**/*.json and does not enable resolveJsonModule. Running bunx --bun tsc --noEmit now emits TS2732: Cannot find module '../examples/legacy/assets/keyboard4.json', breaking the build step cited in the test plan. Either enable JSON module resolution or load the file with fs.readFile to keep type-checking green.

Useful? React with 👍 / 👎.

import { CapacityMeshSolver, getGlobalInMemoryCache } from "../lib"
import type { SimpleRouteJson } from "../lib/types"

const DEFAULT_OUTPUT_PATH = "./keyboard4-cache.json"

async function ensureDirectoryExists(filePath: string) {
const directory = dirname(filePath)
await mkdir(directory, { recursive: true })
}

async function main() {
const outputPathArg = process.argv[2]
const outputPath = resolve(
process.cwd(),
outputPathArg ?? DEFAULT_OUTPUT_PATH,
)

const srj = keyboard4 as unknown as SimpleRouteJson
const solver = new CapacityMeshSolver(srj)

console.log(`Baking keyboard4 cache to ${outputPath}...`)

solver.solve()

if (solver.failed || !solver.solved) {
const errorMessage = `Keyboard4 solver failed: ${solver.error ?? "unknown error"}`
throw new Error(errorMessage)
}

const cache = getGlobalInMemoryCache()
const cacheEntries = Array.from(cache.cache.entries())
const cacheObject = Object.fromEntries(cacheEntries)

await ensureDirectoryExists(outputPath)
await writeFile(outputPath, JSON.stringify(cacheObject, null, 2), "utf-8")

const completionMessage = `Cache baked successfully to ${outputPath}\n`
process.stdout.write(completionMessage)
}

main().catch((error) => {
console.error(error)
process.exit(1)
})