circuit-json-to-kicad 0.0.38 → 0.0.40
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.ts +15 -0
- package/dist/index.js +65 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -255,6 +255,21 @@ interface KicadLibraryConverterOptions {
|
|
|
255
255
|
* Return null if no metadata is available.
|
|
256
256
|
*/
|
|
257
257
|
getComponentKicadMetadata?: (filePath: string, componentName: string) => Promise<KicadFootprintMetadata | null>;
|
|
258
|
+
/**
|
|
259
|
+
* Whether to generate files for KiCad PCM (Plugin and Content Manager).
|
|
260
|
+
* When true:
|
|
261
|
+
* - Footprint references in symbols will be prefixed with "PCM_"
|
|
262
|
+
* - 3D model paths will use ${KICAD_3RD_PARTY} variable instead of relative paths
|
|
263
|
+
* Default: false
|
|
264
|
+
*/
|
|
265
|
+
isPcm?: boolean;
|
|
266
|
+
/**
|
|
267
|
+
* The KiCad PCM package identifier (e.g., "com_tscircuit_author_package-name").
|
|
268
|
+
* Required when useKicadPcmPaths is true.
|
|
269
|
+
* Used to construct 3D model paths like:
|
|
270
|
+
* ${KICAD9_3RD_PARTY}/3dmodels/<kicadPcmPackageId>/<library>.3dshapes/<model>.step
|
|
271
|
+
*/
|
|
272
|
+
kicadPcmPackageId?: string;
|
|
258
273
|
}
|
|
259
274
|
interface KicadLibraryConverterOutput {
|
|
260
275
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2937,8 +2937,15 @@ var CircuitJsonToKicadLibraryConverter = class {
|
|
|
2937
2937
|
|
|
2938
2938
|
// lib/kicad-library/kicad-library-converter-utils/renameKicadFootprint.ts
|
|
2939
2939
|
import { parseKicadMod } from "kicadts";
|
|
2940
|
+
var KICAD_3RD_PARTY_PLACEHOLDER = "${KICAD_3RD_PARTY}";
|
|
2940
2941
|
function renameKicadFootprint(params) {
|
|
2941
|
-
const {
|
|
2942
|
+
const {
|
|
2943
|
+
kicadFootprint,
|
|
2944
|
+
newKicadFootprintName,
|
|
2945
|
+
kicadLibraryName,
|
|
2946
|
+
isPcm,
|
|
2947
|
+
kicadPcmPackageId
|
|
2948
|
+
} = params;
|
|
2942
2949
|
const footprint = parseKicadMod(kicadFootprint.kicadModString);
|
|
2943
2950
|
footprint.libraryLink = newKicadFootprintName;
|
|
2944
2951
|
for (const model of footprint.models) {
|
|
@@ -2946,7 +2953,11 @@ function renameKicadFootprint(params) {
|
|
|
2946
2953
|
const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
|
|
2947
2954
|
if (usesProjectPath) {
|
|
2948
2955
|
const filename = currentPath.split(/[\\/]/).pop() ?? "";
|
|
2949
|
-
|
|
2956
|
+
if (isPcm && kicadPcmPackageId) {
|
|
2957
|
+
model.path = `${KICAD_3RD_PARTY_PLACEHOLDER}/3dmodels/${kicadPcmPackageId}/${kicadLibraryName}.3dshapes/${filename}`;
|
|
2958
|
+
} else {
|
|
2959
|
+
model.path = `../../3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
|
|
2960
|
+
}
|
|
2950
2961
|
}
|
|
2951
2962
|
}
|
|
2952
2963
|
return {
|
|
@@ -3077,6 +3088,8 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
|
|
|
3077
3088
|
}
|
|
3078
3089
|
|
|
3079
3090
|
// lib/kicad-library/stages/ClassifyKicadFootprintsStage.ts
|
|
3091
|
+
import { parseKicadMod as parseKicadMod2 } from "kicadts";
|
|
3092
|
+
var KICAD_3RD_PARTY_PLACEHOLDER2 = "${KICAD_3RD_PARTY}";
|
|
3080
3093
|
function classifyKicadFootprints(ctx) {
|
|
3081
3094
|
for (const extractedKicadComponent of ctx.extractedKicadComponents) {
|
|
3082
3095
|
classifyFootprintsForComponent({
|
|
@@ -3101,7 +3114,9 @@ function classifyFootprintsForComponent({
|
|
|
3101
3114
|
let renamedFootprint = renameKicadFootprint({
|
|
3102
3115
|
kicadFootprint,
|
|
3103
3116
|
newKicadFootprintName: tscircuitComponentName,
|
|
3104
|
-
kicadLibraryName: ctx.kicadLibraryName
|
|
3117
|
+
kicadLibraryName: ctx.kicadLibraryName,
|
|
3118
|
+
isPcm: ctx.isPcm,
|
|
3119
|
+
kicadPcmPackageId: ctx.kicadPcmPackageId
|
|
3105
3120
|
});
|
|
3106
3121
|
if (metadata) {
|
|
3107
3122
|
renamedFootprint = {
|
|
@@ -3139,8 +3154,36 @@ function addBuiltinFootprint({
|
|
|
3139
3154
|
(fp) => fp.footprintName === kicadFootprint.footprintName
|
|
3140
3155
|
);
|
|
3141
3156
|
if (!alreadyExists) {
|
|
3142
|
-
ctx.
|
|
3157
|
+
if (ctx.isPcm && ctx.kicadPcmPackageId) {
|
|
3158
|
+
const updatedFootprint = updateBuiltinFootprintModelPaths({
|
|
3159
|
+
kicadFootprint,
|
|
3160
|
+
kicadPcmPackageId: ctx.kicadPcmPackageId
|
|
3161
|
+
});
|
|
3162
|
+
ctx.builtinKicadFootprints.push(updatedFootprint);
|
|
3163
|
+
} else {
|
|
3164
|
+
ctx.builtinKicadFootprints.push(kicadFootprint);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
function updateBuiltinFootprintModelPaths({
|
|
3169
|
+
kicadFootprint,
|
|
3170
|
+
kicadPcmPackageId
|
|
3171
|
+
}) {
|
|
3172
|
+
const footprint = parseKicadMod2(kicadFootprint.kicadModString);
|
|
3173
|
+
for (const model of footprint.models) {
|
|
3174
|
+
const currentPath = model.path;
|
|
3175
|
+
const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
|
|
3176
|
+
if (usesProjectPath) {
|
|
3177
|
+
const filename = currentPath.split(/[\\/]/).pop() ?? "";
|
|
3178
|
+
model.path = `${KICAD_3RD_PARTY_PLACEHOLDER2}/3dmodels/${kicadPcmPackageId}/tscircuit_builtin.3dshapes/${filename}`;
|
|
3179
|
+
}
|
|
3143
3180
|
}
|
|
3181
|
+
return {
|
|
3182
|
+
footprintName: kicadFootprint.footprintName,
|
|
3183
|
+
kicadModString: footprint.getString(),
|
|
3184
|
+
model3dSourcePaths: kicadFootprint.model3dSourcePaths,
|
|
3185
|
+
isBuiltin: kicadFootprint.isBuiltin
|
|
3186
|
+
};
|
|
3144
3187
|
}
|
|
3145
3188
|
function componentHasCustomFootprint(extractedKicadComponent) {
|
|
3146
3189
|
return extractedKicadComponent.kicadFootprints.some((fp) => !fp.isBuiltin);
|
|
@@ -3165,24 +3208,26 @@ function renameKicadSymbol(params) {
|
|
|
3165
3208
|
|
|
3166
3209
|
// lib/kicad-library/kicad-library-converter-utils/updateKicadSymbolFootprint.ts
|
|
3167
3210
|
function updateKicadSymbolFootprint(params) {
|
|
3168
|
-
const { kicadSymbol, kicadLibraryName, kicadFootprintName } = params;
|
|
3211
|
+
const { kicadSymbol, kicadLibraryName, kicadFootprintName, isPcm } = params;
|
|
3169
3212
|
const properties = kicadSymbol.symbol.properties ?? [];
|
|
3213
|
+
const effectiveKicadLibraryName = isPcm ? `PCM_${kicadLibraryName}` : kicadLibraryName;
|
|
3170
3214
|
for (const prop of properties) {
|
|
3171
3215
|
if (prop.key === "Footprint") {
|
|
3172
|
-
prop.value = `${
|
|
3216
|
+
prop.value = `${effectiveKicadLibraryName}:${kicadFootprintName}`;
|
|
3173
3217
|
}
|
|
3174
3218
|
}
|
|
3175
3219
|
}
|
|
3176
3220
|
|
|
3177
3221
|
// lib/kicad-library/kicad-library-converter-utils/updateBuiltinKicadSymbolFootprint.ts
|
|
3178
|
-
function updateBuiltinKicadSymbolFootprint(kicadSymbol) {
|
|
3222
|
+
function updateBuiltinKicadSymbolFootprint(kicadSymbol, options) {
|
|
3179
3223
|
const symbol = kicadSymbol.symbol;
|
|
3180
3224
|
const properties = symbol.properties ?? [];
|
|
3225
|
+
const libraryName = options?.isPcm ? "PCM_tscircuit_builtin" : "tscircuit_builtin";
|
|
3181
3226
|
for (const prop of properties) {
|
|
3182
3227
|
if (prop.key === "Footprint" && prop.value) {
|
|
3183
3228
|
const parts = prop.value.split(":");
|
|
3184
3229
|
const footprintName = parts.length > 1 ? parts[1] : parts[0];
|
|
3185
|
-
prop.value =
|
|
3230
|
+
prop.value = `${libraryName}:${footprintName}`;
|
|
3186
3231
|
}
|
|
3187
3232
|
}
|
|
3188
3233
|
return { symbolName: kicadSymbol.symbolName, symbol };
|
|
@@ -3218,7 +3263,8 @@ function classifySymbolsForComponent({
|
|
|
3218
3263
|
updateKicadSymbolFootprint({
|
|
3219
3264
|
kicadSymbol: renamedSymbol,
|
|
3220
3265
|
kicadLibraryName: ctx.kicadLibraryName,
|
|
3221
|
-
kicadFootprintName: tscircuitComponentName
|
|
3266
|
+
kicadFootprintName: tscircuitComponentName,
|
|
3267
|
+
isPcm: ctx.isPcm
|
|
3222
3268
|
});
|
|
3223
3269
|
}
|
|
3224
3270
|
addUserSymbol({ ctx, kicadSymbol: renamedSymbol });
|
|
@@ -3234,11 +3280,14 @@ function classifySymbolsForComponent({
|
|
|
3234
3280
|
updateKicadSymbolFootprint({
|
|
3235
3281
|
kicadSymbol: renamedSymbol,
|
|
3236
3282
|
kicadLibraryName: ctx.kicadLibraryName,
|
|
3237
|
-
kicadFootprintName: tscircuitComponentName
|
|
3283
|
+
kicadFootprintName: tscircuitComponentName,
|
|
3284
|
+
isPcm: ctx.isPcm
|
|
3238
3285
|
});
|
|
3239
3286
|
addUserSymbol({ ctx, kicadSymbol: renamedSymbol });
|
|
3240
3287
|
} else {
|
|
3241
|
-
const updatedSymbol = updateBuiltinKicadSymbolFootprint(kicadSymbol
|
|
3288
|
+
const updatedSymbol = updateBuiltinKicadSymbolFootprint(kicadSymbol, {
|
|
3289
|
+
isPcm: ctx.isPcm
|
|
3290
|
+
});
|
|
3242
3291
|
addBuiltinSymbol({ ctx, kicadSymbol: updatedSymbol });
|
|
3243
3292
|
}
|
|
3244
3293
|
}
|
|
@@ -3361,7 +3410,9 @@ var KicadLibraryConverter = class {
|
|
|
3361
3410
|
this.ctx = createKicadLibraryConverterContext({
|
|
3362
3411
|
kicadLibraryName: options.kicadLibraryName ?? "tscircuit_library",
|
|
3363
3412
|
includeBuiltins: options.includeBuiltins ?? true,
|
|
3364
|
-
getComponentKicadMetadata: options.getComponentKicadMetadata
|
|
3413
|
+
getComponentKicadMetadata: options.getComponentKicadMetadata,
|
|
3414
|
+
isPcm: options.isPcm ?? false,
|
|
3415
|
+
kicadPcmPackageId: options.kicadPcmPackageId
|
|
3365
3416
|
});
|
|
3366
3417
|
}
|
|
3367
3418
|
async run() {
|
|
@@ -3487,6 +3538,8 @@ function createKicadLibraryConverterContext(params) {
|
|
|
3487
3538
|
kicadLibraryName: params.kicadLibraryName,
|
|
3488
3539
|
includeBuiltins: params.includeBuiltins,
|
|
3489
3540
|
getComponentKicadMetadata: params.getComponentKicadMetadata,
|
|
3541
|
+
isPcm: params.isPcm,
|
|
3542
|
+
kicadPcmPackageId: params.kicadPcmPackageId,
|
|
3490
3543
|
footprintMetadataMap: /* @__PURE__ */ new Map(),
|
|
3491
3544
|
builtTscircuitComponents: [],
|
|
3492
3545
|
extractedKicadComponents: [],
|