circuit-json-to-kicad 0.0.3 → 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # circuit-json-to-kicad
2
2
 
3
- Convert [Circuit JSON](https://github.com/tscircuit/circuit-json) files to KiCad schematic (`.kicad_sch`) and PCB (`.kicad_pcb`) files.
3
+ Convert [Circuit JSON](https://github.com/tscircuit/circuit-json) files to KiCad schematic (`.kicad_sch`), PCB (`.kicad_pcb`), and project (`.kicad_pro`) files.
4
4
 
5
5
  Circuit JSON is an open-source file format for describing electronic circuits. This library enables you to generate KiCad-compatible files from Circuit JSON, allowing you to use KiCad's powerful PCB design tools with circuits defined in code.
6
6
 
@@ -49,6 +49,26 @@ const kicadPcbContent = converter.getOutputString()
49
49
  Bun.write("output.kicad_pcb", kicadPcbContent)
50
50
  ```
51
51
 
52
+ ### Generating a KiCad Project
53
+
54
+ ```typescript
55
+ import { CircuitJsonToKicadProConverter } from "circuit-json-to-kicad"
56
+
57
+ const circuitJson = /* your circuit JSON */
58
+
59
+ const converter = new CircuitJsonToKicadProConverter(circuitJson, {
60
+ projectName: "my_project",
61
+ schematicFilename: "my_project.kicad_sch",
62
+ pcbFilename: "my_project.kicad_pcb",
63
+ })
64
+
65
+ converter.runUntilFinished()
66
+
67
+ const kicadProjectContent = converter.getOutputString()
68
+
69
+ Bun.write("my_project.kicad_pro", kicadProjectContent)
70
+ ```
71
+
52
72
  ### Complete Example with tscircuit
53
73
 
54
74
  ```typescript
@@ -102,6 +122,7 @@ Bun.write("output.kicad_pcb", pcbConverter.getOutputString())
102
122
  - Vias
103
123
  - Board outlines and graphics
104
124
  - Net assignments
125
+ - **Project Generation**: Produce KiCad project files (`.kicad_pro`) that reference the generated schematic and PCB outputs
105
126
 
106
127
  ## Development
107
128
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CircuitJson } from 'circuit-json';
2
- import { CircuitJsonUtilObjects } from '@tscircuit/circuit-json-util';
2
+ import { CircuitJsonUtilObjects, cju } from '@tscircuit/circuit-json-util';
3
3
  import { KicadSch, KicadPcb } from 'kicadts';
4
4
  import { Matrix } from 'transformation-matrix';
5
5
 
@@ -71,4 +71,76 @@ declare class CircuitJsonToKicadPcbConverter {
71
71
  getOutputString(): string;
72
72
  }
73
73
 
74
- export { CircuitJsonToKicadPcbConverter, CircuitJsonToKicadSchConverter };
74
+ interface CircuitJsonToKicadProOptions {
75
+ projectName?: string;
76
+ schematicFilename?: string;
77
+ pcbFilename?: string;
78
+ }
79
+ interface KicadProProject {
80
+ version: number;
81
+ head: {
82
+ generator: string;
83
+ generator_version: string;
84
+ project_name: string;
85
+ created: string;
86
+ modified: string;
87
+ };
88
+ meta: {
89
+ version: number;
90
+ };
91
+ text_variables: Record<string, string>;
92
+ libraries: {
93
+ pinned_symbol_libs: string[];
94
+ pinned_footprint_libs: string[];
95
+ };
96
+ boards: string[];
97
+ cvpcb: {
98
+ meta: {
99
+ version: number;
100
+ };
101
+ };
102
+ erc: {
103
+ meta: {
104
+ version: number;
105
+ };
106
+ erc_exclusions: unknown[];
107
+ };
108
+ net_settings: {
109
+ meta: {
110
+ version: number;
111
+ };
112
+ last_net_id: number;
113
+ classes: unknown[];
114
+ };
115
+ pcbnew: {
116
+ page_layout_descr_file: string;
117
+ last_paths: Record<string, string>;
118
+ };
119
+ schematic: {
120
+ meta: {
121
+ version: number;
122
+ };
123
+ page_layout_descr_file: string;
124
+ last_opened_files: string[];
125
+ };
126
+ board: {
127
+ meta: {
128
+ version: number;
129
+ };
130
+ last_opened_board: string;
131
+ };
132
+ sheets: [string, string][];
133
+ }
134
+ declare class CircuitJsonToKicadProConverter {
135
+ ctx: {
136
+ db: ReturnType<typeof cju>;
137
+ circuitJson: CircuitJson;
138
+ };
139
+ private project;
140
+ constructor(circuitJson: CircuitJson, options?: CircuitJsonToKicadProOptions);
141
+ runUntilFinished(): void;
142
+ getOutput(): KicadProProject;
143
+ getOutputString(): string;
144
+ }
145
+
146
+ export { CircuitJsonToKicadPcbConverter, CircuitJsonToKicadProConverter, CircuitJsonToKicadSchConverter };
package/dist/index.js CHANGED
@@ -769,7 +769,7 @@ var AddSchematicTracesStage = class extends ConverterStage {
769
769
  y: junction.y
770
770
  });
