ShiboSoftwareDev/mspm0g3507-usb-c-dev-board
This circuit features a USB Type-C connector with integrated resistors and passives, a USB ESD protection device, a CH340 USB-to-serial interface chip, a 3.3V regulator (AP2112K), multiple decoupling and bulk capacitors, and a Microcontroller (MSPM0G3507) with associated I2C and SPI connections, providing USB communication, power regulation, and RGB LED control.
- Version
- 1.4.1
- License
- unset
- Stars
- 0
scripts/check-jlc-stock.mjs
import { readFileSync } from "node:fs"
const circuitPath = process.argv[2] ?? "dist/index/circuit.json"
const circuit = JSON.parse(readFileSync(circuitPath, "utf8"))
const uniqueParts = new Map()
for (const component of circuit.filter((element) => element.type === "source_component")) {
const partNumber = component.supplier_part_numbers?.jlcpcb?.[0]
const mpn = component.manufacturer_part_number
if (!partNumber || !mpn) throw new Error(`${component.name} is missing JLCPCB or MPN metadata`)
const part = uniqueParts.get(partNumber) ?? { partNumber, mpn, designators: [] }
if (part.mpn !== mpn) throw new Error(`${partNumber} is assigned to both ${part.mpn} and ${mpn}`)
part.designators.push(component.name)
uniqueParts.set(partNumber, part)
}
const searchCatalog = async (query) => {
const params = new URLSearchParams({ limit: "10", q: query })
const response = await fetch(`https://jlcsearch.tscircuit.com/api/search?${params}`)
if (!response.ok) return { components: [], status: response.status }
return { ...(await response.json()), status: response.status }
}
const results = await Promise.all([...uniqueParts.values()].map(async (part) => {
const lcscNumber = Number(part.partNumber.slice(1))
let result = await searchCatalog(part.partNumber)
let match = result.components?.find((component) => component.lcsc === lcscNumber)
if (!match) {
result = await searchCatalog(part.mpn)
match = result.components?.find((component) => component.lcsc === lcscNumber)
}
if (!match) throw new Error(`${part.partNumber} was not found in the live parts catalog`)
if (match.mfr !== part.mpn) throw new Error(`${part.partNumber} is ${match.mfr}, but the BOM specifies ${part.mpn}`)
if (!(match.stock > 0)) throw new Error(`${part.partNumber} (${part.mpn}) is out of stock`)
return { ...part, stock: match.stock }
}))
results.sort((a, b) => a.partNumber.localeCompare(b.partNumber, undefined, { numeric: true }))
console.log(JSON.stringify({ checkedAt: new Date().toISOString(), parts: results }, null, 2))