circuit-json-to-kicad 0.0.33 → 0.0.35

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.
Files changed (2) hide show
  1. package/dist/index.js +34 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2691,7 +2691,7 @@ var ExtractFootprintsStage = class extends ConverterStage {
2691
2691
  for (const model of models) {
2692
2692
  if (model.path) {
2693
2693
  const modelFilename = getBasename(model.path);
2694
- const newPath = `\${KIPRJMOD}/${fpLibraryName}.3dshapes/${modelFilename}`;
2694
+ const newPath = `../../3dmodels/${fpLibraryName}.3dshapes/${modelFilename}`;
2695
2695
  const newModel = new FootprintModel2(newPath);
2696
2696
  if (model.offset) newModel.offset = model.offset;
2697
2697
  if (model.scale) newModel.scale = model.scale;
@@ -2870,9 +2870,10 @@ function renameKicadFootprint(params) {
2870
2870
  footprint.libraryLink = newKicadFootprintName;
2871
2871
  for (const model of footprint.models) {
2872
2872
  const currentPath = model.path;
2873
- if (currentPath.includes("${KIPRJMOD}/")) {
2874
- const filename = currentPath.split("/").pop() ?? "";
2875
- model.path = `\${KIPRJMOD}/3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
2873
+ const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
2874
+ if (usesProjectPath) {
2875
+ const filename = currentPath.split(/[\\/]/).pop() ?? "";
2876
+ model.path = `../../3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
2876
2877
  }
2877
2878
  }
2878
2879
  return {
@@ -3176,8 +3177,10 @@ var KicadLibraryConverter = class {
3176
3177
  const builtTscircuitComponents = [];
3177
3178
  const { entrypoint } = this.options;
3178
3179
  const exports = await this.options.getExportsFromTsxFile(entrypoint);
3179
- const componentExports = exports.filter((name) => /^[A-Z]/.test(name));
3180
- for (const exportName of componentExports) {
3180
+ const namedExports = exports.filter(
3181
+ (name) => name !== "default" && /^[A-Z]/.test(name)
3182
+ );
3183
+ for (const exportName of namedExports) {
3181
3184
  let componentPath = entrypoint;
3182
3185
  if (this.options.resolveExportPath) {
3183
3186
  const resolved = await this.options.resolveExportPath(
@@ -3197,6 +3200,27 @@ var KicadLibraryConverter = class {
3197
3200
  });
3198
3201
  }
3199
3202
  }
3203
+ if (exports.includes("default")) {
3204
+ let componentPath = entrypoint;
3205
+ if (this.options.resolveExportPath) {
3206
+ const resolved = await this.options.resolveExportPath(
3207
+ entrypoint,
3208
+ "default"
3209
+ );
3210
+ if (resolved) componentPath = resolved;
3211
+ }
3212
+ const componentName = deriveComponentNameFromPath(componentPath);
3213
+ const circuitJson = await this.options.buildFileToCircuitJson(
3214
+ componentPath,
3215
+ "default"
3216
+ );
3217
+ if (circuitJson && (!Array.isArray(circuitJson) || circuitJson.length > 0)) {
3218
+ builtTscircuitComponents.push({
3219
+ tscircuitComponentName: componentName,
3220
+ circuitJson
3221
+ });
3222
+ }
3223
+ }
3200
3224
  return builtTscircuitComponents;
3201
3225
  }
3202
3226
  /**
@@ -3249,6 +3273,10 @@ function createKicadLibraryConverterContext(params) {
3249
3273
  kicadProjectFsMap: {}
3250
3274
  };
3251
3275
  }
3276
+ function deriveComponentNameFromPath(filePath) {
3277
+ const filename = filePath.split(/[/\\]/).pop() || filePath;
3278
+ return filename.replace(/\.(tsx?|jsx?)$/, "");
3279
+ }
3252
3280
  export {
3253
3281
  CircuitJsonToKicadLibraryConverter,
3254
3282
  CircuitJsonToKicadPcbConverter,
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.33",
4
+ "version": "0.0.35",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"