@tscircuit/cli 0.1.1065 → 0.1.1066

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.
@@ -13348,20 +13348,87 @@ var writeGlbFromCircuitJson = async (circuitJson, glbOutputPath) => {
13348
13348
  fs9.mkdirSync(path12.dirname(glbOutputPath), { recursive: true });
13349
13349
  fs9.writeFileSync(glbOutputPath, Buffer.from(glbData));
13350
13350
  };
13351
- var writePreviewAssetsFromCircuitJson = async (circuitJson, outputDir) => {
13351
+ var writeImageAssetsFromCircuitJson = async (circuitJson, options) => {
13352
+ const { outputDir, imageFormats } = options;
13352
13353
  fs9.mkdirSync(outputDir, { recursive: true });
13353
- const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
13354
- fs9.writeFileSync(path12.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
13355
- const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson);
13356
- fs9.writeFileSync(path12.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
13357
- const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
13358
- const glbBuffer = await convertCircuitJsonToGltf(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
13359
- const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
13360
- const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer, {
13361
- camPos: [10, 10, 10],
13362
- lookAt: [0, 0, 0]
13363
- });
13364
- fs9.writeFileSync(path12.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
13354
+ if (imageFormats.pcbSvgs) {
13355
+ const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
13356
+ fs9.writeFileSync(path12.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
13357
+ }
13358
+ if (imageFormats.schematicSvgs) {
13359
+ const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson);
13360
+ fs9.writeFileSync(path12.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
13361
+ }
13362
+ if (imageFormats.threeDPngs) {
13363
+ const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
13364
+ const glbBuffer = await convertCircuitJsonToGltf(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
13365
+ const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
13366
+ const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer);
13367
+ fs9.writeFileSync(path12.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
13368
+ }
13369
+ };
13370
+
13371
+ // cli/build/image-format-selection.ts
13372
+ var DEFAULT_IMAGE_FORMAT_SELECTION = {
13373
+ threeDPngs: true,
13374
+ pcbSvgs: true,
13375
+ schematicSvgs: true
13376
+ };
13377
+ var EMPTY_IMAGE_FORMAT_SELECTION = {
13378
+ threeDPngs: false,
13379
+ pcbSvgs: false,
13380
+ schematicSvgs: false
13381
+ };
13382
+ var hasAnyImageFormatSelected = (selection) => selection.threeDPngs || selection.pcbSvgs || selection.schematicSvgs;
13383
+ var hasNewOutputFlags = (options) => Boolean(options?.pngs || options?.svgs || options?.pcbSvgs || options?.schematicSvgs);
13384
+ var hasEstablishedOutputFlags = (options) => Boolean(options?.["3d"] || options?.pcbOnly || options?.schematicOnly);
13385
+ var resolveImageFormatSelection = (options) => {
13386
+ const hasNewFlags = hasNewOutputFlags(options);
13387
+ const hasEstablishedFlags = hasEstablishedOutputFlags(options);
13388
+ const hasExplicitSelection = hasNewFlags || hasEstablishedFlags;
13389
+ if (!hasExplicitSelection) {
13390
+ return {
13391
+ selection: { ...DEFAULT_IMAGE_FORMAT_SELECTION },
13392
+ hasExplicitSelection: false
13393
+ };
13394
+ }
13395
+ if (!hasNewFlags && hasEstablishedFlags) {
13396
+ const selection2 = {
13397
+ threeDPngs: Boolean(options?.["3d"]),
13398
+ pcbSvgs: true,
13399
+ schematicSvgs: true
13400
+ };
13401
+ if (options?.pcbOnly && !options?.schematicOnly) {
13402
+ selection2.schematicSvgs = false;
13403
+ }
13404
+ if (options?.schematicOnly && !options?.pcbOnly) {
13405
+ selection2.pcbSvgs = false;
13406
+ }
13407
+ return { selection: selection2, hasExplicitSelection: true };
13408
+ }
13409
+ const selection = {
13410
+ ...EMPTY_IMAGE_FORMAT_SELECTION
13411
+ };
13412
+ if (options?.svgs) {
13413
+ selection.pcbSvgs = true;
13414
+ selection.schematicSvgs = true;
13415
+ }
13416
+ if (options?.pcbSvgs) {
13417
+ selection.pcbSvgs = true;
13418
+ }
13419
+ if (options?.schematicSvgs) {
13420
+ selection.schematicSvgs = true;
13421
+ }
13422
+ if (options?.pngs || options?.["3d"]) {
13423
+ selection.threeDPngs = true;
13424
+ }
13425
+ if (options?.pcbOnly && !options?.schematicOnly) {
13426
+ selection.schematicSvgs = false;
13427
+ }
13428
+ if (options?.schematicOnly && !options?.pcbOnly) {
13429
+ selection.pcbSvgs = false;
13430
+ }
13431
+ return { selection, hasExplicitSelection: true };
13365
13432
  };
13366
13433
 
13367
13434
  // cli/build/worker-build-handlers.ts
@@ -13423,7 +13490,10 @@ var handleBuildFile = async (filePath, outputPath, glbOutputPath, previewOutputD
13423
13490
  try {
13424
13491
  const resolvedPreviewOutputDir = previewOutputDir ?? path13.dirname(outputPath);
13425
13492
  workerLog(`Generating preview assets for ${path13.relative(projectDir, resolvedPreviewOutputDir)} in same worker...`);
13426
- await writePreviewAssetsFromCircuitJson(circuitJson, resolvedPreviewOutputDir);
13493
+ await writeImageAssetsFromCircuitJson(circuitJson, {
13494
+ outputDir: resolvedPreviewOutputDir,
13495
+ imageFormats: options?.imageFormats ?? DEFAULT_IMAGE_FORMAT_SELECTION
13496
+ });
13427
13497
  previewOk = true;
13428
13498
  } catch (err) {
13429
13499
  previewOk = false;
package/dist/cli/main.js CHANGED
@@ -71664,7 +71664,7 @@ var registerStaticAssetLoaders = () => {
71664
71664
  // cli/main.ts
71665
71665
  var import_perfect_cli = __toESM2(require_dist2(), 1);
71666
71666
  // package.json
71667
- var version = "0.1.1064";
71667
+ var version = "0.1.1065";
71668
71668
  var package_default = {
71669
71669
  name: "@tscircuit/cli",
71670
71670
  version,
@@ -81150,7 +81150,8 @@ var normalizeToUint8Array2 = (value) => {
81150
81150
  var generatePreviewAssets = async ({
81151
81151
  build,
81152
81152
  outputDir,
81153
- distDir
81153
+ distDir,
81154
+ imageFormats
81154
81155
  }) => {
81155
81156
  const prefixRelative = path32.relative(distDir, outputDir) || ".";
81156
81157
  const prefix = prefixRelative === "." ? "" : `[${prefixRelative}] `;
@@ -81163,36 +81164,39 @@ var generatePreviewAssets = async ({
81163
81164
  return;
81164
81165
  }
81165
81166
  fs30.mkdirSync(outputDir, { recursive: true });
81166
- try {
81167
- console.log(`${prefix}Generating PCB SVG...`);
81168
- const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
81169
- fs30.writeFileSync(path32.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
81170
- console.log(`${prefix}Written pcb.svg`);
81171
- } catch (error) {
81172
- console.error(`${prefix}Failed to generate PCB SVG:`, error);
81167
+ if (imageFormats.pcbSvgs) {
81168
+ try {
81169
+ console.log(`${prefix}Generating PCB SVG...`);
81170
+ const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
81171
+ fs30.writeFileSync(path32.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
81172
+ console.log(`${prefix}Written pcb.svg`);
81173
+ } catch (error) {
81174
+ console.error(`${prefix}Failed to generate PCB SVG:`, error);
81175
+ }
81173
81176
  }
81174
- try {
81175
- console.log(`${prefix}Generating schematic SVG...`);
81176
- const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson);
81177
- fs30.writeFileSync(path32.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
81178
- console.log(`${prefix}Written schematic.svg`);
81179
- } catch (error) {
81180
- console.error(`${prefix}Failed to generate schematic SVG:`, error);
81177
+ if (imageFormats.schematicSvgs) {
81178
+ try {
81179
+ console.log(`${prefix}Generating schematic SVG...`);
81180
+ const schematicSvg = convertCircuitJsonToSchematicSvg(circuitJson);
81181
+ fs30.writeFileSync(path32.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
81182
+ console.log(`${prefix}Written schematic.svg`);
81183
+ } catch (error) {
81184
+ console.error(`${prefix}Failed to generate schematic SVG:`, error);
81185
+ }
81181
81186
  }
81182
- try {
81183
- console.log(`${prefix}Converting circuit to GLB...`);
81184
- const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
81185
- const glbBuffer = await convertCircuitJsonToGltf3(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
81186
- console.log(`${prefix}Rendering GLB to PNG buffer...`);
81187
- const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
81188
- const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer, {
81189
- camPos: [10, 10, 10],
81190
- lookAt: [0, 0, 0]
81191
- });
81192
- fs30.writeFileSync(path32.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array2(pngBuffer)));
81193
- console.log(`${prefix}Written 3d.png`);
81194
- } catch (error) {
81195
- console.error(`${prefix}Failed to generate 3D PNG:`, error);
81187
+ if (imageFormats.threeDPngs) {
81188
+ try {
81189
+ console.log(`${prefix}Converting circuit to GLB...`);
81190
+ const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
81191
+ const glbBuffer = await convertCircuitJsonToGltf3(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
81192
+ console.log(`${prefix}Rendering GLB to PNG buffer...`);
81193
+ const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
81194
+ const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer);
81195
+ fs30.writeFileSync(path32.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array2(pngBuffer)));
81196
+ console.log(`${prefix}Written 3d.png`);
81197
+ } catch (error) {
81198
+ console.error(`${prefix}Failed to generate 3D PNG:`, error);
81199
+ }
81196
81200
  }
81197
81201
  };
81198
81202
  var buildPreviewImages = async ({
@@ -81200,7 +81204,8 @@ var buildPreviewImages = async ({
81200
81204
  distDir,
81201
81205
  mainEntrypoint,
81202
81206
  previewComponentPath,
81203
- allImages
81207
+ allImages,
81208
+ imageFormats
81204
81209
  }) => {
81205
81210
  const successfulBuilds = builtFiles.filter((file) => file.ok);
81206
81211
  const previewEntrypoint = previewComponentPath || mainEntrypoint;
@@ -81215,7 +81220,8 @@ var buildPreviewImages = async ({
81215
81220
  await generatePreviewAssets({
81216
81221
  build,
81217
81222
  outputDir,
81218
- distDir
81223
+ distDir,
81224
+ imageFormats
81219
81225
  });
81220
81226
  }
81221
81227
  return;
@@ -81235,7 +81241,8 @@ var buildPreviewImages = async ({
81235
81241
  await generatePreviewAssets({
81236
81242
  build: previewBuild,
81237
81243
  outputDir: distDir,
81238
- distDir
81244
+ distDir,
81245
+ imageFormats
81239
81246
  });
81240
81247
  };
81241
81248
 
@@ -81518,6 +81525,69 @@ async function getBuildEntrypoints({
81518
81525
  return buildFromProjectDir();
81519
81526
  }
81520
81527
 
81528
+ // cli/build/image-format-selection.ts
81529
+ var DEFAULT_IMAGE_FORMAT_SELECTION = {
81530
+ threeDPngs: true,
81531
+ pcbSvgs: true,
81532
+ schematicSvgs: true
81533
+ };
81534
+ var EMPTY_IMAGE_FORMAT_SELECTION = {
81535
+ threeDPngs: false,
81536
+ pcbSvgs: false,
81537
+ schematicSvgs: false
81538
+ };
81539
+ var hasAnyImageFormatSelected = (selection) => selection.threeDPngs || selection.pcbSvgs || selection.schematicSvgs;
81540
+ var hasNewOutputFlags = (options) => Boolean(options?.pngs || options?.svgs || options?.pcbSvgs || options?.schematicSvgs);
81541
+ var hasEstablishedOutputFlags = (options) => Boolean(options?.["3d"] || options?.pcbOnly || options?.schematicOnly);
81542
+ var resolveImageFormatSelection = (options) => {
81543
+ const hasNewFlags = hasNewOutputFlags(options);
81544
+ const hasEstablishedFlags = hasEstablishedOutputFlags(options);
81545
+ const hasExplicitSelection = hasNewFlags || hasEstablishedFlags;
81546
+ if (!hasExplicitSelection) {
81547
+ return {
81548
+ selection: { ...DEFAULT_IMAGE_FORMAT_SELECTION },
81549
+ hasExplicitSelection: false
81550
+ };
81551
+ }
81552
+ if (!hasNewFlags && hasEstablishedFlags) {
81553
+ const selection2 = {
81554
+ threeDPngs: Boolean(options?.["3d"]),
81555
+ pcbSvgs: true,
81556
+ schematicSvgs: true
81557
+ };
81558
+ if (options?.pcbOnly && !options?.schematicOnly) {
81559
+ selection2.schematicSvgs = false;
81560
+ }
81561
+ if (options?.schematicOnly && !options?.pcbOnly) {
81562
+ selection2.pcbSvgs = false;
81563
+ }
81564
+ return { selection: selection2, hasExplicitSelection: true };
81565
+ }
81566
+ const selection = {
81567
+ ...EMPTY_IMAGE_FORMAT_SELECTION
81568
+ };
81569
+ if (options?.svgs) {
81570
+ selection.pcbSvgs = true;
81571
+ selection.schematicSvgs = true;
81572
+ }
81573
+ if (options?.pcbSvgs) {
81574
+ selection.pcbSvgs = true;
81575
+ }
81576
+ if (options?.schematicSvgs) {
81577
+ selection.schematicSvgs = true;
81578
+ }
81579
+ if (options?.pngs || options?.["3d"]) {
81580
+ selection.threeDPngs = true;
81581
+ }
81582
+ if (options?.pcbOnly && !options?.schematicOnly) {
81583
+ selection.schematicSvgs = false;
81584
+ }
81585
+ if (options?.schematicOnly && !options?.pcbOnly) {
81586
+ selection.pcbSvgs = false;
81587
+ }
81588
+ return { selection, hasExplicitSelection: true };
81589
+ };
81590
+
81521
81591
  // cli/build/resolve-build-options.ts
81522
81592
  var resolveBuildOptions = ({
81523
81593
  cliOptions,
@@ -82128,7 +82198,7 @@ var getOutputDirName = (relativePath) => {
82128
82198
  return relativePath.replace(/(\.board|\.circuit)?\.tsx$/, "").replace(/\.circuit\.json$/, "");
82129
82199
  };
82130
82200
  var registerBuild = (program2) => {
82131
- program2.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--ignore-config", "Ignore options from tscircuit.config.json").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("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad-project", "Generate KiCad project directories for each successful build output").option("--kicad-library", "Generate KiCad library in dist/kicad-library").option("--kicad-library-name <name>", "Specify the name of the KiCad library").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--glbs", "Generate GLB 3D model files for every successful build").option("--profile", "Log per-circuit circuit.json generation time during build").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").option("--inject-props <json>", "Inject JSON props into the built file's default export").option("--inject-props-file <path>", "Inject JSON props from a file into the built file's default export").action(async (file, options) => {
82201
+ program2.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--ignore-config", "Ignore options from tscircuit.config.json").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("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--pngs", "Generate PNG outputs during build generation").option("--svgs", "Generate SVG outputs during build generation").option("--pcb-svgs", "Generate PCB SVG outputs during build generation").option("--schematic-svgs", "Generate schematic SVG outputs during build generation").option("--3d", "Generate 3D PNG outputs during build generation").option("--pcb-only", "Generate only PCB SVG outputs during build generation").option("--schematic-only", "Generate only schematic SVG outputs during build generation").option("--kicad-project", "Generate KiCad project directories for each successful build output").option("--kicad-library", "Generate KiCad library in dist/kicad-library").option("--kicad-library-name <name>", "Specify the name of the KiCad library").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--glbs", "Generate GLB 3D model files for every successful build").option("--profile", "Log per-circuit circuit.json generation time during build").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").option("--inject-props <json>", "Inject JSON props into the built file's default export").option("--inject-props-file <path>", "Inject JSON props from a file into the built file's default export").action(async (file, options) => {
82132
82202
  try {
82133
82203
  const transpileExplicitlyRequested = options?.transpile === true;
82134
82204
  const resolvedRoot = path39.resolve(process.cwd());
@@ -82207,15 +82277,20 @@ var registerBuild = (program2) => {
82207
82277
  injectPropsFile: resolvedOptions?.injectPropsFile,
82208
82278
  projectDir
82209
82279
  });
82280
+ const {
82281
+ selection: imageFormatSelection,
82282
+ hasExplicitSelection: hasExplicitImageFormatSelection
82283
+ } = resolveImageFormatSelection(resolvedOptions);
82210
82284
  const buildOptions = {
82211
82285
  ignoreErrors: resolvedOptions?.ignoreErrors,
82212
82286
  ignoreWarnings: resolvedOptions?.ignoreWarnings,
82213
82287
  platformConfig,
82214
82288
  profile: resolvedOptions?.profile,
82215
82289
  injectedProps,
82216
- generatePreviewAssets: false
82290
+ generatePreviewAssets: false,
82291
+ imageFormats: imageFormatSelection
82217
82292
  };
82218
- const shouldGeneratePreviewImages = resolvedOptions?.previewImages || resolvedOptions?.allImages;
82293
+ const shouldGeneratePreviewImages = Boolean((resolvedOptions?.previewImages || resolvedOptions?.allImages || hasExplicitImageFormatSelection) && hasAnyImageFormatSelected(imageFormatSelection));
82219
82294
  const shouldGenerateAllPreviewImages = Boolean(resolvedOptions?.allImages);
82220
82295
  const shouldGeneratePreviewAssetsInWorker = Boolean(resolvedOptions?.ci && concurrencyValue > 1 && shouldGeneratePreviewImages);
82221
82296
  buildOptions.generatePreviewAssets = shouldGeneratePreviewAssetsInWorker;
@@ -82379,7 +82454,8 @@ var registerBuild = (program2) => {
82379
82454
  distDir,
82380
82455
  mainEntrypoint,
82381
82456
  previewComponentPath,
82382
- allImages: shouldGenerateAllPreviewImages
82457
+ allImages: shouldGenerateAllPreviewImages,
82458
+ imageFormats: imageFormatSelection
82383
82459
  });
82384
82460
  }
82385
82461
  }
@@ -82521,6 +82597,13 @@ var registerBuild = (program2) => {
82521
82597
  resolvedOptions?.transpile && "transpile",
82522
82598
  resolvedOptions?.previewImages && "preview-images",
82523
82599
  resolvedOptions?.allImages && "all-images",
82600
+ resolvedOptions?.pngs && "pngs",
82601
+ resolvedOptions?.svgs && "svgs",
82602
+ resolvedOptions?.pcbSvgs && "pcb-svgs",
82603
+ resolvedOptions?.schematicSvgs && "schematic-svgs",
82604
+ resolvedOptions?.["3d"] && "3d",
82605
+ resolvedOptions?.pcbOnly && "pcb-only",
82606
+ resolvedOptions?.schematicOnly && "schematic-only",
82524
82607
  resolvedOptions?.glbs && "glbs",
82525
82608
  resolvedOptions?.kicadProject && "kicad-project",
82526
82609
  resolvedOptions?.kicadLibrary && "kicad-library",
package/dist/lib/index.js CHANGED
@@ -60435,7 +60435,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
60435
60435
  }));
60436
60436
  };
60437
60437
  // package.json
60438
- var version = "0.1.1064";
60438
+ var version = "0.1.1065";
60439
60439
  var package_default = {
60440
60440
  name: "@tscircuit/cli",
60441
60441
  version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.1065",
3
+ "version": "0.1.1066",
4
4
  "main": "dist/cli/main.js",
5
5
  "exports": {
6
6
  ".": "./dist/cli/main.js",