@modular-circuit/transpiler 0.1.12 → 0.1.13
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/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +87 -32
- package/dist/index.mjs +85 -30
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -136,13 +136,13 @@ declare function convert_graph_to_design_block(ctx: ConvertGraphToKiCadInput): P
|
|
|
136
136
|
|
|
137
137
|
declare const KICAD_SCH_FRAME: string;
|
|
138
138
|
declare class KiCadProjectArchive {
|
|
139
|
-
|
|
140
|
-
sheets: Record<string, string>;
|
|
139
|
+
private designBlock;
|
|
141
140
|
kicad_sym?: string;
|
|
142
141
|
fp_lib_table?: string;
|
|
143
142
|
layout_frame?: string;
|
|
144
143
|
pcb?: string;
|
|
145
144
|
sym_lib_table?: string;
|
|
145
|
+
project_name: string;
|
|
146
146
|
get sch_frame(): string;
|
|
147
147
|
get kicad_prl(): {
|
|
148
148
|
board: {
|
|
@@ -367,7 +367,7 @@ declare class KiCadProjectArchive {
|
|
|
367
367
|
text_variables: {};
|
|
368
368
|
};
|
|
369
369
|
get main_sch_name(): string;
|
|
370
|
-
constructor(
|
|
370
|
+
constructor(designBlock: DesignBlockContent);
|
|
371
371
|
get_project_directive_file_name(ext: string): string;
|
|
372
372
|
toZip(): Promise<Blob>;
|
|
373
373
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -136,13 +136,13 @@ declare function convert_graph_to_design_block(ctx: ConvertGraphToKiCadInput): P
|
|
|
136
136
|
|
|
137
137
|
declare const KICAD_SCH_FRAME: string;
|
|
138
138
|
declare class KiCadProjectArchive {
|
|
139
|
-
|
|
140
|
-
sheets: Record<string, string>;
|
|
139
|
+
private designBlock;
|
|
141
140
|
kicad_sym?: string;
|
|
142
141
|
fp_lib_table?: string;
|
|
143
142
|
layout_frame?: string;
|
|
144
143
|
pcb?: string;
|
|
145
144
|
sym_lib_table?: string;
|
|
145
|
+
project_name: string;
|
|
146
146
|
get sch_frame(): string;
|
|
147
147
|
get kicad_prl(): {
|
|
148
148
|
board: {
|
|
@@ -367,7 +367,7 @@ declare class KiCadProjectArchive {
|
|
|
367
367
|
text_variables: {};
|
|
368
368
|
};
|
|
369
369
|
get main_sch_name(): string;
|
|
370
|
-
constructor(
|
|
370
|
+
constructor(designBlock: DesignBlockContent);
|
|
371
371
|
get_project_directive_file_name(ext: string): string;
|
|
372
372
|
toZip(): Promise<Blob>;
|
|
373
373
|
}
|
package/dist/index.js
CHANGED
|
@@ -2501,9 +2501,6 @@ async function convert_graph_to_sheets(ctx) {
|
|
|
2501
2501
|
});
|
|
2502
2502
|
}
|
|
2503
2503
|
|
|
2504
|
-
// src/kicad/project/kicad_project_archive.ts
|
|
2505
|
-
var import_utils16 = require("@modular-circuit/utils");
|
|
2506
|
-
|
|
2507
2504
|
// src/kicad/project/kicad_prl.ts
|
|
2508
2505
|
var kicad_prl = (prj_name) => ({
|
|
2509
2506
|
board: {
|
|
@@ -2816,16 +2813,18 @@ var kicad_pro = (project_name) => ({
|
|
|
2816
2813
|
});
|
|
2817
2814
|
|
|
2818
2815
|
// src/kicad/project/kicad_project_archive.ts
|
|
2819
|
-
var
|
|
2816
|
+
var import_utils16 = require("@modular-circuit/utils");
|
|
2817
|
+
var import_jszip = __toESM(require("jszip"));
|
|
2820
2818
|
var KICAD_SCH_FRAME = get_sch_default_drawing_sheet();
|
|
2821
2819
|
var KiCadProjectArchive = class {
|
|
2822
|
-
constructor(
|
|
2823
|
-
this.
|
|
2824
|
-
this.
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2820
|
+
constructor(designBlock) {
|
|
2821
|
+
this.designBlock = designBlock;
|
|
2822
|
+
if (!this.designBlock.root) {
|
|
2823
|
+
throw new Error("No root sch file found");
|
|
2824
|
+
}
|
|
2825
|
+
this.project_name = this.designBlock.root.split(".")[0];
|
|
2826
|
+
if (!this.project_name) {
|
|
2827
|
+
throw new Error(`Cannot get project name from ${this.designBlock.root}`);
|
|
2829
2828
|
}
|
|
2830
2829
|
}
|
|
2831
2830
|
get sch_frame() {
|
|
@@ -2838,38 +2837,87 @@ var KiCadProjectArchive = class {
|
|
|
2838
2837
|
return kicad_pro(this.project_name);
|
|
2839
2838
|
}
|
|
2840
2839
|
get main_sch_name() {
|
|
2841
|
-
return this.get_project_directive_file_name(
|
|
2840
|
+
return this.get_project_directive_file_name(import_utils16.KiCadSchematicFileExtension);
|
|
2842
2841
|
}
|
|
2843
2842
|
get_project_directive_file_name(ext) {
|
|
2844
2843
|
return `${this.project_name}.${ext}`;
|
|
2845
2844
|
}
|
|
2846
|
-
toZip() {
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2845
|
+
async toZip() {
|
|
2846
|
+
const zip = new import_jszip.default();
|
|
2847
|
+
zip.file(
|
|
2848
|
+
this.get_project_directive_file_name(import_utils16.ProjectLocalSettingsFileExtension),
|
|
2849
|
+
JSON.stringify(this.kicad_prl)
|
|
2850
|
+
);
|
|
2851
|
+
zip.file(
|
|
2852
|
+
this.get_project_directive_file_name(import_utils16.ProjectFileExtension),
|
|
2853
|
+
JSON.stringify(this.kicad_pro)
|
|
2854
|
+
);
|
|
2855
|
+
zip.file(
|
|
2856
|
+
this.get_project_directive_file_name(import_utils16.DrawingSheetFileExtension),
|
|
2857
|
+
this.sch_frame
|
|
2858
|
+
);
|
|
2859
|
+
for (const schematic of this.designBlock.schematics) {
|
|
2860
|
+
zip.file(schematic.filename, schematic.content);
|
|
2861
|
+
}
|
|
2862
|
+
const fpLibTableContent = `(fp_lib_table
|
|
2863
|
+
(version 7)
|
|
2864
|
+
(lib (name "kicad_api_lib")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/kicad_api_lib.pretty")(options "Added by KiCad IPC API")(descr ""))
|
|
2865
|
+
)`;
|
|
2866
|
+
zip.file("fp-lib-table", fpLibTableContent);
|
|
2867
|
+
let symLibTableContent = "(sym_lib_table\n (version 7)\n";
|
|
2868
|
+
const existing_components = /* @__PURE__ */ new Set();
|
|
2869
|
+
if (this.designBlock.components) {
|
|
2870
|
+
for (const component of this.designBlock.components) {
|
|
2871
|
+
const symFilename = component.symbol.filename;
|
|
2872
|
+
const componentName = symFilename.replace(".kicad_sym", "");
|
|
2873
|
+
if (existing_components.has(componentName)) {
|
|
2874
|
+
continue;
|
|
2875
|
+
}
|
|
2876
|
+
existing_components.add(componentName);
|
|
2877
|
+
symLibTableContent += ` (lib (name "${componentName}")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/${symFilename}")(options "Added by KiCad IPC API")(descr ""))
|
|
2878
|
+
`;
|
|
2879
|
+
zip.file(`kicad_api_libs/${symFilename}`, component.symbol.content);
|
|
2880
|
+
if (component.footprints) {
|
|
2881
|
+
for (const fp of component.footprints) {
|
|
2882
|
+
const fpFilename = fp.footprint.filename;
|
|
2883
|
+
zip.file(
|
|
2884
|
+
`kicad_api_libs/kicad_api_lib.pretty/${fpFilename}`,
|
|
2885
|
+
fp.footprint.content
|
|
2886
|
+
);
|
|
2887
|
+
if (fp.models) {
|
|
2888
|
+
for (const model of fp.models) {
|
|
2889
|
+
zip.file(
|
|
2890
|
+
`kicad_api_libs/3d_models/${model.filename}`,
|
|
2891
|
+
model.content
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2899
|
+
symLibTableContent += ")";
|
|
2900
|
+
zip.file("sym-lib-table", symLibTableContent);
|
|
2901
|
+
if (this.designBlock.pcb?.pcb) {
|
|
2902
|
+
if (this.designBlock.pcb.pcb.content) {
|
|
2903
|
+
zip.file(this.designBlock.pcb.pcb.filename, this.designBlock.pcb.pcb.content);
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
2907
|
+
return blob;
|
|
2853
2908
|
}
|
|
2854
2909
|
};
|
|
2855
2910
|
|
|
2856
|
-
// src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
|
|
2857
|
-
async function convert_graph_to_kicad_project(ctx) {
|
|
2858
|
-
const sheets = await convert_graph_to_sheets(ctx);
|
|
2859
|
-
const kicad_project = new KiCadProjectArchive(ctx.project.name, {
|
|
2860
|
-
...sheets
|
|
2861
|
-
});
|
|
2862
|
-
return kicad_project.toZip();
|
|
2863
|
-
}
|
|
2864
|
-
|
|
2865
2911
|
// src/builder/graph_to_kicad/convert_graph_to_design_block.ts
|
|
2912
|
+
var import_utils17 = require("@modular-circuit/utils");
|
|
2866
2913
|
async function convert_graph_to_design_block(ctx) {
|
|
2914
|
+
const root = ctx.project.main.replace(import_utils17.ModularCircuitFileExtension, import_utils17.KiCadSchematicFileExtension);
|
|
2867
2915
|
const sheets = await convert_graph_to_sheets(ctx);
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
}
|
|
2916
|
+
if (!(root in sheets)) {
|
|
2917
|
+
throw new Error(`Cannot find root sch file ${root}`);
|
|
2918
|
+
}
|
|
2871
2919
|
const design_block = {
|
|
2872
|
-
root
|
|
2920
|
+
root,
|
|
2873
2921
|
pcb: null,
|
|
2874
2922
|
components: [],
|
|
2875
2923
|
schematics: Object.entries(sheets).map(([filename, content]) => {
|
|
@@ -2881,6 +2929,13 @@ async function convert_graph_to_design_block(ctx) {
|
|
|
2881
2929
|
};
|
|
2882
2930
|
return design_block;
|
|
2883
2931
|
}
|
|
2932
|
+
|
|
2933
|
+
// src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
|
|
2934
|
+
async function convert_graph_to_kicad_project(ctx) {
|
|
2935
|
+
const design_block = await convert_graph_to_design_block(ctx);
|
|
2936
|
+
const kicad_project = new KiCadProjectArchive(design_block);
|
|
2937
|
+
return kicad_project.toZip();
|
|
2938
|
+
}
|
|
2884
2939
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2885
2940
|
0 && (module.exports = {
|
|
2886
2941
|
BLOCK_PIN_GAP,
|
package/dist/index.mjs
CHANGED
|
@@ -2461,9 +2461,6 @@ async function convert_graph_to_sheets(ctx) {
|
|
|
2461
2461
|
});
|
|
2462
2462
|
}
|
|
2463
2463
|
|
|
2464
|
-
// src/kicad/project/kicad_project_archive.ts
|
|
2465
|
-
import { zipFiles } from "@modular-circuit/utils";
|
|
2466
|
-
|
|
2467
2464
|
// src/kicad/project/kicad_prl.ts
|
|
2468
2465
|
var kicad_prl = (prj_name) => ({
|
|
2469
2466
|
board: {
|
|
@@ -2782,15 +2779,17 @@ import {
|
|
|
2782
2779
|
ProjectFileExtension,
|
|
2783
2780
|
ProjectLocalSettingsFileExtension
|
|
2784
2781
|
} from "@modular-circuit/utils";
|
|
2782
|
+
import JSZip from "jszip";
|
|
2785
2783
|
var KICAD_SCH_FRAME = get_sch_default_drawing_sheet();
|
|
2786
2784
|
var KiCadProjectArchive = class {
|
|
2787
|
-
constructor(
|
|
2788
|
-
this.
|
|
2789
|
-
this.
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2785
|
+
constructor(designBlock) {
|
|
2786
|
+
this.designBlock = designBlock;
|
|
2787
|
+
if (!this.designBlock.root) {
|
|
2788
|
+
throw new Error("No root sch file found");
|
|
2789
|
+
}
|
|
2790
|
+
this.project_name = this.designBlock.root.split(".")[0];
|
|
2791
|
+
if (!this.project_name) {
|
|
2792
|
+
throw new Error(`Cannot get project name from ${this.designBlock.root}`);
|
|
2794
2793
|
}
|
|
2795
2794
|
}
|
|
2796
2795
|
get sch_frame() {
|
|
@@ -2808,33 +2807,82 @@ var KiCadProjectArchive = class {
|
|
|
2808
2807
|
get_project_directive_file_name(ext) {
|
|
2809
2808
|
return `${this.project_name}.${ext}`;
|
|
2810
2809
|
}
|
|
2811
|
-
toZip() {
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2810
|
+
async toZip() {
|
|
2811
|
+
const zip = new JSZip();
|
|
2812
|
+
zip.file(
|
|
2813
|
+
this.get_project_directive_file_name(ProjectLocalSettingsFileExtension),
|
|
2814
|
+
JSON.stringify(this.kicad_prl)
|
|
2815
|
+
);
|
|
2816
|
+
zip.file(
|
|
2817
|
+
this.get_project_directive_file_name(ProjectFileExtension),
|
|
2818
|
+
JSON.stringify(this.kicad_pro)
|
|
2819
|
+
);
|
|
2820
|
+
zip.file(
|
|
2821
|
+
this.get_project_directive_file_name(DrawingSheetFileExtension2),
|
|
2822
|
+
this.sch_frame
|
|
2823
|
+
);
|
|
2824
|
+
for (const schematic of this.designBlock.schematics) {
|
|
2825
|
+
zip.file(schematic.filename, schematic.content);
|
|
2826
|
+
}
|
|
2827
|
+
const fpLibTableContent = `(fp_lib_table
|
|
2828
|
+
(version 7)
|
|
2829
|
+
(lib (name "kicad_api_lib")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/kicad_api_lib.pretty")(options "Added by KiCad IPC API")(descr ""))
|
|
2830
|
+
)`;
|
|
2831
|
+
zip.file("fp-lib-table", fpLibTableContent);
|
|
2832
|
+
let symLibTableContent = "(sym_lib_table\n (version 7)\n";
|
|
2833
|
+
const existing_components = /* @__PURE__ */ new Set();
|
|
2834
|
+
if (this.designBlock.components) {
|
|
2835
|
+
for (const component of this.designBlock.components) {
|
|
2836
|
+
const symFilename = component.symbol.filename;
|
|
2837
|
+
const componentName = symFilename.replace(".kicad_sym", "");
|
|
2838
|
+
if (existing_components.has(componentName)) {
|
|
2839
|
+
continue;
|
|
2840
|
+
}
|
|
2841
|
+
existing_components.add(componentName);
|
|
2842
|
+
symLibTableContent += ` (lib (name "${componentName}")(type "KiCad")(uri "\${KIPRJMOD}/kicad_api_libs/${symFilename}")(options "Added by KiCad IPC API")(descr ""))
|
|
2843
|
+
`;
|
|
2844
|
+
zip.file(`kicad_api_libs/${symFilename}`, component.symbol.content);
|
|
2845
|
+
if (component.footprints) {
|
|
2846
|
+
for (const fp of component.footprints) {
|
|
2847
|
+
const fpFilename = fp.footprint.filename;
|
|
2848
|
+
zip.file(
|
|
2849
|
+
`kicad_api_libs/kicad_api_lib.pretty/${fpFilename}`,
|
|
2850
|
+
fp.footprint.content
|
|
2851
|
+
);
|
|
2852
|
+
if (fp.models) {
|
|
2853
|
+
for (const model of fp.models) {
|
|
2854
|
+
zip.file(
|
|
2855
|
+
`kicad_api_libs/3d_models/${model.filename}`,
|
|
2856
|
+
model.content
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
symLibTableContent += ")";
|
|
2865
|
+
zip.file("sym-lib-table", symLibTableContent);
|
|
2866
|
+
if (this.designBlock.pcb?.pcb) {
|
|
2867
|
+
if (this.designBlock.pcb.pcb.content) {
|
|
2868
|
+
zip.file(this.designBlock.pcb.pcb.filename, this.designBlock.pcb.pcb.content);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
const blob = await zip.generateAsync({ type: "blob" });
|
|
2872
|
+
return blob;
|
|
2818
2873
|
}
|
|
2819
2874
|
};
|
|
2820
2875
|
|
|
2821
|
-
// src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
|
|
2822
|
-
async function convert_graph_to_kicad_project(ctx) {
|
|
2823
|
-
const sheets = await convert_graph_to_sheets(ctx);
|
|
2824
|
-
const kicad_project = new KiCadProjectArchive(ctx.project.name, {
|
|
2825
|
-
...sheets
|
|
2826
|
-
});
|
|
2827
|
-
return kicad_project.toZip();
|
|
2828
|
-
}
|
|
2829
|
-
|
|
2830
2876
|
// src/builder/graph_to_kicad/convert_graph_to_design_block.ts
|
|
2877
|
+
import { KiCadSchematicFileExtension as KiCadSchematicFileExtension5, ModularCircuitFileExtension } from "@modular-circuit/utils";
|
|
2831
2878
|
async function convert_graph_to_design_block(ctx) {
|
|
2879
|
+
const root = ctx.project.main.replace(ModularCircuitFileExtension, KiCadSchematicFileExtension5);
|
|
2832
2880
|
const sheets = await convert_graph_to_sheets(ctx);
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
}
|
|
2881
|
+
if (!(root in sheets)) {
|
|
2882
|
+
throw new Error(`Cannot find root sch file ${root}`);
|
|
2883
|
+
}
|
|
2836
2884
|
const design_block = {
|
|
2837
|
-
root
|
|
2885
|
+
root,
|
|
2838
2886
|
pcb: null,
|
|
2839
2887
|
components: [],
|
|
2840
2888
|
schematics: Object.entries(sheets).map(([filename, content]) => {
|
|
@@ -2846,6 +2894,13 @@ async function convert_graph_to_design_block(ctx) {
|
|
|
2846
2894
|
};
|
|
2847
2895
|
return design_block;
|
|
2848
2896
|
}
|
|
2897
|
+
|
|
2898
|
+
// src/builder/graph_to_kicad/convert_graph_to_kicad_project.ts
|
|
2899
|
+
async function convert_graph_to_kicad_project(ctx) {
|
|
2900
|
+
const design_block = await convert_graph_to_design_block(ctx);
|
|
2901
|
+
const kicad_project = new KiCadProjectArchive(design_block);
|
|
2902
|
+
return kicad_project.toZip();
|
|
2903
|
+
}
|
|
2849
2904
|
export {
|
|
2850
2905
|
BLOCK_PIN_GAP,
|
|
2851
2906
|
BLOCK_PIN_TB_MARGIN,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modular-circuit/transpiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Intermediate representation of the modular circuit",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"elkjs": "^0.11.0",
|
|
30
30
|
"js-base64": "^3.7.7",
|
|
31
31
|
"jszip": "^3.10.1",
|
|
32
|
+
"@modular-circuit/ir": "0.1.4",
|
|
32
33
|
"@modular-circuit/electronics-model": "0.1.1",
|
|
33
|
-
"@modular-circuit/
|
|
34
|
-
"@modular-circuit/utils": "0.1.
|
|
35
|
-
"@modular-circuit/perc": "0.1.4"
|
|
34
|
+
"@modular-circuit/perc": "0.1.4",
|
|
35
|
+
"@modular-circuit/utils": "0.1.5"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"clean": "rimraf dist",
|