@tscircuit/cli 0.1.805 → 0.1.806

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/main.js +82 -24
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -74267,7 +74267,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
74267
74267
  import { execSync as execSync2 } from "node:child_process";
74268
74268
  var import_semver2 = __toESM2(require_semver2(), 1);
74269
74269
  // package.json
74270
- var version = "0.1.804";
74270
+ var version = "0.1.805";
74271
74271
  var package_default = {
74272
74272
  name: "@tscircuit/cli",
74273
74273
  version,
@@ -74294,7 +74294,7 @@ var package_default = {
74294
74294
  chokidar: "4.0.1",
74295
74295
  "circuit-json": "0.0.325",
74296
74296
  "circuit-json-to-gltf": "^0.0.58",
74297
- "circuit-json-to-kicad": "^0.0.38",
74297
+ "circuit-json-to-kicad": "^0.0.40",
74298
74298
  "circuit-json-to-readable-netlist": "^0.0.13",
74299
74299
  "circuit-json-to-spice": "^0.0.10",
74300
74300
  "circuit-json-to-tscircuit": "^0.0.9",
@@ -81825,6 +81825,7 @@ import {
81825
81825
  TextEffects as TextEffects7,
81826
81826
  TextEffectsFont as TextEffectsFont7
81827
81827
  } from "kicadts";
81828
+ import { parseKicadMod as parseKicadMod2 } from "kicadts";
81828
81829
  import { KicadSymbolLib as KicadSymbolLib2 } from "kicadts";
81829
81830
  var ConverterStage = class {
81830
81831
  MAX_ITERATIONS = 1000;
@@ -84295,8 +84296,15 @@ var CircuitJsonToKicadLibraryConverter = class {
84295
84296
  return this.getOutput().model3dSourcePaths;
84296
84297
  }
84297
84298
  };
84299
+ var KICAD_3RD_PARTY_PLACEHOLDER = "${KICAD_3RD_PARTY}";
84298
84300
  function renameKicadFootprint(params2) {
84299
- const { kicadFootprint, newKicadFootprintName, kicadLibraryName } = params2;
84301
+ const {
84302
+ kicadFootprint,
84303
+ newKicadFootprintName,
84304
+ kicadLibraryName,
84305
+ isPcm,
84306
+ kicadPcmPackageId
84307
+ } = params2;
84300
84308
  const footprint = parseKicadMod(kicadFootprint.kicadModString);
84301
84309
  footprint.libraryLink = newKicadFootprintName;
84302
84310
  for (const model of footprint.models) {
@@ -84304,7 +84312,11 @@ function renameKicadFootprint(params2) {
84304
84312
  const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
84305
84313
  if (usesProjectPath) {
84306
84314
  const filename = currentPath.split(/[\\/]/).pop() ?? "";
84307
- model.path = `../../3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
84315
+ if (isPcm && kicadPcmPackageId) {
84316
+ model.path = `${KICAD_3RD_PARTY_PLACEHOLDER}/3dmodels/${kicadPcmPackageId}/${kicadLibraryName}.3dshapes/${filename}`;
84317
+ } else {
84318
+ model.path = `../../3dmodels/${kicadLibraryName}.3dshapes/${filename}`;
84319
+ }
84308
84320
  }
84309
84321
  }
84310
84322
  return {
@@ -84413,6 +84425,7 @@ function applyKicadFootprintMetadata(kicadModString, metadata, footprintName) {
84413
84425
  return kicadModString;
84414
84426
  }
84415
84427
  }
84428
+ var KICAD_3RD_PARTY_PLACEHOLDER2 = "${KICAD_3RD_PARTY}";
84416
84429
  function classifyKicadFootprints(ctx) {
84417
84430
  for (const extractedKicadComponent of ctx.extractedKicadComponents) {
84418
84431
  classifyFootprintsForComponent({
@@ -84437,7 +84450,9 @@ function classifyFootprintsForComponent({
84437
84450
  let renamedFootprint = renameKicadFootprint({
84438
84451
  kicadFootprint,
84439
84452
  newKicadFootprintName: tscircuitComponentName,
84440
- kicadLibraryName: ctx.kicadLibraryName
84453
+ kicadLibraryName: ctx.kicadLibraryName,
84454
+ isPcm: ctx.isPcm,
84455
+ kicadPcmPackageId: ctx.kicadPcmPackageId
84441
84456
  });
84442
84457
  if (metadata) {
84443
84458
  renamedFootprint = {
@@ -84467,8 +84482,36 @@ function addBuiltinFootprint({
84467
84482
  }) {
84468
84483
  const alreadyExists = ctx.builtinKicadFootprints.some((fp) => fp.footprintName === kicadFootprint.footprintName);
84469
84484
  if (!alreadyExists) {
84470
- ctx.builtinKicadFootprints.push(kicadFootprint);
84485
+ if (ctx.isPcm && ctx.kicadPcmPackageId) {
84486
+ const updatedFootprint = updateBuiltinFootprintModelPaths({
84487
+ kicadFootprint,
84488
+ kicadPcmPackageId: ctx.kicadPcmPackageId
84489
+ });
84490
+ ctx.builtinKicadFootprints.push(updatedFootprint);
84491
+ } else {
84492
+ ctx.builtinKicadFootprints.push(kicadFootprint);
84493
+ }
84494
+ }
84495
+ }
84496
+ function updateBuiltinFootprintModelPaths({
84497
+ kicadFootprint,
84498
+ kicadPcmPackageId
84499
+ }) {
84500
+ const footprint = parseKicadMod2(kicadFootprint.kicadModString);
84501
+ for (const model of footprint.models) {
84502
+ const currentPath = model.path;
84503
+ const usesProjectPath = currentPath.includes("${KIPRJMOD}/") || /3dmodels[\\/]/.test(currentPath);
84504
+ if (usesProjectPath) {
84505
+ const filename = currentPath.split(/[\\/]/).pop() ?? "";
84506
+ model.path = `${KICAD_3RD_PARTY_PLACEHOLDER2}/3dmodels/${kicadPcmPackageId}/tscircuit_builtin.3dshapes/${filename}`;
84507
+ }
84471
84508
  }
84509
+ return {
84510
+ footprintName: kicadFootprint.footprintName,
84511
+ kicadModString: footprint.getString(),
84512
+ model3dSourcePaths: kicadFootprint.model3dSourcePaths,
84513
+ isBuiltin: kicadFootprint.isBuiltin
84514
+ };
84472
84515
  }
84473
84516
  function componentHasCustomFootprint(extractedKicadComponent) {
84474
84517
  return extractedKicadComponent.kicadFootprints.some((fp) => !fp.isBuiltin);
@@ -84489,22 +84532,24 @@ function renameKicadSymbol(params2) {
84489
84532
  return { symbolName: newKicadSymbolName, symbol };
84490
84533
  }
84491
84534
  function updateKicadSymbolFootprint(params2) {
84492
- const { kicadSymbol, kicadLibraryName, kicadFootprintName } = params2;
84535
+ const { kicadSymbol, kicadLibraryName, kicadFootprintName, isPcm } = params2;
84493
84536
  const properties = kicadSymbol.symbol.properties ?? [];
84537
+ const effectiveKicadLibraryName = isPcm ? `PCM_${kicadLibraryName}` : kicadLibraryName;
84494
84538
  for (const prop of properties) {
84495
84539
  if (prop.key === "Footprint") {
84496
- prop.value = `${kicadLibraryName}:${kicadFootprintName}`;
84540
+ prop.value = `${effectiveKicadLibraryName}:${kicadFootprintName}`;
84497
84541
  }
84498
84542
  }
84499
84543
  }
84500
- function updateBuiltinKicadSymbolFootprint(kicadSymbol) {
84544
+ function updateBuiltinKicadSymbolFootprint(kicadSymbol, options) {
84501
84545
  const symbol = kicadSymbol.symbol;
84502
84546
  const properties = symbol.properties ?? [];
84547
+ const libraryName = options?.isPcm ? "PCM_tscircuit_builtin" : "tscircuit_builtin";
84503
84548
  for (const prop of properties) {
84504
84549
  if (prop.key === "Footprint" && prop.value) {
84505
84550
  const parts = prop.value.split(":");
84506
84551
  const footprintName = parts.length > 1 ? parts[1] : parts[0];
84507
- prop.value = `tscircuit_builtin:${footprintName}`;
84552
+ prop.value = `${libraryName}:${footprintName}`;
84508
84553
  }
84509
84554
  }
84510
84555
  return { symbolName: kicadSymbol.symbolName, symbol };
@@ -84536,7 +84581,8 @@ function classifySymbolsForComponent({
84536
84581
  updateKicadSymbolFootprint({
84537
84582
  kicadSymbol: renamedSymbol,
84538
84583
  kicadLibraryName: ctx.kicadLibraryName,
84539
- kicadFootprintName: tscircuitComponentName
84584
+ kicadFootprintName: tscircuitComponentName,
84585
+ isPcm: ctx.isPcm
84540
84586
  });
84541
84587
  }
84542
84588
  addUserSymbol({ ctx, kicadSymbol: renamedSymbol });
@@ -84552,11 +84598,14 @@ function classifySymbolsForComponent({
84552
84598
  updateKicadSymbolFootprint({
84553
84599
  kicadSymbol: renamedSymbol,
84554
84600
  kicadLibraryName: ctx.kicadLibraryName,
84555
- kicadFootprintName: tscircuitComponentName
84601
+ kicadFootprintName: tscircuitComponentName,
84602
+ isPcm: ctx.isPcm
84556
84603
  });
84557
84604
  addUserSymbol({ ctx, kicadSymbol: renamedSymbol });
84558
84605
  } else {
84559
- const updatedSymbol = updateBuiltinKicadSymbolFootprint(kicadSymbol);
84606
+ const updatedSymbol = updateBuiltinKicadSymbolFootprint(kicadSymbol, {
84607
+ isPcm: ctx.isPcm
84608
+ });
84560
84609
  addBuiltinSymbol({ ctx, kicadSymbol: updatedSymbol });
84561
84610
  }
84562
84611
  }
@@ -84671,7 +84720,9 @@ var KicadLibraryConverter = class {
84671
84720
  this.ctx = createKicadLibraryConverterContext({
84672
84721
  kicadLibraryName: options.kicadLibraryName ?? "tscircuit_library",
84673
84722
  includeBuiltins: options.includeBuiltins ?? true,
84674
- getComponentKicadMetadata: options.getComponentKicadMetadata
84723
+ getComponentKicadMetadata: options.getComponentKicadMetadata,
84724
+ isPcm: options.isPcm ?? false,
84725
+ kicadPcmPackageId: options.kicadPcmPackageId
84675
84726
  });
84676
84727
  }
84677
84728
  async run() {
@@ -84771,6 +84822,8 @@ function createKicadLibraryConverterContext(params2) {
84771
84822
  kicadLibraryName: params2.kicadLibraryName,
84772
84823
  includeBuiltins: params2.includeBuiltins,
84773
84824
  getComponentKicadMetadata: params2.getComponentKicadMetadata,
84825
+ isPcm: params2.isPcm,
84826
+ kicadPcmPackageId: params2.kicadPcmPackageId,
84774
84827
  footprintMetadataMap: /* @__PURE__ */ new Map,
84775
84828
  builtTscircuitComponents: [],
84776
84829
  extractedKicadComponents: [],
@@ -84895,7 +84948,9 @@ import { jsxDEV } from "react/jsx-dev-runtime";
84895
84948
  async function convertToKicadLibrary({
84896
84949
  filePath,
84897
84950
  libraryName,
84898
- outputDir
84951
+ outputDir,
84952
+ isPcm,
84953
+ kicadPcmPackageId
84899
84954
  }) {
84900
84955
  const absoluteFilePath = path30.isAbsolute(filePath) ? filePath : path30.resolve(process.cwd(), filePath);
84901
84956
  const React = await importFromUserLand("react");
@@ -84938,7 +84993,9 @@ async function convertToKicadLibrary({
84938
84993
  return null;
84939
84994
  }
84940
84995
  },
84941
- includeBuiltins: true
84996
+ includeBuiltins: true,
84997
+ isPcm,
84998
+ kicadPcmPackageId
84942
84999
  });
84943
85000
  await converter.run();
84944
85001
  const kicadLibOutput = converter.getOutput();
@@ -173757,14 +173814,15 @@ async function buildKicadPcm({
173757
173814
  const description = packageJson.description || "";
173758
173815
  const libraryName = resolveKicadLibraryName({ projectDir });
173759
173816
  const kicadLibOutputDir = path45.join(distDir, "kicad-library");
173760
- if (!fs45.existsSync(kicadLibOutputDir)) {
173761
- console.log("Converting to KiCad library...");
173762
- await convertToKicadLibrary({
173763
- filePath: entryFile,
173764
- libraryName,
173765
- outputDir: kicadLibOutputDir
173766
- });
173767
- }
173817
+ const kicadPcmPackageId = `com_tscircuit_${author}_${packageName}`.replace(/\./g, "_");
173818
+ console.log("Converting to KiCad library for PCM...");
173819
+ await convertToKicadLibrary({
173820
+ filePath: entryFile,
173821
+ libraryName,
173822
+ outputDir: kicadLibOutputDir,
173823
+ isPcm: true,
173824
+ kicadPcmPackageId
173825
+ });
173768
173826
  const pcmOutputDir = path45.join(distDir, "pcm");
173769
173827
  const envDeploymentUrl = process.env.TSCIRCUIT_DEPLOYMENT_URL?.replace(/\/+$/, "");
173770
173828
  const baseUrl = envDeploymentUrl ?? `https://${author}--${packageName}.tscircuit.app`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.805",
3
+ "version": "0.1.806",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",
@@ -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.38",
27
+ "circuit-json-to-kicad": "^0.0.40",
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",