Skip to content
Closed
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
11 changes: 11 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lib/shared/export-snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
CircuitJsonToKicadProConverter,
CircuitJsonToKicadSchConverter,
} from "circuit-json-to-kicad"
import {
convertCircuitJsonToBomRows,
convertBomRowsToCsv,
} from "circuit-json-to-bom-csv"
import { convertCircuitJsonToReadableNetlist } from "circuit-json-to-readable-netlist"
import {
convertCircuitJsonToPcbSvg,
Expand Down Expand Up @@ -39,6 +43,7 @@ export const ALLOWED_EXPORT_FORMATS = [
"kicad_zip",
"kicad-library",
"srj",
"bom-csv",
] as const

export type ExportFormat = (typeof ALLOWED_EXPORT_FORMATS)[number]
Expand All @@ -58,6 +63,7 @@ const OUTPUT_EXTENSIONS: Record<ExportFormat, string> = {
kicad_zip: "-kicad.zip",
"kicad-library": "",
srj: ".simple-route.json",
"bom-csv": ".bom.csv",
}

type ExportOptions = {
Expand Down Expand Up @@ -164,6 +170,14 @@ export const exportSnippet = async ({
case "readable-netlist":
outputContent = convertCircuitJsonToReadableNetlist(circuitJson)
break
case "bom-csv":
{
const bomRows = await convertCircuitJsonToBomRows({
circuitJson,
})
outputContent = convertBomRowsToCsv(bomRows)
}
break
case "gltf":
outputContent = JSON.stringify(
await convertCircuitJsonToGltf(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"bun-match-svg": "^0.0.12",
"chokidar": "4.0.1",
"circuit-json": "^0.0.403",
"circuit-json-to-bom-csv": "^0.0.8",
"circuit-json-to-kicad": "^0.0.86",
"circuit-json-to-readable-netlist": "^0.0.15",
"circuit-json-to-spice": "^0.0.10",
Expand Down
45 changes: 45 additions & 0 deletions tests/cli/export/export-bom-csv.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { getCliTestFixture } from "../../fixtures/get-cli-test-fixture"
import { test, expect } from "bun:test"
import { writeFile, readFile } from "node:fs/promises"
import path from "node:path"

const circuitCode = `
export default () => (
<board width="10mm" height="10mm">
<resistor
resistance="1k"
footprint="0402"
name="R1"
schX={3}
pcbX={3}
/>
<capacitor
capacitance="1000pF"
footprint="0402"
name="C1"
schX={-3}
pcbX={-3}
/>
<trace from=".R1 > .pin1" to=".C1 > .pin1" />
</board>
)`

test("export bom-csv", async () => {
const { tmpDir, runCommand } = await getCliTestFixture()
const circuitPath = path.join(tmpDir, "test-circuit.tsx")

await writeFile(circuitPath, circuitCode)

const { stdout, stderr } = await runCommand(
`tsci export ${circuitPath} -f bom-csv`,
)
expect(stderr).toBe("")

Check failure on line 36 in tests/cli/export/export-bom-csv.test.ts

View workflow job for this annotation

GitHub Actions / test (3)

error: expect(received).toBe(expected)

- "" + "Error generating circuit JSON: ResolveMessage: ENOENT while resolving package 'react/jsx-dev-runtime' from '/tmp/b44aff525ad98c3d2287f72c2a450cf6/test-circuit.tsx' + " - Expected - 1 + Received + 2 at <anonymous> (/home/runner/work/cli/cli/tests/cli/export/export-bom-csv.test.ts:36:18)

const bomCsv = await readFile(
path.join(tmpDir, "test-circuit.bom.csv"),
"utf-8",
)
expect(bomCsv).toContain("Designator")
expect(bomCsv).toContain("R1")
expect(bomCsv).toContain("C1")
})
Loading