@tscircuit/cli 0.0.96 → 0.0.98
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.lockb +0 -0
- package/dev-server-frontend/bun.lockb +0 -0
- package/dev-server-frontend/package.json +3 -3
- package/dist/cli.js +86 -30
- package/lib/cmd-fns/dev/start-edit-event-watcher.ts +156 -50
- package/package.json +5 -2
- package/tests/assets/example-project/examples/basic-bug.tsx +5 -6
- package/tests/assets/example-project/package.json +2 -2
- package/tests/assets/example-project/src/MyCircuit.tsx +22 -0
- package/tests/assets/example-project/src/manual-edits.ts +3 -20
|
@@ -6,17 +6,11 @@ import fg from "fast-glob"
|
|
|
6
6
|
import fs from "fs"
|
|
7
7
|
import { Project, ts } from "ts-morph"
|
|
8
8
|
import * as Path from "path"
|
|
9
|
-
import { ManualPcbPosition } from "@tscircuit/builder"
|
|
9
|
+
import type { ManualPcbPosition } from "@tscircuit/builder"
|
|
10
10
|
import { deriveSelectorFromPcbComponentId } from "./derive-selector-from-pcb-component-id"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
edit_event_id: string
|
|
15
|
-
pcb_edit_event_type: "edit_component_location"
|
|
16
|
-
pcb_component_id: string
|
|
17
|
-
original_center: { x: number; y: number }
|
|
18
|
-
new_center: { x: number; y: number }
|
|
19
|
-
}
|
|
11
|
+
import type { EditEvent } from "@tscircuit/manual-edit-events"
|
|
12
|
+
import { getManualTraceHintFromEvent, ManualTraceHint } from "@tscircuit/layout"
|
|
13
|
+
import JSON5 from "json5"
|
|
20
14
|
|
|
21
15
|
export const startEditEventWatcher = async (
|
|
22
16
|
{
|
|
@@ -142,11 +136,34 @@ export const startEditEventWatcher = async (
|
|
|
142
136
|
const pcb_placements_ts =
|
|
143
137
|
object_literal.getPropertyOrThrow("pcb_placements")
|
|
144
138
|
|
|
139
|
+
if (object_literal.getProperty("edit_events") === undefined) {
|
|
140
|
+
object_literal.addPropertyAssignment({
|
|
141
|
+
name: "edit_events",
|
|
142
|
+
initializer: "[]",
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const edit_events_ts =
|
|
147
|
+
object_literal.getPropertyOrThrow("edit_events")
|
|
148
|
+
|
|
149
|
+
if (
|
|
150
|
+
object_literal.getProperty("manual_trace_hints") === undefined
|
|
151
|
+
) {
|
|
152
|
+
object_literal.addPropertyAssignment({
|
|
153
|
+
name: "manual_trace_hints",
|
|
154
|
+
initializer: "[]",
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
const manual_trace_hints_ts =
|
|
158
|
+
object_literal.getPropertyOrThrow("manual_trace_hints")
|
|
159
|
+
|
|
145
160
|
let pcb_placements: (ManualPcbPosition & {
|
|
146
161
|
_edit_event_id?: string
|
|
147
162
|
})[]
|
|
163
|
+
let in_file_edit_events: EditEvent[]
|
|
164
|
+
let manual_trace_hints: ManualTraceHint[]
|
|
148
165
|
try {
|
|
149
|
-
pcb_placements =
|
|
166
|
+
pcb_placements = JSON5.parse(
|
|
150
167
|
pcb_placements_ts.getText().replace(/pcb_placements:\s/, "")
|
|
151
168
|
)
|
|
152
169
|
} catch (e: any) {
|
|
@@ -157,60 +174,149 @@ export const startEditEventWatcher = async (
|
|
|
157
174
|
)
|
|
158
175
|
continue
|
|
159
176
|
}
|
|
177
|
+
try {
|
|
178
|
+
in_file_edit_events = JSON5.parse(
|
|
179
|
+
edit_events_ts.getText().replace(/edit_events:\s/, "")
|
|
180
|
+
)
|
|
181
|
+
} catch (e: any) {
|
|
182
|
+
console.log(
|
|
183
|
+
kleur.red(
|
|
184
|
+
`Error parsing edit_events from manual edits file: ${edit_events_ts.getText()} ${e.toString()}`
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
manual_trace_hints = JSON5.parse(
|
|
191
|
+
manual_trace_hints_ts
|
|
192
|
+
.getText()
|
|
193
|
+
.replace(/manual_trace_hints:\s/, "")
|
|
194
|
+
)
|
|
195
|
+
} catch (e: any) {
|
|
196
|
+
console.log(
|
|
197
|
+
kleur.red(
|
|
198
|
+
`Error parsing manual_trace_hints from manual edits file: ${pcb_placements_ts.getText()} ${e.toString()}`
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
160
203
|
|
|
161
204
|
const handled_edit_events = new Set<string>(
|
|
162
205
|
pcb_placements
|
|
163
206
|
.map((p) => (p as any)._edit_event_id)
|
|
164
|
-
.
|
|
207
|
+
.concat(in_file_edit_events.map((a) => a.edit_event_id))
|
|
165
208
|
)
|
|
166
209
|
|
|
167
210
|
// Add PCB placements from edit events
|
|
168
|
-
for (const
|
|
169
|
-
if (handled_edit_events.has(
|
|
211
|
+
for (const incoming_edit_event of edit_events) {
|
|
212
|
+
if (handled_edit_events.has(incoming_edit_event.edit_event_id))
|
|
213
|
+
continue
|
|
214
|
+
|
|
215
|
+
if (
|
|
216
|
+
incoming_edit_event.pcb_edit_event_type ===
|
|
217
|
+
"edit_component_location"
|
|
218
|
+
) {
|
|
219
|
+
// TODO Figure out a good selector for this pcb_component
|
|
220
|
+
let pcb_component_selector: string | null = null
|
|
221
|
+
if (incoming_edit_event.pcb_component_id) {
|
|
222
|
+
pcb_component_selector = deriveSelectorFromPcbComponentId({
|
|
223
|
+
soup: dev_package_example_full.tscircuit_soup,
|
|
224
|
+
pcb_component_id: incoming_edit_event.pcb_component_id,
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// TODO we'll need to work past this for edit_event_type=edit_trace
|
|
229
|
+
if (!pcb_component_selector) continue
|
|
230
|
+
|
|
231
|
+
const existing_placement_for_selector = pcb_placements.find(
|
|
232
|
+
(pp) => pp.selector === pcb_component_selector
|
|
233
|
+
)
|
|
170
234
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
235
|
+
if (!existing_placement_for_selector) {
|
|
236
|
+
console.log(
|
|
237
|
+
kleur.gray(
|
|
238
|
+
` adding PCB placement from edit event for "${pcb_component_selector}"`
|
|
239
|
+
)
|
|
240
|
+
)
|
|
176
241
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
242
|
+
pcb_placements.push({
|
|
243
|
+
_edit_event_id: incoming_edit_event.edit_event_id,
|
|
244
|
+
selector: pcb_component_selector,
|
|
245
|
+
center: incoming_edit_event.new_center,
|
|
246
|
+
relative_to: "group_center",
|
|
247
|
+
})
|
|
248
|
+
} else {
|
|
249
|
+
existing_placement_for_selector.center =
|
|
250
|
+
incoming_edit_event.new_center
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Edit the pcb placements object
|
|
254
|
+
pcb_placements_ts.replaceWithText(
|
|
255
|
+
`pcb_placements: ${JSON.stringify(
|
|
256
|
+
pcb_placements,
|
|
257
|
+
null,
|
|
258
|
+
" "
|
|
259
|
+
)}`
|
|
260
|
+
)
|
|
180
261
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
262
|
+
// Save the file
|
|
263
|
+
fs.writeFileSync(
|
|
264
|
+
Path.join(ctx.cwd, manual_edit_file),
|
|
265
|
+
ts_manual_edits_file.getFullText()
|
|
266
|
+
)
|
|
267
|
+
await devServerAxios.post("/api/dev_package_examples/update", {
|
|
268
|
+
dev_package_example_id,
|
|
269
|
+
edit_events_last_applied_at:
|
|
270
|
+
dev_package_example.edit_events_last_updated_at,
|
|
271
|
+
})
|
|
272
|
+
} else if (
|
|
273
|
+
incoming_edit_event.pcb_edit_event_type === "edit_trace_hint"
|
|
274
|
+
) {
|
|
275
|
+
const new_trace_hint = getManualTraceHintFromEvent(
|
|
276
|
+
dev_package_example_full.tscircuit_soup,
|
|
277
|
+
incoming_edit_event
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
manual_trace_hints_ts.replaceWithText(
|
|
281
|
+
`manual_trace_hints: ${JSON.stringify(
|
|
282
|
+
manual_trace_hints
|
|
283
|
+
.filter(
|
|
284
|
+
(th) =>
|
|
285
|
+
th.pcb_port_selector !==
|
|
286
|
+
new_trace_hint.pcb_port_selector
|
|
287
|
+
)
|
|
288
|
+
.concat([new_trace_hint]),
|
|
289
|
+
null,
|
|
290
|
+
" "
|
|
291
|
+
)}`
|
|
186
292
|
)
|
|
187
293
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
294
|
+
fs.writeFileSync(
|
|
295
|
+
Path.join(ctx.cwd, manual_edit_file),
|
|
296
|
+
ts_manual_edits_file.getFullText()
|
|
297
|
+
)
|
|
298
|
+
await devServerAxios.post("/api/dev_package_examples/update", {
|
|
299
|
+
dev_package_example_id,
|
|
300
|
+
edit_events_last_applied_at:
|
|
301
|
+
dev_package_example.edit_events_last_updated_at,
|
|
193
302
|
})
|
|
194
303
|
} else {
|
|
195
|
-
|
|
304
|
+
// All other events just go to the manual-edits.ts file with
|
|
305
|
+
// in the "edit_events" property
|
|
306
|
+
edit_events_ts.replaceWithText(
|
|
307
|
+
`edit_events: ${JSON.stringify(edit_events, null, " ")}`
|
|
308
|
+
)
|
|
309
|
+
console.log(edit_events_ts.getFullText())
|
|
310
|
+
fs.writeFileSync(
|
|
311
|
+
Path.join(ctx.cwd, manual_edit_file),
|
|
312
|
+
ts_manual_edits_file.getFullText()
|
|
313
|
+
)
|
|
314
|
+
await devServerAxios.post("/api/dev_package_examples/update", {
|
|
315
|
+
dev_package_example_id,
|
|
316
|
+
edit_events_last_applied_at:
|
|
317
|
+
dev_package_example.edit_events_last_updated_at,
|
|
318
|
+
})
|
|
196
319
|
}
|
|
197
|
-
|
|
198
|
-
// Edit the pcb placements object
|
|
199
|
-
pcb_placements_ts.replaceWithText(
|
|
200
|
-
`pcb_placements: ${JSON.stringify(pcb_placements, null, " ")}`
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
// Save the file
|
|
204
|
-
|
|
205
|
-
fs.writeFileSync(
|
|
206
|
-
Path.join(ctx.cwd, manual_edit_file),
|
|
207
|
-
ts_manual_edits_file.getFullText()
|
|
208
|
-
)
|
|
209
|
-
await devServerAxios.post("/api/dev_package_examples/update", {
|
|
210
|
-
dev_package_example_id,
|
|
211
|
-
edit_events_last_applied_at:
|
|
212
|
-
dev_package_example.edit_events_last_updated_at,
|
|
213
|
-
})
|
|
214
320
|
}
|
|
215
321
|
}
|
|
216
322
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.98",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Command line tool for developing, publishing and installing tscircuit circuits",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@edge-runtime/primitives": "^4.1.0",
|
|
37
37
|
"@hono/node-server": "^1.8.2",
|
|
38
|
-
"@tscircuit/builder": "^1.5.
|
|
38
|
+
"@tscircuit/builder": "^1.5.118",
|
|
39
|
+
"@tscircuit/layout": "^0.0.20",
|
|
39
40
|
"@tscircuit/react-fiber": "^1.1.27",
|
|
40
41
|
"@tscircuit/soup-util": "^0.0.1",
|
|
41
42
|
"archiver": "^7.0.1",
|
|
@@ -67,9 +68,11 @@
|
|
|
67
68
|
"semver": "^7.6.0",
|
|
68
69
|
"ts-morph": "^22.0.0",
|
|
69
70
|
"tsup": "^8.0.2",
|
|
71
|
+
"json5": "^2.2.3",
|
|
70
72
|
"zod": "latest"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
75
|
+
"@tscircuit/manual-edit-events": "^0.0.4",
|
|
73
76
|
"@types/archiver": "^6.0.2",
|
|
74
77
|
"@types/bun": "^1.0.8",
|
|
75
78
|
"@types/chokidar": "^2.1.3",
|
|
@@ -9,13 +9,12 @@ export const BasicBug = () => (
|
|
|
9
9
|
>
|
|
10
10
|
<bug
|
|
11
11
|
name="U2"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
schPortArrangement={{
|
|
13
|
+
leftSize: 4,
|
|
14
|
+
rightSize: 4,
|
|
15
15
|
}}
|
|
16
|
-
footprint="
|
|
17
|
-
|
|
18
|
-
port_labels={{
|
|
16
|
+
footprint="ssop16"
|
|
17
|
+
pinLabels={{
|
|
19
18
|
"1": "GND",
|
|
20
19
|
"2": "VBUS",
|
|
21
20
|
"3": "D-",
|
|
@@ -13,10 +13,32 @@ export const MyCircuit = () => (
|
|
|
13
13
|
<resistor
|
|
14
14
|
name="R1"
|
|
15
15
|
resistance="20kohm"
|
|
16
|
+
pcbX={0}
|
|
17
|
+
pcbY={0}
|
|
16
18
|
footprint="0805"
|
|
17
19
|
supplierPartNumbers={{
|
|
18
20
|
jlcpcb: ["C2759650"],
|
|
19
21
|
}}
|
|
20
22
|
/>
|
|
23
|
+
<resistor
|
|
24
|
+
name="R2"
|
|
25
|
+
pcbX={5}
|
|
26
|
+
pcbY={0}
|
|
27
|
+
resistance="20kohm"
|
|
28
|
+
footprint="0805"
|
|
29
|
+
supplierPartNumbers={{
|
|
30
|
+
jlcpcb: ["C2759650"],
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
<trace from=".R1 > .right" to=".R2 > .left" />
|
|
34
|
+
{/* <tracehint
|
|
35
|
+
for=".R1 > .right"
|
|
36
|
+
offsets={[
|
|
37
|
+
{
|
|
38
|
+
x: 3,
|
|
39
|
+
y: 3,
|
|
40
|
+
},
|
|
41
|
+
]}
|
|
42
|
+
/> */}
|
|
21
43
|
</board>
|
|
22
44
|
)
|
|
@@ -14,24 +14,7 @@ export default {
|
|
|
14
14
|
manual_edit_id: "abcdef",
|
|
15
15
|
|
|
16
16
|
// Manual pcb placements, added when you drag a footprint
|
|
17
|
-
pcb_placements: [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"selector": ".U2",
|
|
21
|
-
"center": {
|
|
22
|
-
"x": 13.777148607991913,
|
|
23
|
-
"y": -10.354434189987284
|
|
24
|
-
},
|
|
25
|
-
"relative_to": "group_center"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"_edit_event_id": "0.37279140805799216",
|
|
29
|
-
"selector": ".R1",
|
|
30
|
-
"center": {
|
|
31
|
-
"x": 5.433378371344073,
|
|
32
|
-
"y": -6.95083299460385
|
|
33
|
-
},
|
|
34
|
-
"relative_to": "group_center"
|
|
35
|
-
}
|
|
36
|
-
],
|
|
17
|
+
pcb_placements: [],
|
|
18
|
+
manual_trace_hints: [],
|
|
19
|
+
edit_events: [],
|
|
37
20
|
}
|