diff --git a/.gitignore b/.gitignore index df85d35..a8f8ada 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist *.bettereasy.json .vscode tmp +temp.tsx diff --git a/benchmark/benchmark.ts b/benchmark/benchmark.ts new file mode 100644 index 0000000..c680cef --- /dev/null +++ b/benchmark/benchmark.ts @@ -0,0 +1,48 @@ +import { readFile, writeFile } from "node:fs/promises" +import { convertEasyEdaJsonToVariousFormats } from "../lib/convert-easyeda-json-to-various-formats" +import path from "node:path" + +async function benchmark() { + const partnumbersPath = path.join(__dirname, "partnumbers.json") + const resultPath = path.join(__dirname, "result.txt") + + let partnumbers: string[] + try { + const data = await readFile(partnumbersPath, "utf-8") + partnumbers = JSON.parse(data) + } catch (error) { + console.error("Error reading partnumbers.json:", error) + return + } + + let successes = 0 + let failures = 0 + let failureLog = "" + + for (const partnumber of partnumbers) { + try { + await convertEasyEdaJsonToVariousFormats({ + jlcpcbPartNumberOrFilepath: partnumber, + outputFilename: "temp.tsx", + formatType: "tsx", + }) + successes++ + } catch (error) { + failures++ + failureLog += `Part number: ${partnumber}\nError: ${error}\n\n` + } + } + + const summary = `Successes: ${successes}\nFailures: ${failures}\n\nFailure Details:\n${failureLog}` + + try { + await writeFile(resultPath, summary) + console.log(`Benchmark complete. Results written to ${resultPath}`) + console.log(`Successes: ${successes}`) + console.log(`Failures: ${failures}`) + } catch (error) { + console.error("Error writing result.txt:", error) + } +} + +benchmark() diff --git a/benchmark/partnumbers.json b/benchmark/partnumbers.json new file mode 100644 index 0000000..1b5dcfb --- /dev/null +++ b/benchmark/partnumbers.json @@ -0,0 +1,26 @@ +[ + "C21376", + "C25744", + "C965808", + "C14663", + "C1178474", + "C1153543", + "C1177579", + "C1184469", + "C1185108", + "C1180645", + "C1189664", + "C1178711", + "C389354", + "C516304", + "C2998002", + "C74384", + "C11702", + "C94784", + "C72044", + "C49678", + "C25804", + "C26083", + "C2843864", + "C2040" +] diff --git a/benchmark/result.txt b/benchmark/result.txt new file mode 100644 index 0000000..08f6868 --- /dev/null +++ b/benchmark/result.txt @@ -0,0 +1,43 @@ +Successes: 11 +Failures: 13 + +Failure Details: +Part number: C965808 +Error: Error: Invalid shape type: PT~M 245 303 L 235 310 L 245 317 Z ~#880000~1~0~none~gge49~0~ + +Part number: C1178474 +Error: Error: Component not found + +Part number: C1153543 +Error: Error: Component not found + +Part number: C1177579 +Error: Error: Component not found + +Part number: C1184469 +Error: Error: Component not found + +Part number: C1185108 +Error: Error: Component not found + +Part number: C1180645 +Error: Error: Component not found + +Part number: C1189664 +Error: Error: Component not found + +Part number: C1178711 +Error: Error: Component not found + +Part number: C389354 +Error: Error: Invalid shape type: PT~M 405 294 L 395 300 L 405 307 Z ~#880000~1~0~none~gge18~0~ + +Part number: C516304 +Error: Error: Invalid shape type: PT~M 395 326 L 405 320 L 395 313 Z~#880000~1~0~#880000~gge25~0~ + +Part number: C2998002 +Error: Error: Invalid shape type: T~L~415~303~0~#0000FF~~5.5pt~~~~comment~TR1~1~start~gge7~0~pinpart + +Part number: C2843864 +Error: Error: Invalid shape type: PT~M 420 337 L 430 330 L 420 323 Z ~#880000~1~0~none~gge82~0~ + diff --git a/lib/convert-easyeda-json-to-various-formats.ts b/lib/convert-easyeda-json-to-various-formats.ts index 9a00c6e..364f21f 100644 --- a/lib/convert-easyeda-json-to-various-formats.ts +++ b/lib/convert-easyeda-json-to-various-formats.ts @@ -63,26 +63,36 @@ export const convertEasyEdaJsonToVariousFormats = async ({ const betterEasy = EasyEdaJsonSchema.parse(rawEasyEdaJson) const tscircuitSoup = convertEasyEdaJsonToTscircuitSoupJson(betterEasy) - if (outputFilename.endsWith(".soup.json")) { + if ( + outputFilename.endsWith(".soup.json") || + outputFilename.endsWith(".circuit.json") + ) { await fs.writeFile(outputFilename, JSON.stringify(tscircuitSoup, null, 2)) - console.log(`Converted to tscircuit soup JSON: ${outputFilename}`) + console.log( + `[${jlcpcbPartNumberOrFilepath}] Converted to circuit json: ${outputFilename}`, + ) } else if (outputFilename.endsWith(".kicad_mod")) { // TODO: Implement conversion to KiCad footprint console.log("Conversion to KiCad footprint not yet implemented") } else if (outputFilename.endsWith(".bettereasy.json")) { await fs.writeFile(outputFilename, JSON.stringify(betterEasy, null, 2)) - console.log(`Saved better EasyEDA JSON: ${outputFilename}`) + console.log( + `[${jlcpcbPartNumberOrFilepath}] Saved better EasyEDA JSON: ${outputFilename}`, + ) } else if ( outputFilename.endsWith(".tsx") || outputFilename.endsWith(".ts") ) { const tsComp = await convertRawEasyEdaToTs(rawEasyEdaJson) await fs.writeFile(outputFilename, tsComp) - console.log(`Saved TypeScript component: ${outputFilename}`) + console.log( + `[${jlcpcbPartNumberOrFilepath}] Saved TypeScript component: ${outputFilename}`, + ) } else { console.error("Unsupported output format") } } catch (error: any) { console.error("Error:", error.message) + throw error } }