mohan-bee/mini-mp3-player

Portable, battery-powered MP3 player hardware with USB charging, microSD storage, an MCU, VS10xx audio decoder, headphone output, status controls, and regulated power rails.

Version
1.2.0
License
unset
Stars
0

scripts/write-model-urls.mjs

import fs from "node:fs"

export function writeModelUrls(models) {
  fs.mkdirSync("mechanical/model-data", { recursive: true })
  const imports = []
  const entries = []
  for (const [name, url] of Object.entries(models)) {
    const identifiers = []
    for (let offset = 0; offset < url.length; offset += 450000) {
      const identifier = `modelChunk${imports.length}`
      const filename = `${name}-${offset / 450000}.json`
      fs.writeFileSync(`mechanical/model-data/${filename}`, JSON.stringify(url.slice(offset, offset + 450000)))
      imports.push(`import ${identifier} from "./model-data/${filename}"`)
      identifiers.push(identifier)
    }
    entries.push(`  "${name}": [${identifiers.join(", ")}].join("")`)
  }
  fs.writeFileSync("mechanical/model-urls.ts", imports.join("\n") + "\nexport default {\n" + entries.join(",\n") + "\n}\n")
}