ShiboSoftwareDev/MSP-EXP430FR2433
This code defines a 4 MHz surface-mount quartz crystal resonator with 15pF load capacitance and ground pin configuration, including PCB footprint and 3D model details.
- Version
- 1.0.1
- License
- unset
- Stars
- 0
scripts/kicad-prefix.mjs
import { readFileSync, writeFileSync } from "node:fs"
const [inputPath, outputPath, countText] = process.argv.slice(2)
const text = readFileSync(inputPath, "utf8")
const rootStart = text.indexOf("(kicad_pcb")
if (rootStart < 0) throw new Error("Missing kicad_pcb root")
let depth = 0
let inString = false
let escaped = false
let childStart = -1
const children = []
for (let index = rootStart; index < text.length; index += 1) {
const char = text[index]
if (inString) {
if (escaped) escaped = false
else if (char === "\\") escaped = true
else if (char === '"') inString = false
continue
}
if (char === '"') {
inString = true
continue
}
if (char === "(") {
depth += 1
if (depth === 2) childStart = index
} else if (char === ")") {
if (depth === 2 && childStart >= 0) {
children.push(text.slice(childStart, index + 1))
childStart = -1
}
depth -= 1
}
}
const count = Math.min(Number(countText ?? children.length), children.length)
writeFileSync(outputPath, `(kicad_pcb\n${children.slice(0, count).join("\n")}\n)\n`)
console.log(`Wrote ${count}/${children.length} top-level KiCad nodes`)