@tscircuit/cli 0.1.32 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lock +214 -126
- package/cli/export/register.ts +18 -2
- package/dist/main.js +23 -4
- package/lib/server/createHttpServer.ts +3 -1
- package/lib/shared/generate-gitignore-file.ts +2 -2
- package/package.json +3 -1
- package/tests/cli/export/__snapshots__/pcb.snap.svg +13 -0
- package/tests/cli/export/__snapshots__/schematic.snap.svg +17 -0
- package/tests/cli/export/export.test.ts +62 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600" style="background-color: rgb(245, 241, 237)" data-real-to-screen-transform="matrix(144.84007242,0,0,-144.84007242,601.2614556427,338.9300573808)"><style>
|
|
2
|
+
.boundary { fill: rgb(245, 241, 237); }
|
|
3
|
+
.schematic-boundary { fill: none; stroke: #fff; }
|
|
4
|
+
.component { fill: none; stroke: rgb(132, 0, 0); }
|
|
5
|
+
.chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); }
|
|
6
|
+
.component-pin { fill: none; stroke: rgb(132, 0, 0); }
|
|
7
|
+
.trace:hover {
|
|
8
|
+
filter: invert(1);
|
|
9
|
+
}
|
|
10
|
+
.trace:hover .trace-crossing-outline {
|
|
11
|
+
opacity: 0;
|
|
12
|
+
}
|
|
13
|
+
.text { font-family: sans-serif; fill: rgb(0, 150, 0); }
|
|
14
|
+
.pin-number { fill: rgb(169, 0, 0); }
|
|
15
|
+
.port-label { fill: rgb(0, 100, 100); }
|
|
16
|
+
.component-name { fill: rgb(0, 100, 100); }
|
|
17
|
+
</style><rect class="boundary" x="0" y="0" width="1200" height="600"/><g data-circuit-json-type="schematic_component" data-schematic-component-id="schematic_component_0"><rect class="component-overlay" x="961.6451659624652" y="313.0828974532263" width="153.28907181649743" height="38.32227881712976" fill="transparent"/><path d="M 961.6451659624652 332.2440368617912 L 999.9674302955876 332.2440368617912" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><path d="M 1076.611958961833 332.2440368617912 L 1114.9342377789626 332.2440368617912" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><path d="M 1038.289680144703 313.0828974532263 L 1076.6119444778255 313.0828974532263 L 1076.6119444778255 351.40517627035604 L 999.967401327573 351.40517627035604 L 999.967401327573 313.0828974532263 L 1038.2896801447027 313.0828974532263" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><text x="1035.7816729027" y="305.7221862096437" fill="rgb(15, 15, 15)" font-family="sans-serif" text-anchor="middle" dominant-baseline="auto" font-size="26.0712130356px">R1</text><text x="1035.7816729027" y="361.9991234825565" fill="rgb(15, 15, 15)" font-family="sans-serif" text-anchor="middle" dominant-baseline="hanging" font-size="26.0712130356px">1kΩ</text><circle cx="958.4673892575775" cy="332.2956288955875" r="2.8968014484px" stroke-width="2.8968014484px" fill="none" stroke="rgb(132, 0, 0)"/><circle cx="1113.0959565478224" cy="332.3747839951648" r="2.8968014484px" stroke-width="2.8968014484px" fill="none" stroke="rgb(132, 0, 0)"/></g><g data-circuit-json-type="schematic_component" data-schematic-component-id="schematic_component_1"><rect class="component-overlay" x="89.19451538935782" y="298.10451483403904" width="153.2890718164976" height="76.64452866624515" fill="transparent"/><path d="M 242.48358720585543 336.4267791671613 L 177.33573928794772 336.4267791671613" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><path d="M 154.34237779127272 336.4267791671613 L 89.19451538935782 336.4267791671613" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><path d="M 177.33573928794766 298.10451483403904 L 177.33573928794772 374.7490435002842" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><path d="M 154.34237779127272 298.10451483403904 L 154.34237779127272 374.7490435002842" stroke="rgb(132, 0, 0)" fill="none" stroke-width="2.8968014484px"/><text x="164.87794327105283" y="278.14889075777336" fill="rgb(15, 15, 15)" font-family="sans-serif" text-anchor="middle" dominant-baseline="auto" font-size="26.0712130356px">C1</text><text x="166.18353168384664" y="399.7112240038267" fill="rgb(15, 15, 15)" font-family="sans-serif" text-anchor="middle" dominant-baseline="hanging" font-size="26.0712130356px">1nF</text><circle cx="86.90404345212234" cy="336.5575407845422" r="2.8968014484px" stroke-width="2.8968014484px" fill="none" stroke="rgb(132, 0, 0)"/><circle cx="246.57843331327743" cy="336.47835671695026" r="2.8968014484px" stroke-width="2.8968014484px" fill="none" stroke="rgb(132, 0, 0)"/></g><g class="trace" data-circuit-json-type="schematic_trace" data-schematic-trace-id="schematic_trace_0"><path d="M 958.4673892575775 332.2956288955875 L 398.66050935427745 332.2956288955875 L 398.66050935427745 184.39628067595024 L 86.90404345212232 184.39628067595024 L 86.90404345212232 314.83152992154214 L 86.90404345212232 336.55754078454214" class="trace-invisible-hover-outline" stroke="rgb(0, 150, 0)" fill="none" stroke-width="23.1744115872px" stroke-linecap="round" opacity="0" stroke-linejoin="round"/><path d="M 958.4673892575775 332.2956288955875 L 398.66050935427745 332.2956288955875 L 398.66050935427745 184.39628067595024 L 86.90404345212232 184.39628067595024 L 86.90404345212232 314.83152992154214 L 86.90404345212232 336.55754078454214" stroke="rgb(0, 150, 0)" fill="none" stroke-width="2.8968014484px" stroke-linecap="round" stroke-linejoin="round"/></g></svg>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getCliTestFixture } from "../../fixtures/get-cli-test-fixture"
|
|
2
|
+
import { test, expect } from "bun:test"
|
|
3
|
+
import { readFile } from "node:fs/promises"
|
|
4
|
+
import path from "node:path"
|
|
5
|
+
import "bun-match-svg"
|
|
6
|
+
|
|
7
|
+
const circuitCode = `
|
|
8
|
+
export default () => (
|
|
9
|
+
<board width="10mm" height="10mm">
|
|
10
|
+
<resistor
|
|
11
|
+
resistance="1k"
|
|
12
|
+
footprint="0402"
|
|
13
|
+
name="R1"
|
|
14
|
+
schX={3}
|
|
15
|
+
pcbX={3}
|
|
16
|
+
/>
|
|
17
|
+
<capacitor
|
|
18
|
+
capacitance="1000pF"
|
|
19
|
+
footprint="0402"
|
|
20
|
+
name="C1"
|
|
21
|
+
schX={-3}
|
|
22
|
+
pcbX={-3}
|
|
23
|
+
/>
|
|
24
|
+
<trace from=".R1 > .pin1" to=".C1 > .pin1" />
|
|
25
|
+
</board>
|
|
26
|
+
)`
|
|
27
|
+
|
|
28
|
+
async function setupTestCircuit(tmpDir: string) {
|
|
29
|
+
await Bun.write(path.join(tmpDir, "test-circuit.tsx"), circuitCode)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test("export pcb-svg", async () => {
|
|
33
|
+
const { tmpDir, runCommand } = await getCliTestFixture()
|
|
34
|
+
await setupTestCircuit(tmpDir)
|
|
35
|
+
|
|
36
|
+
const { stdout, stderr } = await runCommand(
|
|
37
|
+
`tsci export ${path.join(tmpDir, "test-circuit.tsx")} -f pcb-svg`,
|
|
38
|
+
)
|
|
39
|
+
expect(stderr).toBe("")
|
|
40
|
+
|
|
41
|
+
const pcbSvg = await readFile(
|
|
42
|
+
path.join(tmpDir, "test-circuit-pcb.svg"),
|
|
43
|
+
"utf-8",
|
|
44
|
+
)
|
|
45
|
+
expect(pcbSvg).toMatchSvgSnapshot(import.meta.path, "pcb")
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("export schematic-svg", async () => {
|
|
49
|
+
const { tmpDir, runCommand } = await getCliTestFixture()
|
|
50
|
+
await setupTestCircuit(tmpDir)
|
|
51
|
+
|
|
52
|
+
const { stdout, stderr } = await runCommand(
|
|
53
|
+
`tsci export ${path.join(tmpDir, "test-circuit.tsx")} -f schematic-svg`,
|
|
54
|
+
)
|
|
55
|
+
expect(stderr).toBe("")
|
|
56
|
+
|
|
57
|
+
const schematicSvg = await readFile(
|
|
58
|
+
path.join(tmpDir, "test-circuit-schematic.svg"),
|
|
59
|
+
"utf-8",
|
|
60
|
+
)
|
|
61
|
+
expect(schematicSvg).toMatchSvgSnapshot(import.meta.path, "schematic")
|
|
62
|
+
})
|