@tscircuit/cli 0.1.355 → 0.1.356

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 +97 -34
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -72193,7 +72193,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
72193
72193
  import { execSync as execSync2 } from "node:child_process";
72194
72194
  var import_semver2 = __toESM2(require_semver2(), 1);
72195
72195
  // package.json
72196
- var version = "0.1.354";
72196
+ var version = "0.1.355";
72197
72197
  var package_default = {
72198
72198
  name: "@tscircuit/cli",
72199
72199
  version,
@@ -195694,13 +195694,97 @@ import {
195694
195694
  } from "circuit-to-svg";
195695
195695
  import { renderGLTFToPNGBufferFromGLBBuffer } from "poppygl";
195696
195696
  import { convertCircuitJsonToGltf as convertCircuitJsonToGltf2 } from "circuit-json-to-gltf";
195697
+ var viewToArrayBuffer = (view) => {
195698
+ const copy = new Uint8Array(view.byteLength);
195699
+ copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
195700
+ return copy.buffer;
195701
+ };
195702
+ var normalizeToArrayBuffer = async (value) => {
195703
+ if (value instanceof ArrayBuffer) {
195704
+ return value;
195705
+ }
195706
+ if (ArrayBuffer.isView(value)) {
195707
+ return viewToArrayBuffer(value);
195708
+ }
195709
+ if (value && typeof value === "object") {
195710
+ const maybeArrayBufferLike = value;
195711
+ if (typeof maybeArrayBufferLike.arrayBuffer === "function") {
195712
+ const result = maybeArrayBufferLike.arrayBuffer();
195713
+ return result instanceof Promise ? await result : result;
195714
+ }
195715
+ }
195716
+ throw new Error("Expected ArrayBuffer, ArrayBufferView, or Buffer-compatible object");
195717
+ };
195718
+ var normalizeToUint8Array = (value) => {
195719
+ if (value instanceof Uint8Array) {
195720
+ return value;
195721
+ }
195722
+ if (value instanceof ArrayBuffer) {
195723
+ return new Uint8Array(value);
195724
+ }
195725
+ if (ArrayBuffer.isView(value)) {
195726
+ return new Uint8Array(viewToArrayBuffer(value));
195727
+ }
195728
+ throw new Error("Expected Uint8Array, ArrayBuffer, or ArrayBufferView for PNG");
195729
+ };
195730
+ var generatePreviewAssets = async ({
195731
+ build,
195732
+ outputDir,
195733
+ distDir
195734
+ }) => {
195735
+ const prefixRelative = path29.relative(distDir, outputDir) || ".";
195736
+ const prefix = prefixRelative === "." ? "" : `[${prefixRelative}] `;
195737
+ try {
195738
+ const circuitJsonRaw = fs30.readFileSync(build.outputPath, "utf-8");
195739
+ const circuitJson = JSON.parse(circuitJsonRaw);
195740
+ console.log(`${prefix}Generating PCB SVG...`);
195741
+ const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
195742
+ console.log(`${prefix}Generating schematic SVG...`);
195743
+ const schematicSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
195744
+ console.log(`${prefix}Converting circuit to GLB...`);
195745
+ const glbBuffer = await convertCircuitJsonToGltf2(circuitJson, {
195746
+ format: "glb"
195747
+ });
195748
+ console.log(`${prefix}Rendering GLB to PNG buffer...`);
195749
+ const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
195750
+ const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer, {
195751
+ camPos: [10, 10, 10],
195752
+ lookAt: [0, 0, 0]
195753
+ });
195754
+ fs30.mkdirSync(outputDir, { recursive: true });
195755
+ fs30.writeFileSync(path29.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
195756
+ console.log(`${prefix}Written pcb.svg`);
195757
+ fs30.writeFileSync(path29.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
195758
+ console.log(`${prefix}Written schematic.svg`);
195759
+ fs30.writeFileSync(path29.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
195760
+ console.log(`${prefix}Written 3d.png`);
195761
+ } catch (error) {
195762
+ console.error(`${prefix}Failed to generate preview images:`, error);
195763
+ }
195764
+ };
195697
195765
  var buildPreviewImages = async ({
195698
195766
  builtFiles,
195699
195767
  distDir,
195700
- mainEntrypoint
195768
+ mainEntrypoint,
195769
+ allImages
195701
195770
  }) => {
195702
195771
  const successfulBuilds = builtFiles.filter((file) => file.ok);
195703
195772
  const normalizedMainEntrypoint = mainEntrypoint ? path29.resolve(mainEntrypoint) : undefined;
195773
+ if (allImages) {
195774
+ if (successfulBuilds.length === 0) {
195775
+ console.warn("No successful build output available for preview image generation.");
195776
+ return;
195777
+ }
195778
+ for (const build of successfulBuilds) {
195779
+ const outputDir = path29.dirname(build.outputPath);
195780
+ await generatePreviewAssets({
195781
+ build,
195782
+ outputDir,
195783
+ distDir
195784
+ });
195785
+ }
195786
+ return;
195787
+ }
195704
195788
  const previewBuild = (() => {
195705
195789
  if (normalizedMainEntrypoint) {
195706
195790
  const match = successfulBuilds.find((built) => path29.resolve(built.sourcePath) === normalizedMainEntrypoint);
@@ -195713,39 +195797,16 @@ var buildPreviewImages = async ({
195713
195797
  console.warn("No successful build output available for preview image generation.");
195714
195798
  return;
195715
195799
  }
195716
- try {
195717
- const circuitJsonRaw = fs30.readFileSync(previewBuild.outputPath, "utf-8");
195718
- const circuitJson = JSON.parse(circuitJsonRaw);
195719
- console.log("Generating PCB SVG...");
195720
- const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
195721
- console.log("Generating schematic SVG...");
195722
- const schematicSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
195723
- console.log("Converting circuit to GLB...");
195724
- const glbBuffer = await convertCircuitJsonToGltf2(circuitJson, {
195725
- format: "glb"
195726
- });
195727
- console.log("Rendering GLB to PNG buffer...");
195728
- if (!(glbBuffer instanceof ArrayBuffer)) {
195729
- throw new Error("Expected ArrayBuffer from convertCircuitJsonToGltf with glb format");
195730
- }
195731
- const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbBuffer, {
195732
- camPos: [10, 10, 10],
195733
- lookAt: [0, 0, 0]
195734
- });
195735
- fs30.writeFileSync(path29.join(distDir, "pcb.svg"), pcbSvg, "utf-8");
195736
- console.log("Written pcb.svg");
195737
- fs30.writeFileSync(path29.join(distDir, "schematic.svg"), schematicSvg, "utf-8");
195738
- console.log("Written schematic.svg");
195739
- fs30.writeFileSync(path29.join(distDir, "3d.png"), Buffer.from(pngBuffer));
195740
- console.log("Written 3d.png");
195741
- } catch (error) {
195742
- console.error("Failed to generate preview images:", error);
195743
- }
195800
+ await generatePreviewAssets({
195801
+ build: previewBuild,
195802
+ outputDir: distDir,
195803
+ distDir
195804
+ });
195744
195805
  };
195745
195806
 
195746
195807
  // cli/build/register.ts
195747
195808
  var registerBuild = (program3) => {
195748
- program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--preview-images", "Generate preview images in the dist directory").action(async (file, options) => {
195809
+ program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").action(async (file, options) => {
195749
195810
  const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
195750
195811
  fileOrDir: file
195751
195812
  });
@@ -195797,12 +195858,14 @@ var registerBuild = (program3) => {
195797
195858
  if (hasErrors && !options?.ignoreErrors) {
195798
195859
  process.exit(1);
195799
195860
  }
195800
- if (options?.previewImages) {
195801
- console.log("Generating preview images...");
195861
+ const shouldGeneratePreviewImages = options?.previewImages || options?.allImages;
195862
+ if (shouldGeneratePreviewImages) {
195863
+ console.log(options?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
195802
195864
  await buildPreviewImages({
195803
195865
  builtFiles,
195804
195866
  distDir,
195805
- mainEntrypoint
195867
+ mainEntrypoint,
195868
+ allImages: options?.allImages
195806
195869
  });
195807
195870
  }
195808
195871
  if (options?.site) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.355",
3
+ "version": "0.1.356",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",