diff --git a/README.md b/README.md index 0f3525f5..89a325a0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ const soupJson = convertEasyEdaJsonToCircuitJson(rawEasyJson) import { convertRawEasyEdaToTs } from "easyeda" // Convert to TypeScript React component -const tsxComponent = await convertRawEasyEdaToTs(rawEasyJson) +const tsxComponent = await convertRawEasyEdaToTs({ rawEasy: rawEasyJson }) ``` ### Full Example: Fetching and Converting to TSX @@ -36,7 +36,7 @@ import { fetchEasyEDAComponent, convertRawEasyEdaToTs } from "easyeda" async function convertPartNumberToTsx(partNumber: string) { const rawEasyJson = await fetchEasyEDAComponent(partNumber) - const tsxComponent = await convertRawEasyEdaToTs(rawEasyJson) + const tsxComponent = await convertRawEasyEdaToTs({ rawEasy: rawEasyJson }) return tsxComponent } diff --git a/lib/convert-easyeda-json-to-various-formats.ts b/lib/convert-easyeda-json-to-various-formats.ts index 744cace6..6f073a6b 100644 --- a/lib/convert-easyeda-json-to-various-formats.ts +++ b/lib/convert-easyeda-json-to-various-formats.ts @@ -84,7 +84,7 @@ export const convertEasyEdaJsonToVariousFormats = async ({ outputFilename.endsWith(".tsx") || outputFilename.endsWith(".ts") ) { - const tsComp = await convertRawEasyToTsx(rawEasyEdaJson) + const tsComp = await convertRawEasyToTsx({ rawEasy: rawEasyEdaJson }) await fs.writeFile(outputFilename, tsComp) console.log( `[${jlcpcbPartNumberOrFilepath}] Saved TypeScript component: ${outputFilename}`, diff --git a/tests/convert-easyeda-json-to-various-formats.test.ts b/tests/convert-easyeda-json-to-various-formats.test.ts new file mode 100644 index 00000000..ae5c2151 --- /dev/null +++ b/tests/convert-easyeda-json-to-various-formats.test.ts @@ -0,0 +1,23 @@ +import { expect, test } from "bun:test" +import fs from "node:fs/promises" +import os from "node:os" +import path from "node:path" +import { convertEasyEdaJsonToVariousFormats } from "lib/convert-easyeda-json-to-various-formats" + +test("converts a local raweasy.json file to a tsx component file", async () => { + const inputPath = path.join(import.meta.dir, "assets/C46749.raweasy.json") + const outputDir = await fs.mkdtemp( + path.join(os.tmpdir(), "easyeda-cli-test-"), + ) + const outputPath = path.join(outputDir, "C46749.tsx") + + await convertEasyEdaJsonToVariousFormats({ + jlcpcbPartNumberOrFilepath: inputPath, + outputFilename: outputPath, + outputFormat: "tsx", + }) + + const output = await fs.readFile(outputPath, "utf-8") + expect(output).toContain("