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
6 changes: 3 additions & 3 deletions lib/convert-easyeda-json-to-various-formats.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fetchEasyEDAComponent } from "lib/websafe/fetch-easyeda-json"
import { convertEasyEdaJsonToCircuitJson } from "lib/convert-easyeda-json-to-tscircuit-soup-json"
import { EasyEdaJsonSchema } from "lib/schemas/easy-eda-json-schema"
import { convertRawEasyToTsx } from "lib/websafe/convert-to-typescript-component"
import { normalizeManufacturerPartNumber } from "lib/utils/normalize-manufacturer-part-number"
import { convertRawEasyToTsx } from "lib/websafe/convert-to-typescript-component"
import { fetchEasyEDAComponent } from "lib/websafe/fetch-easyeda-json"

export const convertEasyEdaJsonToVariousFormats = async ({
jlcpcbPartNumberOrFilepath,
Expand Down 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
34 changes: 34 additions & 0 deletions tests/cli/convert-tsx-output-400.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, it } 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"

// https://github.com/tscircuit/easyeda-converter/issues/400
//
// `easyeda convert -i <part> -o <file>.tsx` crashed for every part:
// convertRawEasyToTsx takes `{ rawEasy }` but was called with the raw JSON
// directly, so EasyEdaJsonSchema.parse(undefined) threw. Uses a local
// .raweasy.json asset so no network is needed.
it("converts a local raweasy.json to a tsx component file", async () => {
const inputPath = path.join(
import.meta.dir,
"..",
"assets",
"C46749.raweasy.json",
)
const outputPath = path.join(
await fs.mkdtemp(path.join(os.tmpdir(), "easyeda-400-")),
"C46749.tsx",
)

await convertEasyEdaJsonToVariousFormats({
jlcpcbPartNumberOrFilepath: inputPath,
outputFilename: outputPath,
outputFormat: "tsx",
})

const tsx = await fs.readFile(outputPath, "utf-8")
expect(tsx).toContain("const pinLabels")
expect(tsx).toContain("<chip")
})
Loading