Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion lib/convert-easyeda-json-to-various-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
23 changes: 23 additions & 0 deletions tests/convert-easyeda-json-to-various-formats.test.ts
Original file line number Diff line number Diff line change
@@ -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("<chip")
expect(output).toContain("C46749")
})
Loading