771
771
  const kicadJunction = new Junction({
772
- at: [x, y, 0],
772
+ at: [x, y],
773
773
  diameter: 0
774
774
  // 0 means use default diameter
775
775
  });
@@ -1335,7 +1335,91 @@ var CircuitJsonToKicadPcbConverter = class {
1335
1335
  return this.ctx.kicadPcb.getString();
1336
1336
  }
1337
1337
  };
1338
+
1339
+ // lib/project/CircuitJsonToKicadProConverter.ts
1340
+ import { cju as cju3 } from "@tscircuit/circuit-json-util";
1341
+ import { randomUUID } from "crypto";
1342
+ var CircuitJsonToKicadProConverter = class {
1343
+ ctx;
1344
+ project;
1345
+ constructor(circuitJson, options = {}) {
1346
+ const projectName = options.projectName ?? // @ts-expect-error project metadata is optional in circuit json
1347
+ circuitJson?.project?.name ?? "circuit-json-project";
1348
+ const schematicFilename = options.schematicFilename ?? `${projectName}.kicad_sch`;
1349
+ const pcbFilename = options.pcbFilename ?? `${projectName}.kicad_pcb`;
1350
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
1351
+ this.ctx = {
1352
+ db: cju3(circuitJson),
1353
+ circuitJson
1354
+ };
1355
+ this.project = {
1356
+ version: 1,
1357
+ head: {
1358
+ generator: "circuit-json-to-kicad",
1359
+ generator_version: "0.0.1",
1360
+ project_name: projectName,
1361
+ created: timestamp,
1362
+ modified: timestamp
1363
+ },
1364
+ meta: {
1365
+ version: 1
1366
+ },
1367
+ text_variables: {},
1368
+ libraries: {
1369
+ pinned_symbol_libs: [],
1370
+ pinned_footprint_libs: []
1371
+ },
1372
+ boards: [],
1373
+ cvpcb: {
1374
+ meta: {
1375
+ version: 0
1376
+ }
1377
+ },
1378
+ erc: {
1379
+ meta: {
1380
+ version: 0
1381
+ },
1382
+ erc_exclusions: []
1383
+ },
1384
+ net_settings: {
1385
+ meta: {
1386
+ version: 1
1387
+ },
1388
+ last_net_id: 0,
1389
+ classes: []
1390
+ },
1391
+ pcbnew: {
1392
+ page_layout_descr_file: "",
1393
+ last_paths: {}
1394
+ },
1395
+ schematic: {
1396
+ meta: {
1397
+ version: 1
1398
+ },
1399
+ page_layout_descr_file: "",
1400
+ last_opened_files: [schematicFilename]
1401
+ },
1402
+ board: {
1403
+ meta: {
1404
+ version: 1
1405
+ },
1406
+ last_opened_board: pcbFilename
1407
+ },
1408
+ sheets: [[randomUUID(), "Root"]]
1409
+ };
1410
+ }
1411
+ runUntilFinished() {
1412
+ }
1413
+ getOutput() {
1414
+ return this.project;
1415
+ }
1416
+ getOutputString() {
1417
+ return `${JSON.stringify(this.project, null, 2)}
1418
+ `;
1419
+ }
1420
+ };
1338
1421
  export {
1339
1422
  CircuitJsonToKicadPcbConverter,
1423
+ CircuitJsonToKicadProConverter,
1340
1424
  CircuitJsonToKicadSchConverter
1341
1425
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "circuit-json-to-kicad",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"