circuit-json-to-tscircuit 0.0.4 → 0.0.5
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/assets/input-circuit-json.json +196 -0
- package/bun.lockb +0 -0
- package/cli/main.ts +54 -0
- package/dist/chunk-27MYDU45.js +5756 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +3387 -0
- package/dist/lib/index.js +6 -0
- package/package.json +3 -2
- package/tests/cli/cli-circuit-json-to-tsx.test.tsx +51 -0
- package/tests/fixtures/get-cli-test-fixture.ts +44 -0
- package/dist/index.js +0 -104
- /package/dist/{index.d.ts → lib/index.d.ts} +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"type": "source_port",
|
|
4
|
+
"source_port_id": "source_port_0",
|
|
5
|
+
"name": "pin1",
|
|
6
|
+
"pin_number": 1,
|
|
7
|
+
"port_hints": ["anode", "pos", "left", "pin1", "1"],
|
|
8
|
+
"source_component_id": "source_component_0"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"type": "source_port",
|
|
12
|
+
"source_port_id": "source_port_1",
|
|
13
|
+
"name": "pin2",
|
|
14
|
+
"pin_number": 2,
|
|
15
|
+
"port_hints": ["cathode", "neg", "right", "pin2", "2"],
|
|
16
|
+
"source_component_id": "source_component_0"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"type": "source_component",
|
|
20
|
+
"source_component_id": "source_component_0",
|
|
21
|
+
"ftype": "simple_resistor",
|
|
22
|
+
"name": "R1",
|
|
23
|
+
"supplier_part_numbers": {
|
|
24
|
+
"jlcpcb": ["C11702", "C25543", "C226166"]
|
|
25
|
+
},
|
|
26
|
+
"resistance": 1000,
|
|
27
|
+
"display_resistance": "1kΩ"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "source_group",
|
|
31
|
+
"source_group_id": "source_group_0",
|
|
32
|
+
"is_subcircuit": true,
|
|
33
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"type": "schematic_component",
|
|
37
|
+
"schematic_component_id": "schematic_component_0",
|
|
38
|
+
"center": {
|
|
39
|
+
"x": 0,
|
|
40
|
+
"y": 0
|
|
41
|
+
},
|
|
42
|
+
"rotation": 0,
|
|
43
|
+
"size": {
|
|
44
|
+
"width": 1.0583332999999997,
|
|
45
|
+
"height": 0.388910699999999
|
|
46
|
+
},
|
|
47
|
+
"source_component_id": "source_component_0",
|
|
48
|
+
"symbol_name": "boxresistor_right",
|
|
49
|
+
"symbol_display_value": "1kΩ"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"type": "schematic_port",
|
|
53
|
+
"schematic_port_id": "schematic_port_0",
|
|
54
|
+
"schematic_component_id": "schematic_component_0",
|
|
55
|
+
"center": {
|
|
56
|
+
"x": -0.5337907000000003,
|
|
57
|
+
"y": 0.045805199999999324
|
|
58
|
+
},
|
|
59
|
+
"source_port_id": "source_port_0",
|
|
60
|
+
"facing_direction": "left",
|
|
61
|
+
"distance_from_component_edge": 0.4,
|
|
62
|
+
"pin_number": 1,
|
|
63
|
+
"display_pin_label": "left"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"type": "schematic_port",
|
|
67
|
+
"schematic_port_id": "schematic_port_1",
|
|
68
|
+
"schematic_component_id": "schematic_component_0",
|
|
69
|
+
"center": {
|
|
70
|
+
"x": 0.5337907000000003,
|
|
71
|
+
"y": 0.04525870000000065
|
|
72
|
+
},
|
|
73
|
+
"source_port_id": "source_port_1",
|
|
74
|
+
"facing_direction": "right",
|
|
75
|
+
"distance_from_component_edge": 0.4,
|
|
76
|
+
"pin_number": 2,
|
|
77
|
+
"display_pin_label": "right"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"type": "pcb_component",
|
|
81
|
+
"pcb_component_id": "pcb_component_0",
|
|
82
|
+
"center": {
|
|
83
|
+
"x": 0,
|
|
84
|
+
"y": 0
|
|
85
|
+
},
|
|
86
|
+
"width": 1.6,
|
|
87
|
+
"height": 0.6000000000000001,
|
|
88
|
+
"layer": "top",
|
|
89
|
+
"rotation": 0,
|
|
90
|
+
"source_component_id": "source_component_0",
|
|
91
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"type": "pcb_board",
|
|
95
|
+
"pcb_board_id": "pcb_board_0",
|
|
96
|
+
"center": {
|
|
97
|
+
"x": 0,
|
|
98
|
+
"y": 0
|
|
99
|
+
},
|
|
100
|
+
"thickness": 1.4,
|
|
101
|
+
"num_layers": 4,
|
|
102
|
+
"width": 5,
|
|
103
|
+
"height": 5
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "pcb_smtpad",
|
|
107
|
+
"pcb_smtpad_id": "pcb_smtpad_0",
|
|
108
|
+
"pcb_component_id": "pcb_component_0",
|
|
109
|
+
"pcb_port_id": "pcb_port_0",
|
|
110
|
+
"layer": "top",
|
|
111
|
+
"shape": "rect",
|
|
112
|
+
"width": 0.6000000000000001,
|
|
113
|
+
"height": 0.6000000000000001,
|
|
114
|
+
"port_hints": ["1", "left"],
|
|
115
|
+
"x": -0.5,
|
|
116
|
+
"y": 0,
|
|
117
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"type": "pcb_solder_paste",
|
|
121
|
+
"pcb_solder_paste_id": "pcb_solder_paste_0",
|
|
122
|
+
"layer": "top",
|
|
123
|
+
"shape": "rect",
|
|
124
|
+
"width": 0.42000000000000004,
|
|
125
|
+
"height": 0.42000000000000004,
|
|
126
|
+
"x": -0.5,
|
|
127
|
+
"y": 0,
|
|
128
|
+
"pcb_component_id": "pcb_component_0",
|
|
129
|
+
"pcb_smtpad_id": "pcb_smtpad_0",
|
|
130
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"type": "pcb_smtpad",
|
|
134
|
+
"pcb_smtpad_id": "pcb_smtpad_1",
|
|
135
|
+
"pcb_component_id": "pcb_component_0",
|
|
136
|
+
"pcb_port_id": "pcb_port_1",
|
|
137
|
+
"layer": "top",
|
|
138
|
+
"shape": "rect",
|
|
139
|
+
"width": 0.6000000000000001,
|
|
140
|
+
"height": 0.6000000000000001,
|
|
141
|
+
"port_hints": ["2", "right"],
|
|
142
|
+
"x": 0.5,
|
|
143
|
+
"y": 0,
|
|
144
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"type": "pcb_solder_paste",
|
|
148
|
+
"pcb_solder_paste_id": "pcb_solder_paste_1",
|
|
149
|
+
"layer": "top",
|
|
150
|
+
"shape": "rect",
|
|
151
|
+
"width": 0.42000000000000004,
|
|
152
|
+
"height": 0.42000000000000004,
|
|
153
|
+
"x": 0.5,
|
|
154
|
+
"y": 0,
|
|
155
|
+
"pcb_component_id": "pcb_component_0",
|
|
156
|
+
"pcb_smtpad_id": "pcb_smtpad_1",
|
|
157
|
+
"subcircuit_id": "subcircuit_source_group_0"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"type": "pcb_port",
|
|
161
|
+
"pcb_port_id": "pcb_port_0",
|
|
162
|
+
"pcb_component_id": "pcb_component_0",
|
|
163
|
+
"layers": ["top"],
|
|
164
|
+
"subcircuit_id": "subcircuit_source_group_0",
|
|
165
|
+
"x": -0.5,
|
|
166
|
+
"y": 0,
|
|
167
|
+
"source_port_id": "source_port_0"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"type": "pcb_port",
|
|
171
|
+
"pcb_port_id": "pcb_port_1",
|
|
172
|
+
"pcb_component_id": "pcb_component_0",
|
|
173
|
+
"layers": ["top"],
|
|
174
|
+
"subcircuit_id": "subcircuit_source_group_0",
|
|
175
|
+
"x": 0.5,
|
|
176
|
+
"y": 0,
|
|
177
|
+
"source_port_id": "source_port_1"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"type": "cad_component",
|
|
181
|
+
"cad_component_id": "cad_component_0",
|
|
182
|
+
"position": {
|
|
183
|
+
"x": 0,
|
|
184
|
+
"y": 0,
|
|
185
|
+
"z": 0.7
|
|
186
|
+
},
|
|
187
|
+
"rotation": {
|
|
188
|
+
"x": 0,
|
|
189
|
+
"y": 0,
|
|
190
|
+
"z": 0
|
|
191
|
+
},
|
|
192
|
+
"pcb_component_id": "pcb_component_0",
|
|
193
|
+
"source_component_id": "source_component_0",
|
|
194
|
+
"footprinter_string": "0402"
|
|
195
|
+
}
|
|
196
|
+
]
|
package/bun.lockb
CHANGED
|
Binary file
|
package/cli/main.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander"
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises"
|
|
4
|
+
import { convertCircuitJsonToTscircuit } from "../lib"
|
|
5
|
+
import type { CircuitJson } from "circuit-json"
|
|
6
|
+
import pkg from "../package.json"
|
|
7
|
+
|
|
8
|
+
const program = new Command()
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name("circuit-json-to-tscircuit")
|
|
12
|
+
.description("Convert circuit.json files to TSCircuit components")
|
|
13
|
+
.version(pkg.version)
|
|
14
|
+
.argument("<input>", "Input circuit.json file path")
|
|
15
|
+
.option("-o, --output <path>", "Output TSX file path")
|
|
16
|
+
.option("-n, --name <name>", "Component name")
|
|
17
|
+
.action(async (input, options) => {
|
|
18
|
+
if (!options.output) {
|
|
19
|
+
throw new Error("Output path is required. Use -o or --output option.")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log(`Converting ${input} to ${options.output}`)
|
|
23
|
+
|
|
24
|
+
// Read input JSON file
|
|
25
|
+
console.log("Reading input file...")
|
|
26
|
+
const jsonContent = await readFile(input, "utf-8")
|
|
27
|
+
console.log("Parsing JSON...")
|
|
28
|
+
const circuitJson = JSON.parse(jsonContent) as CircuitJson
|
|
29
|
+
|
|
30
|
+
// Convert to TSCircuit
|
|
31
|
+
if (!Array.isArray(circuitJson)) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"Invalid circuit.json: expected an array of circuit elements",
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log("Converting to TSCircuit...")
|
|
38
|
+
const tsxContent = convertCircuitJsonToTscircuit(circuitJson, {
|
|
39
|
+
componentName: options.name || "Circuit",
|
|
40
|
+
})
|
|
41
|
+
console.log("TSX content generated")
|
|
42
|
+
|
|
43
|
+
// Write output TSX file
|
|
44
|
+
console.log("Writing output file...")
|
|
45
|
+
await writeFile(options.output, tsxContent, "utf-8")
|
|
46
|
+
|
|
47
|
+
console.log("Conversion completed successfully!")
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
if (process.argv.length === 2) {
|
|
51
|
+
program.help()
|
|
52
|
+
} else {
|
|
53
|
+
program.parse()
|
|
54
|
+
}
|