@tscircuit/cli 0.1.795 → 0.1.796
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/main.js +316 -16
- package/package.json +4 -4
package/dist/main.js
CHANGED
|
@@ -74141,7 +74141,7 @@ var package_default = {
|
|
|
74141
74141
|
"@tscircuit/fake-snippets": "^0.0.182",
|
|
74142
74142
|
"@tscircuit/file-server": "^0.0.32",
|
|
74143
74143
|
"@tscircuit/math-utils": "0.0.29",
|
|
74144
|
-
"@tscircuit/props": "^0.0.
|
|
74144
|
+
"@tscircuit/props": "^0.0.448",
|
|
74145
74145
|
"@tscircuit/runframe": "^0.0.1510",
|
|
74146
74146
|
"@tscircuit/schematic-match-adapt": "^0.0.22",
|
|
74147
74147
|
"@types/bun": "^1.2.2",
|
|
@@ -74156,7 +74156,7 @@ var package_default = {
|
|
|
74156
74156
|
chokidar: "4.0.1",
|
|
74157
74157
|
"circuit-json": "0.0.325",
|
|
74158
74158
|
"circuit-json-to-gltf": "^0.0.58",
|
|
74159
|
-
"circuit-json-to-kicad": "^0.0.
|
|
74159
|
+
"circuit-json-to-kicad": "^0.0.38",
|
|
74160
74160
|
"circuit-json-to-readable-netlist": "^0.0.13",
|
|
74161
74161
|
"circuit-json-to-spice": "^0.0.10",
|
|
74162
74162
|
"circuit-json-to-tscircuit": "^0.0.9",
|
|
@@ -74176,7 +74176,7 @@ var package_default = {
|
|
|
74176
74176
|
jszip: "^3.10.1",
|
|
74177
74177
|
"jwt-decode": "^4.0.0",
|
|
74178
74178
|
"kicad-component-converter": "^0.1.22",
|
|
74179
|
-
kicadts: "^0.0.
|
|
74179
|
+
kicadts: "^0.0.24",
|
|
74180
74180
|
kleur: "^4.1.5",
|
|
74181
74181
|
ky: "^1.7.4",
|
|
74182
74182
|
"looks-same": "^9.0.1",
|
|
@@ -81716,10 +81716,22 @@ import {
|
|
|
81716
81716
|
parseKicadSexpr as parseKicadSexpr2,
|
|
81717
81717
|
KicadPcb as KicadPcb2,
|
|
81718
81718
|
FootprintModel as FootprintModel2,
|
|
81719
|
-
At as At2
|
|
81719
|
+
At as At2,
|
|
81720
|
+
EmbeddedFonts as EmbeddedFonts4,
|
|
81721
|
+
FootprintAttr,
|
|
81722
|
+
Property,
|
|
81723
|
+
TextEffects as TextEffects6,
|
|
81724
|
+
TextEffectsFont as TextEffectsFont6
|
|
81720
81725
|
} from "kicadts";
|
|
81721
81726
|
import { KicadSymbolLib } from "kicadts";
|
|
81722
81727
|
import { parseKicadMod } from "kicadts";
|
|
81728
|
+
import {
|
|
81729
|
+
parseKicadSexpr as parseKicadSexpr3,
|
|
81730
|
+
Footprint as Footprint3,
|
|
81731
|
+
Property as Property2,
|
|
81732
|
+
TextEffects as TextEffects7,
|
|
81733
|
+
TextEffectsFont as TextEffectsFont7
|
|
81734
|
+
} from "kicadts";
|
|
81723
81735
|
import { KicadSymbolLib as KicadSymbolLib2 } from "kicadts";
|
|
81724
81736
|
var ConverterStage = class {
|
|
81725
81737
|
MAX_ITERATIONS = 1000;
|
|
@@ -83350,6 +83362,9 @@ var AddFootprintsStage = class extends ConverterStage {
|
|
|
83350
83362
|
componentRotation: component.rotation || 0
|
|
83351
83363
|
});
|
|
83352
83364
|
if (fpText) {
|
|
83365
|
+
if (sourceComponent?.name && textElement.text === sourceComponent.name) {
|
|
83366
|
+
fpText.type = "reference";
|
|
83367
|
+
}
|
|
83353
83368
|
fpTexts.push(fpText);
|
|
83354
83369
|
}
|
|
83355
83370
|
}
|
|
@@ -83935,11 +83950,69 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
83935
83950
|
footprint.position = At2.from([0, 0, 0]);
|
|
83936
83951
|
footprint.locked = false;
|
|
83937
83952
|
footprint.placed = false;
|
|
83953
|
+
if (!footprint.descr) {
|
|
83954
|
+
footprint.descr = "";
|
|
83955
|
+
}
|
|
83956
|
+
if (!footprint.tags) {
|
|
83957
|
+
footprint.tags = "";
|
|
83958
|
+
}
|
|
83959
|
+
if (!footprint.embeddedFonts) {
|
|
83960
|
+
footprint.embeddedFonts = new EmbeddedFonts4(false);
|
|
83961
|
+
}
|
|
83962
|
+
if (!footprint.attr) {
|
|
83963
|
+
const attr = new FootprintAttr;
|
|
83964
|
+
const padTypes = (footprint.fpPads ?? []).map((pad) => pad.padType);
|
|
83965
|
+
if (padTypes.some((padType) => padType.includes("thru_hole"))) {
|
|
83966
|
+
attr.type = "through_hole";
|
|
83967
|
+
} else if (padTypes.some((padType) => padType.includes("smd"))) {
|
|
83968
|
+
attr.type = "smd";
|
|
83969
|
+
}
|
|
83970
|
+
footprint.attr = attr;
|
|
83971
|
+
}
|
|
83938
83972
|
footprint.uuid = undefined;
|
|
83939
83973
|
footprint.path = undefined;
|
|
83940
83974
|
footprint.sheetfile = undefined;
|
|
83941
83975
|
footprint.sheetname = undefined;
|
|
83942
|
-
|
|
83976
|
+
const defaultFont = new TextEffectsFont6;
|
|
83977
|
+
defaultFont.size = { width: 1.27, height: 1.27 };
|
|
83978
|
+
defaultFont.thickness = 0.15;
|
|
83979
|
+
const defaultEffects = new TextEffects6({ font: defaultFont });
|
|
83980
|
+
footprint.properties = [
|
|
83981
|
+
new Property({
|
|
83982
|
+
key: "Reference",
|
|
83983
|
+
value: "Ref**",
|
|
83984
|
+
position: [0, 0, 0],
|
|
83985
|
+
layer: "F.SilkS",
|
|
83986
|
+
uuid: generateDeterministicUuid(`${footprintName}-property-Reference`),
|
|
83987
|
+
effects: defaultEffects
|
|
83988
|
+
}),
|
|
83989
|
+
new Property({
|
|
83990
|
+
key: "Value",
|
|
83991
|
+
value: "Val**",
|
|
83992
|
+
position: [0, 0, 0],
|
|
83993
|
+
layer: "F.Fab",
|
|
83994
|
+
uuid: generateDeterministicUuid(`${footprintName}-property-Value`),
|
|
83995
|
+
effects: defaultEffects
|
|
83996
|
+
}),
|
|
83997
|
+
new Property({
|
|
83998
|
+
key: "Datasheet",
|
|
83999
|
+
value: "",
|
|
84000
|
+
position: [0, 0, 0],
|
|
84001
|
+
layer: "F.Fab",
|
|
84002
|
+
hidden: true,
|
|
84003
|
+
uuid: generateDeterministicUuid(`${footprintName}-property-Datasheet`),
|
|
84004
|
+
effects: defaultEffects
|
|
84005
|
+
}),
|
|
84006
|
+
new Property({
|
|
84007
|
+
key: "Description",
|
|
84008
|
+
value: "",
|
|
84009
|
+
position: [0, 0, 0],
|
|
84010
|
+
layer: "F.Fab",
|
|
84011
|
+
hidden: true,
|
|
84012
|
+
uuid: generateDeterministicUuid(`${footprintName}-property-Description`),
|
|
84013
|
+
effects: defaultEffects
|
|
84014
|
+
})
|
|
84015
|
+
];
|
|
83943
84016
|
const texts = footprint.fpTexts ?? [];
|
|
83944
84017
|
for (const text of texts) {
|
|
83945
84018
|
text.uuid = undefined;
|
|
@@ -83951,9 +84024,12 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
83951
84024
|
}
|
|
83952
84025
|
footprint.fpTexts = texts;
|
|
83953
84026
|
const pads = footprint.fpPads ?? [];
|
|
83954
|
-
for (
|
|
83955
|
-
pad
|
|
83956
|
-
pad
|
|
84027
|
+
for (let i = 0;i < pads.length; i++) {
|
|
84028
|
+
const pad = pads[i];
|
|
84029
|
+
if (pad) {
|
|
84030
|
+
pad.uuid = generateDeterministicUuid(`${footprintName}-pad-${pad.number ?? i}`);
|
|
84031
|
+
pad.net = undefined;
|
|
84032
|
+
}
|
|
83957
84033
|
}
|
|
83958
84034
|
footprint.fpPads = pads;
|
|
83959
84035
|
const models = footprint.models ?? [];
|
|
@@ -83962,7 +84038,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
|
|
|
83962
84038
|
for (const model of models) {
|
|
83963
84039
|
if (model.path) {
|
|
83964
84040
|
const modelFilename = getBasename(model.path);
|
|
83965
|
-
const newPath =
|
|
84041
|
+
const newPath = `../../3dmodels/${fpLibraryName}.3dshapes/${modelFilename}`;
|
|
83966
84042
|
const newModel = new FootprintModel2(newPath);
|
|
83967
84043
|
if (model.offset)
|
|
83968
84044
|
newModel.offset = model.offset;
|
|
@@ -84132,9 +84208,10 @@ function renameKicadFootprint(params2) {
|
|
|
84132
84208
|
footprint.libraryLink = newKicadFootprintName;
|
|
84133
84209
|
for (const model of footprint.models) {
|
|
84134
84210
|
const currentPath = model.path;
|
|
84135
|
-
|
|
84136
|
-
|
|
84137
|
-
|
|
84211
|
+
const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
|
|
84212
|
+
if (usesProjectPath) {
|
|
84213
|
+
const filename = currentPath.split(/[\\/]/).pop() ?? "";
|
|
84214
|
+
model.path = `../../3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
|
|
84138
84215
|
}
|
|
84139
84216
|
}
|
|
84140
84217
|
return {
|
|
@@ -84143,6 +84220,106 @@ function renameKicadFootprint(params2) {
|
|
|
84143
84220
|
model3dSourcePaths: kicadFootprint.model3dSourcePaths
|
|
84144
84221
|
};
|
|
84145
84222
|
}
|
|
84223
|
+
function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
84224
|
+
try {
|
|
84225
|
+
const parsed = parseKicadSexpr3(kicadModString);
|
|
84226
|
+
const footprint = parsed.find((node) => node instanceof Footprint3);
|
|
84227
|
+
if (!footprint) {
|
|
84228
|
+
return kicadModString;
|
|
84229
|
+
}
|
|
84230
|
+
if (metadata.version !== undefined) {
|
|
84231
|
+
footprint.version = Number(metadata.version);
|
|
84232
|
+
}
|
|
84233
|
+
if (metadata.generator !== undefined) {
|
|
84234
|
+
footprint.generator = metadata.generator;
|
|
84235
|
+
}
|
|
84236
|
+
if (metadata.generatorVersion !== undefined) {
|
|
84237
|
+
footprint.generatorVersion = String(metadata.generatorVersion);
|
|
84238
|
+
}
|
|
84239
|
+
if (metadata.embeddedFonts !== undefined) {}
|
|
84240
|
+
if (metadata.properties) {
|
|
84241
|
+
const defaultFont = new TextEffectsFont7;
|
|
84242
|
+
defaultFont.size = { width: 1.27, height: 1.27 };
|
|
84243
|
+
defaultFont.thickness = 0.15;
|
|
84244
|
+
const defaultEffects = new TextEffects7({ font: defaultFont });
|
|
84245
|
+
const newProperties = [];
|
|
84246
|
+
const refMeta = metadata.properties.Reference;
|
|
84247
|
+
newProperties.push(new Property2({
|
|
84248
|
+
key: "Reference",
|
|
84249
|
+
value: refMeta?.value ?? "REF**",
|
|
84250
|
+
position: refMeta?.at ? [
|
|
84251
|
+
Number(refMeta.at.x),
|
|
84252
|
+
Number(refMeta.at.y),
|
|
84253
|
+
Number(refMeta.at.rotation ?? 0)
|
|
84254
|
+
] : [0, 0, 0],
|
|
84255
|
+
layer: refMeta?.layer ?? "F.SilkS",
|
|
84256
|
+
uuid: refMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Reference`),
|
|
84257
|
+
effects: defaultEffects,
|
|
84258
|
+
hidden: refMeta?.hide
|
|
84259
|
+
}));
|
|
84260
|
+
const valMeta = metadata.properties.Value;
|
|
84261
|
+
newProperties.push(new Property2({
|
|
84262
|
+
key: "Value",
|
|
84263
|
+
value: valMeta?.value ?? footprintName,
|
|
84264
|
+
position: valMeta?.at ? [
|
|
84265
|
+
Number(valMeta.at.x),
|
|
84266
|
+
Number(valMeta.at.y),
|
|
84267
|
+
Number(valMeta.at.rotation ?? 0)
|
|
84268
|
+
] : [0, 0, 0],
|
|
84269
|
+
layer: valMeta?.layer ?? "F.Fab",
|
|
84270
|
+
uuid: valMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Value`),
|
|
84271
|
+
effects: defaultEffects,
|
|
84272
|
+
hidden: valMeta?.hide
|
|
84273
|
+
}));
|
|
84274
|
+
const dsMeta = metadata.properties.Datasheet;
|
|
84275
|
+
newProperties.push(new Property2({
|
|
84276
|
+
key: "Datasheet",
|
|
84277
|
+
value: dsMeta?.value ?? "",
|
|
84278
|
+
position: dsMeta?.at ? [
|
|
84279
|
+
Number(dsMeta.at.x),
|
|
84280
|
+
Number(dsMeta.at.y),
|
|
84281
|
+
Number(dsMeta.at.rotation ?? 0)
|
|
84282
|
+
] : [0, 0, 0],
|
|
84283
|
+
layer: dsMeta?.layer ?? "F.Fab",
|
|
84284
|
+
uuid: dsMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Datasheet`),
|
|
84285
|
+
effects: defaultEffects,
|
|
84286
|
+
hidden: dsMeta?.hide ?? true
|
|
84287
|
+
}));
|
|
84288
|
+
const descMeta = metadata.properties.Description;
|
|
84289
|
+
newProperties.push(new Property2({
|
|
84290
|
+
key: "Description",
|
|
84291
|
+
value: descMeta?.value ?? "",
|
|
84292
|
+
position: descMeta?.at ? [
|
|
84293
|
+
Number(descMeta.at.x),
|
|
84294
|
+
Number(descMeta.at.y),
|
|
84295
|
+
Number(descMeta.at.rotation ?? 0)
|
|
84296
|
+
] : [0, 0, 0],
|
|
84297
|
+
layer: descMeta?.layer ?? "F.Fab",
|
|
84298
|
+
uuid: descMeta?.uuid ?? generateDeterministicUuid(`${footprintName}-property-Description`),
|
|
84299
|
+
effects: defaultEffects,
|
|
84300
|
+
hidden: descMeta?.hide ?? true
|
|
84301
|
+
}));
|
|
84302
|
+
footprint.properties = newProperties;
|
|
84303
|
+
}
|
|
84304
|
+
if (metadata.attributes && footprint.attr) {
|
|
84305
|
+
if (metadata.attributes.through_hole) {
|
|
84306
|
+
footprint.attr.type = "through_hole";
|
|
84307
|
+
} else if (metadata.attributes.smd) {
|
|
84308
|
+
footprint.attr.type = "smd";
|
|
84309
|
+
}
|
|
84310
|
+
if (metadata.attributes.exclude_from_pos_files !== undefined) {
|
|
84311
|
+
footprint.attr.excludeFromPosFiles = metadata.attributes.exclude_from_pos_files;
|
|
84312
|
+
}
|
|
84313
|
+
if (metadata.attributes.exclude_from_bom !== undefined) {
|
|
84314
|
+
footprint.attr.excludeFromBom = metadata.attributes.exclude_from_bom;
|
|
84315
|
+
}
|
|
84316
|
+
}
|
|
84317
|
+
return footprint.getString();
|
|
84318
|
+
} catch (error) {
|
|
84319
|
+
console.warn(`Failed to apply kicadFootprintMetadata:`, error);
|
|
84320
|
+
return kicadModString;
|
|
84321
|
+
}
|
|
84322
|
+
}
|
|
84146
84323
|
function classifyKicadFootprints(ctx) {
|
|
84147
84324
|
for (const extractedKicadComponent of ctx.extractedKicadComponents) {
|
|
84148
84325
|
classifyFootprintsForComponent({
|
|
@@ -84157,17 +84334,24 @@ function classifyFootprintsForComponent({
|
|
|
84157
84334
|
}) {
|
|
84158
84335
|
const { tscircuitComponentName, kicadFootprints } = extractedKicadComponent;
|
|
84159
84336
|
let hasAddedUserFootprint = false;
|
|
84337
|
+
const metadata = ctx.footprintMetadataMap.get(tscircuitComponentName);
|
|
84160
84338
|
for (const kicadFootprint of kicadFootprints) {
|
|
84161
84339
|
if (kicadFootprint.isBuiltin) {
|
|
84162
84340
|
addBuiltinFootprint({ ctx, kicadFootprint });
|
|
84163
84341
|
} else {
|
|
84164
84342
|
if (!hasAddedUserFootprint) {
|
|
84165
84343
|
hasAddedUserFootprint = true;
|
|
84166
|
-
|
|
84344
|
+
let renamedFootprint = renameKicadFootprint({
|
|
84167
84345
|
kicadFootprint,
|
|
84168
84346
|
newKicadFootprintName: tscircuitComponentName,
|
|
84169
84347
|
kicadLibraryName: ctx.kicadLibraryName
|
|
84170
84348
|
});
|
|
84349
|
+
if (metadata) {
|
|
84350
|
+
renamedFootprint = {
|
|
84351
|
+
...renamedFootprint,
|
|
84352
|
+
kicadModString: applyKicadFootprintMetadata(renamedFootprint.kicadModString, metadata, tscircuitComponentName)
|
|
84353
|
+
};
|
|
84354
|
+
}
|
|
84171
84355
|
addUserFootprint({ ctx, kicadFootprint: renamedFootprint });
|
|
84172
84356
|
} else {
|
|
84173
84357
|
addUserFootprint({ ctx, kicadFootprint });
|
|
@@ -84393,7 +84577,8 @@ var KicadLibraryConverter = class {
|
|
|
84393
84577
|
this.options = options;
|
|
84394
84578
|
this.ctx = createKicadLibraryConverterContext({
|
|
84395
84579
|
kicadLibraryName: options.kicadLibraryName ?? "tscircuit_library",
|
|
84396
|
-
includeBuiltins: options.includeBuiltins ?? true
|
|
84580
|
+
includeBuiltins: options.includeBuiltins ?? true,
|
|
84581
|
+
getComponentKicadMetadata: options.getComponentKicadMetadata
|
|
84397
84582
|
});
|
|
84398
84583
|
}
|
|
84399
84584
|
async run() {
|
|
@@ -84411,14 +84596,20 @@ var KicadLibraryConverter = class {
|
|
|
84411
84596
|
const builtTscircuitComponents = [];
|
|
84412
84597
|
const { entrypoint } = this.options;
|
|
84413
84598
|
const exports2 = await this.options.getExportsFromTsxFile(entrypoint);
|
|
84414
|
-
const
|
|
84415
|
-
for (const exportName of
|
|
84599
|
+
const namedExports = exports2.filter((name) => name !== "default" && /^[A-Z]/.test(name));
|
|
84600
|
+
for (const exportName of namedExports) {
|
|
84416
84601
|
let componentPath = entrypoint;
|
|
84417
84602
|
if (this.options.resolveExportPath) {
|
|
84418
84603
|
const resolved = await this.options.resolveExportPath(entrypoint, exportName);
|
|
84419
84604
|
if (resolved)
|
|
84420
84605
|
componentPath = resolved;
|
|
84421
84606
|
}
|
|
84607
|
+
if (this.ctx.getComponentKicadMetadata) {
|
|
84608
|
+
const metadata = await this.ctx.getComponentKicadMetadata(componentPath, exportName);
|
|
84609
|
+
if (metadata) {
|
|
84610
|
+
this.ctx.footprintMetadataMap.set(exportName, metadata);
|
|
84611
|
+
}
|
|
84612
|
+
}
|
|
84422
84613
|
const circuitJson = await this.options.buildFileToCircuitJson(componentPath, exportName);
|
|
84423
84614
|
if (circuitJson && (!Array.isArray(circuitJson) || circuitJson.length > 0)) {
|
|
84424
84615
|
builtTscircuitComponents.push({
|
|
@@ -84427,6 +84618,28 @@ var KicadLibraryConverter = class {
|
|
|
84427
84618
|
});
|
|
84428
84619
|
}
|
|
84429
84620
|
}
|
|
84621
|
+
if (exports2.includes("default")) {
|
|
84622
|
+
let componentPath = entrypoint;
|
|
84623
|
+
if (this.options.resolveExportPath) {
|
|
84624
|
+
const resolved = await this.options.resolveExportPath(entrypoint, "default");
|
|
84625
|
+
if (resolved)
|
|
84626
|
+
componentPath = resolved;
|
|
84627
|
+
}
|
|
84628
|
+
const componentName = deriveComponentNameFromPath(componentPath);
|
|
84629
|
+
if (this.ctx.getComponentKicadMetadata) {
|
|
84630
|
+
const metadata = await this.ctx.getComponentKicadMetadata(componentPath, "default");
|
|
84631
|
+
if (metadata) {
|
|
84632
|
+
this.ctx.footprintMetadataMap.set(componentName, metadata);
|
|
84633
|
+
}
|
|
84634
|
+
}
|
|
84635
|
+
const circuitJson = await this.options.buildFileToCircuitJson(componentPath, "default");
|
|
84636
|
+
if (circuitJson && (!Array.isArray(circuitJson) || circuitJson.length > 0)) {
|
|
84637
|
+
builtTscircuitComponents.push({
|
|
84638
|
+
tscircuitComponentName: componentName,
|
|
84639
|
+
circuitJson
|
|
84640
|
+
});
|
|
84641
|
+
}
|
|
84642
|
+
}
|
|
84430
84643
|
return builtTscircuitComponents;
|
|
84431
84644
|
}
|
|
84432
84645
|
extractKicadComponents() {
|
|
@@ -84464,6 +84677,8 @@ function createKicadLibraryConverterContext(params2) {
|
|
|
84464
84677
|
return {
|
|
84465
84678
|
kicadLibraryName: params2.kicadLibraryName,
|
|
84466
84679
|
includeBuiltins: params2.includeBuiltins,
|
|
84680
|
+
getComponentKicadMetadata: params2.getComponentKicadMetadata,
|
|
84681
|
+
footprintMetadataMap: /* @__PURE__ */ new Map,
|
|
84467
84682
|
builtTscircuitComponents: [],
|
|
84468
84683
|
extractedKicadComponents: [],
|
|
84469
84684
|
userKicadFootprints: [],
|
|
@@ -84474,6 +84689,10 @@ function createKicadLibraryConverterContext(params2) {
|
|
|
84474
84689
|
kicadProjectFsMap: {}
|
|
84475
84690
|
};
|
|
84476
84691
|
}
|
|
84692
|
+
function deriveComponentNameFromPath(filePath) {
|
|
84693
|
+
const filename = filePath.split(/[/\\]/).pop() || filePath;
|
|
84694
|
+
return filename.replace(/\.(tsx?|jsx?)$/, "");
|
|
84695
|
+
}
|
|
84477
84696
|
|
|
84478
84697
|
// lib/shared/convert-to-kicad-library.tsx
|
|
84479
84698
|
import fs27 from "node:fs";
|
|
@@ -84509,6 +84728,75 @@ async function importFromUserLand(moduleName) {
|
|
|
84509
84728
|
return import(moduleName);
|
|
84510
84729
|
}
|
|
84511
84730
|
|
|
84731
|
+
// lib/shared/extract-kicad-footprint-metadata.ts
|
|
84732
|
+
function extractKicadFootprintMetadata(Component, options = {}) {
|
|
84733
|
+
const { maxIterations = 100, debug: debug11 = false } = options;
|
|
84734
|
+
let reactElm;
|
|
84735
|
+
try {
|
|
84736
|
+
reactElm = Component({});
|
|
84737
|
+
} catch (e) {
|
|
84738
|
+
if (debug11) {
|
|
84739
|
+
console.log(`[extractKicadFootprintMetadata] Failed to call root component:`, e);
|
|
84740
|
+
}
|
|
84741
|
+
return {};
|
|
84742
|
+
}
|
|
84743
|
+
if (!reactElm) {
|
|
84744
|
+
return {};
|
|
84745
|
+
}
|
|
84746
|
+
const queue = [reactElm];
|
|
84747
|
+
let iterations = 0;
|
|
84748
|
+
while (queue.length > 0) {
|
|
84749
|
+
iterations++;
|
|
84750
|
+
if (iterations > maxIterations) {
|
|
84751
|
+
if (debug11) {
|
|
84752
|
+
console.log(`[extractKicadFootprintMetadata] Max iterations (${maxIterations}) reached`);
|
|
84753
|
+
}
|
|
84754
|
+
break;
|
|
84755
|
+
}
|
|
84756
|
+
const elm = queue.shift();
|
|
84757
|
+
if (!elm)
|
|
84758
|
+
continue;
|
|
84759
|
+
if (typeof elm.type === "function") {
|
|
84760
|
+
try {
|
|
84761
|
+
let childElm = null;
|
|
84762
|
+
try {
|
|
84763
|
+
childElm = elm.type(elm.props || {});
|
|
84764
|
+
} catch {
|
|
84765
|
+
childElm = elm.type();
|
|
84766
|
+
}
|
|
84767
|
+
if (childElm) {
|
|
84768
|
+
queue.push(childElm);
|
|
84769
|
+
}
|
|
84770
|
+
} catch (e) {
|
|
84771
|
+
if (debug11) {
|
|
84772
|
+
console.log(`[extractKicadFootprintMetadata] Failed to call functional component:`, e);
|
|
84773
|
+
}
|
|
84774
|
+
}
|
|
84775
|
+
}
|
|
84776
|
+
if (elm?.props?.kicadFootprintMetadata) {
|
|
84777
|
+
return elm.props.kicadFootprintMetadata;
|
|
84778
|
+
}
|
|
84779
|
+
if (elm?.props) {
|
|
84780
|
+
const children = elm.props.children;
|
|
84781
|
+
if (Array.isArray(children)) {
|
|
84782
|
+
for (const child of children) {
|
|
84783
|
+
if (child && typeof child === "object") {
|
|
84784
|
+
queue.push(child);
|
|
84785
|
+
}
|
|
84786
|
+
}
|
|
84787
|
+
} else if (children && typeof children === "object") {
|
|
84788
|
+
queue.push(children);
|
|
84789
|
+
}
|
|
84790
|
+
for (const [key, value] of Object.entries(elm.props)) {
|
|
84791
|
+
if (key !== "children" && value && typeof value === "object" && "type" in value && "props" in value) {
|
|
84792
|
+
queue.push(value);
|
|
84793
|
+
}
|
|
84794
|
+
}
|
|
84795
|
+
}
|
|
84796
|
+
}
|
|
84797
|
+
return {};
|
|
84798
|
+
}
|
|
84799
|
+
|
|
84512
84800
|
// lib/shared/convert-to-kicad-library.tsx
|
|
84513
84801
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
84514
84802
|
async function convertToKicadLibrary({
|
|
@@ -84545,6 +84833,18 @@ async function convertToKicadLibrary({
|
|
|
84545
84833
|
const module2 = await import(pathToFileURL(filePath2).href);
|
|
84546
84834
|
return Object.keys(module2);
|
|
84547
84835
|
},
|
|
84836
|
+
getComponentKicadMetadata: async (filePath2, componentName) => {
|
|
84837
|
+
try {
|
|
84838
|
+
const module2 = await import(pathToFileURL(filePath2).href);
|
|
84839
|
+
const Component = module2[componentName];
|
|
84840
|
+
if (!Component || typeof Component !== "function") {
|
|
84841
|
+
return null;
|
|
84842
|
+
}
|
|
84843
|
+
return extractKicadFootprintMetadata(Component);
|
|
84844
|
+
} catch (error) {
|
|
84845
|
+
return null;
|
|
84846
|
+
}
|
|
84847
|
+
},
|
|
84548
84848
|
includeBuiltins: true
|
|
84549
84849
|
});
|
|
84550
84850
|
await converter.run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.796",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/standalone": "^7.26.9",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@tscircuit/fake-snippets": "^0.0.182",
|
|
10
10
|
"@tscircuit/file-server": "^0.0.32",
|
|
11
11
|
"@tscircuit/math-utils": "0.0.29",
|
|
12
|
-
"@tscircuit/props": "^0.0.
|
|
12
|
+
"@tscircuit/props": "^0.0.448",
|
|
13
13
|
"@tscircuit/runframe": "^0.0.1510",
|
|
14
14
|
"@tscircuit/schematic-match-adapt": "^0.0.22",
|
|
15
15
|
"@types/bun": "^1.2.2",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"chokidar": "4.0.1",
|
|
25
25
|
"circuit-json": "0.0.325",
|
|
26
26
|
"circuit-json-to-gltf": "^0.0.58",
|
|
27
|
-
"circuit-json-to-kicad": "^0.0.
|
|
27
|
+
"circuit-json-to-kicad": "^0.0.38",
|
|
28
28
|
"circuit-json-to-readable-netlist": "^0.0.13",
|
|
29
29
|
"circuit-json-to-spice": "^0.0.10",
|
|
30
30
|
"circuit-json-to-tscircuit": "^0.0.9",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"jszip": "^3.10.1",
|
|
45
45
|
"jwt-decode": "^4.0.0",
|
|
46
46
|
"kicad-component-converter": "^0.1.22",
|
|
47
|
-
"kicadts": "^0.0.
|
|
47
|
+
"kicadts": "^0.0.24",
|
|
48
48
|
"kleur": "^4.1.5",
|
|
49
49
|
"ky": "^1.7.4",
|
|
50
50
|
"looks-same": "^9.0.1",
|