@tscircuit/cli 0.1.356 → 0.1.358

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 +107 -80
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -71530,7 +71530,8 @@ import { z } from "zod";
71530
71530
  var projectConfigSchema = z.object({
71531
71531
  mainEntrypoint: z.string().optional(),
71532
71532
  ignoredFiles: z.array(z.string()).optional(),
71533
- includeBoardFiles: z.array(z.string()).optional()
71533
+ includeBoardFiles: z.array(z.string()).optional(),
71534
+ snapshotsDir: z.string().optional()
71534
71535
  });
71535
71536
 
71536
71537
  // lib/project-config/index.ts
@@ -71561,6 +71562,10 @@ var getBoardFilePatterns = (projectDir = process.cwd()) => {
71561
71562
  }
71562
71563
  return DEFAULT_BOARD_FILE_PATTERNS;
71563
71564
  };
71565
+ var getSnapshotsDir = (projectDir = process.cwd()) => {
71566
+ const config = loadProjectConfig(projectDir);
71567
+ return config?.snapshotsDir;
71568
+ };
71564
71569
  var saveProjectConfig = (config, projectDir = process.cwd()) => {
71565
71570
  const configPath = path9.join(projectDir, CONFIG_FILENAME);
71566
71571
  try {
@@ -72193,7 +72198,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
72193
72198
  import { execSync as execSync2 } from "node:child_process";
72194
72199
  var import_semver2 = __toESM2(require_semver2(), 1);
72195
72200
  // package.json
72196
- var version = "0.1.355";
72201
+ var version = "0.1.357";
72197
72202
  var package_default = {
72198
72203
  name: "@tscircuit/cli",
72199
72204
  version,
@@ -72205,7 +72210,7 @@ var package_default = {
72205
72210
  "@tscircuit/fake-snippets": "^0.0.110",
72206
72211
  "@tscircuit/file-server": "^0.0.32",
72207
72212
  "@tscircuit/math-utils": "0.0.21",
72208
- "@tscircuit/props": "^0.0.356",
72213
+ "@tscircuit/props": "^0.0.371",
72209
72214
  "@tscircuit/runframe": "^0.0.1123",
72210
72215
  "@tscircuit/schematic-match-adapt": "^0.0.22",
72211
72216
  "@types/bun": "^1.2.2",
@@ -195611,21 +195616,26 @@ var buildFile = async (input, output, projectDir, options) => {
195611
195616
  // cli/build/get-build-entrypoints.ts
195612
195617
  import fs29 from "node:fs";
195613
195618
  import path28 from "node:path";
195619
+ var isSubPath2 = (maybeChild, maybeParent) => {
195620
+ const relative9 = path28.relative(maybeParent, maybeChild);
195621
+ return relative9 === "" || !relative9.startsWith("..") && !path28.isAbsolute(relative9);
195622
+ };
195614
195623
  async function getBuildEntrypoints({
195615
195624
  fileOrDir,
195616
195625
  rootDir = process.cwd()
195617
195626
  }) {
195618
195627
  const resolvedRoot = path28.resolve(rootDir);
195619
- const buildFromProjectDir = async (projectDir2) => {
195620
- const files = findBoardFiles({ projectDir: projectDir2 });
195628
+ const includeBoardFiles = getBoardFilePatterns(resolvedRoot);
195629
+ const buildFromProjectDir = async () => {
195630
+ const files = findBoardFiles({ projectDir: resolvedRoot });
195621
195631
  if (files.length > 0) {
195622
195632
  return {
195623
- projectDir: projectDir2,
195633
+ projectDir: resolvedRoot,
195624
195634
  circuitFiles: files
195625
195635
  };
195626
195636
  }
195627
195637
  const mainEntrypoint = await getEntrypoint({
195628
- projectDir: projectDir2,
195638
+ projectDir: resolvedRoot,
195629
195639
  onSuccess: () => {
195630
195640
  return;
195631
195641
  },
@@ -195635,26 +195645,34 @@ async function getBuildEntrypoints({
195635
195645
  });
195636
195646
  if (mainEntrypoint) {
195637
195647
  return {
195638
- projectDir: projectDir2,
195648
+ projectDir: resolvedRoot,
195639
195649
  mainEntrypoint,
195640
195650
  circuitFiles: [mainEntrypoint]
195641
195651
  };
195642
195652
  }
195643
195653
  return {
195644
- projectDir: projectDir2,
195654
+ projectDir: resolvedRoot,
195645
195655
  circuitFiles: []
195646
195656
  };
195647
195657
  };
195648
195658
  if (fileOrDir) {
195649
195659
  const resolved = path28.resolve(resolvedRoot, fileOrDir);
195650
195660
  if (fs29.existsSync(resolved) && fs29.statSync(resolved).isDirectory()) {
195651
- const projectDir2 = resolved;
195652
- return buildFromProjectDir(projectDir2);
195661
+ const circuitFiles = findBoardFiles({
195662
+ projectDir: resolvedRoot,
195663
+ filePaths: [resolved]
195664
+ }).filter((file) => isSubPath2(file, resolved));
195665
+ if (circuitFiles.length === 0) {
195666
+ throw new Error(`There were no files to build found matching the includeBoardFiles globs: ${JSON.stringify(includeBoardFiles)}`);
195667
+ }
195668
+ return {
195669
+ projectDir: resolvedRoot,
195670
+ circuitFiles
195671
+ };
195653
195672
  }
195654
195673
  return { projectDir: path28.dirname(resolved), circuitFiles: [resolved] };
195655
195674
  }
195656
- const projectDir = resolvedRoot;
195657
- return buildFromProjectDir(projectDir);
195675
+ return buildFromProjectDir();
195658
195676
  }
195659
195677
 
195660
195678
  // lib/site/getStaticIndexHtmlFile.ts
@@ -195807,77 +195825,83 @@ var buildPreviewImages = async ({
195807
195825
  // cli/build/register.ts
195808
195826
  var registerBuild = (program3) => {
195809
195827
  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) => {
195810
- const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
195811
- fileOrDir: file
195812
- });
195813
- const platformConfig2 = (() => {
195814
- if (!options?.disablePcb && !options?.disablePartsEngine)
195815
- return;
195816
- const config = {};
195817
- if (options?.disablePcb) {
195818
- config.pcbDisabled = true;
195828
+ try {
195829
+ const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
195830
+ fileOrDir: file
195831
+ });
195832
+ const platformConfig2 = (() => {
195833
+ if (!options?.disablePcb && !options?.disablePartsEngine)
195834
+ return;
195835
+ const config = {};
195836
+ if (options?.disablePcb) {
195837
+ config.pcbDisabled = true;
195838
+ }
195839
+ if (options?.disablePartsEngine) {
195840
+ config.partsEngineDisabled = true;
195841
+ }
195842
+ return config;
195843
+ })();
195844
+ const distDir = path30.join(projectDir, "dist");
195845
+ fs31.mkdirSync(distDir, { recursive: true });
195846
+ console.log(`Building ${circuitFiles.length} file(s)...`);
195847
+ let hasErrors = false;
195848
+ const staticFileReferences = [];
195849
+ const builtFiles = [];
195850
+ for (const filePath of circuitFiles) {
195851
+ const relative9 = path30.relative(projectDir, filePath);
195852
+ console.log(`Building ${relative9}...`);
195853
+ const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
195854
+ const outputPath = path30.join(distDir, outputDirName, "circuit.json");
195855
+ const ok = await buildFile(filePath, outputPath, projectDir, {
195856
+ ignoreErrors: options?.ignoreErrors,
195857
+ ignoreWarnings: options?.ignoreWarnings,
195858
+ platformConfig: platformConfig2
195859
+ });
195860
+ builtFiles.push({
195861
+ sourcePath: filePath,
195862
+ outputPath,
195863
+ ok
195864
+ });
195865
+ if (!ok) {
195866
+ hasErrors = true;
195867
+ } else if (options?.site) {
195868
+ const normalizedSourcePath = relative9.split(path30.sep).join("/");
195869
+ const relativeOutputPath = path30.join(outputDirName, "circuit.json");
195870
+ const normalizedOutputPath = relativeOutputPath.split(path30.sep).join("/");
195871
+ staticFileReferences.push({
195872
+ filePath: normalizedSourcePath,
195873
+ fileStaticAssetUrl: `./${normalizedOutputPath}`
195874
+ });
195875
+ }
195819
195876
  }
195820
- if (options?.disablePartsEngine) {
195821
- config.partsEngineDisabled = true;
195877
+ if (hasErrors && !options?.ignoreErrors) {
195878
+ process.exit(1);
195822
195879
  }
195823
- return config;
195824
- })();
195825
- const distDir = path30.join(projectDir, "dist");
195826
- fs31.mkdirSync(distDir, { recursive: true });
195827
- console.log(`Building ${circuitFiles.length} file(s)...`);
195828
- let hasErrors = false;
195829
- const staticFileReferences = [];
195830
- const builtFiles = [];
195831
- for (const filePath of circuitFiles) {
195832
- const relative9 = path30.relative(projectDir, filePath);
195833
- console.log(`Building ${relative9}...`);
195834
- const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
195835
- const outputPath = path30.join(distDir, outputDirName, "circuit.json");
195836
- const ok = await buildFile(filePath, outputPath, projectDir, {
195837
- ignoreErrors: options?.ignoreErrors,
195838
- ignoreWarnings: options?.ignoreWarnings,
195839
- platformConfig: platformConfig2
195840
- });
195841
- builtFiles.push({
195842
- sourcePath: filePath,
195843
- outputPath,
195844
- ok
195845
- });
195846
- if (!ok) {
195847
- hasErrors = true;
195848
- } else if (options?.site) {
195849
- const normalizedSourcePath = relative9.split(path30.sep).join("/");
195850
- const relativeOutputPath = path30.join(outputDirName, "circuit.json");
195851
- const normalizedOutputPath = relativeOutputPath.split(path30.sep).join("/");
195852
- staticFileReferences.push({
195853
- filePath: normalizedSourcePath,
195854
- fileStaticAssetUrl: `./${normalizedOutputPath}`
195880
+ const shouldGeneratePreviewImages = options?.previewImages || options?.allImages;
195881
+ if (shouldGeneratePreviewImages) {
195882
+ console.log(options?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
195883
+ await buildPreviewImages({
195884
+ builtFiles,
195885
+ distDir,
195886
+ mainEntrypoint,
195887
+ allImages: options?.allImages
195855
195888
  });
195856
195889
  }
195857
- }
195858
- if (hasErrors && !options?.ignoreErrors) {
195890
+ if (options?.site) {
195891
+ const indexHtml = getStaticIndexHtmlFile({
195892
+ files: staticFileReferences,
195893
+ standaloneScriptSrc: "./standalone.min.js"
195894
+ });
195895
+ fs31.writeFileSync(path30.join(distDir, "index.html"), indexHtml);
195896
+ fs31.writeFileSync(path30.join(distDir, "standalone.min.js"), standalone_min_default);
195897
+ }
195898
+ console.log("Build complete!");
195899
+ process.exit(0);
195900
+ } catch (error) {
195901
+ const message = error instanceof Error ? error.message : String(error);
195902
+ console.error(message);
195859
195903
  process.exit(1);
195860
195904
  }
195861
- const shouldGeneratePreviewImages = options?.previewImages || options?.allImages;
195862
- if (shouldGeneratePreviewImages) {
195863
- console.log(options?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
195864
- await buildPreviewImages({
195865
- builtFiles,
195866
- distDir,
195867
- mainEntrypoint,
195868
- allImages: options?.allImages
195869
- });
195870
- }
195871
- if (options?.site) {
195872
- const indexHtml = getStaticIndexHtmlFile({
195873
- files: staticFileReferences,
195874
- standaloneScriptSrc: "./standalone.min.js"
195875
- });
195876
- fs31.writeFileSync(path30.join(distDir, "index.html"), indexHtml);
195877
- fs31.writeFileSync(path30.join(distDir, "standalone.min.js"), standalone_min_default);
195878
- }
195879
- console.log("Build complete!");
195880
- process.exit(0);
195881
195905
  });
195882
195906
  };
195883
195907
 
@@ -195945,6 +195969,7 @@ var snapshotProject = async ({
195945
195969
  console.log("No entrypoint found. Run 'tsci init' to bootstrap a project or specify a file with 'tsci snapshot <file>'");
195946
195970
  return onExit(0);
195947
195971
  }
195972
+ const snapshotsDirName = getSnapshotsDir(projectDir);
195948
195973
  const mismatches = [];
195949
195974
  let didUpdate = false;
195950
195975
  for (const file of boardFiles) {
@@ -196002,7 +196027,9 @@ var snapshotProject = async ({
196002
196027
  } catch (error) {
196003
196028
  const errorMessage = error instanceof Error ? error.message : String(error);
196004
196029
  if (errorMessage.includes("No pcb_board found in circuit JSON")) {
196005
- const snapDir2 = path31.join(path31.dirname(file), "__snapshots__");
196030
+ const fileDir = path31.dirname(file);
196031
+ const relativeDir = path31.relative(projectDir, fileDir);
196032
+ const snapDir2 = snapshotsDirName ? path31.join(projectDir, snapshotsDirName, relativeDir) : path31.join(fileDir, "__snapshots__");
196006
196033
  const base2 = path31.basename(file).replace(/\.tsx$/, "");
196007
196034
  const snap3dPath = path31.join(snapDir2, `${base2}-3d.snap.png`);
196008
196035
  const existing3dSnapshot = fs33.existsSync(snap3dPath);
@@ -196026,7 +196053,7 @@ var snapshotProject = async ({
196026
196053
  }
196027
196054
  }
196028
196055
  }
196029
- const snapDir = path31.join(path31.dirname(file), "__snapshots__");
196056
+ const snapDir = snapshotsDirName ? path31.join(projectDir, snapshotsDirName, path31.relative(projectDir, path31.dirname(file))) : path31.join(path31.dirname(file), "__snapshots__");
196030
196057
  fs33.mkdirSync(snapDir, { recursive: true });
196031
196058
  const base = path31.basename(file).replace(/\.tsx$/, "");
196032
196059
  const snapshots = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.356",
3
+ "version": "0.1.358",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",
@@ -9,7 +9,7 @@
9
9
  "@tscircuit/fake-snippets": "^0.0.110",
10
10
  "@tscircuit/file-server": "^0.0.32",
11
11
  "@tscircuit/math-utils": "0.0.21",
12
- "@tscircuit/props": "^0.0.356",
12
+ "@tscircuit/props": "^0.0.371",
13
13
  "@tscircuit/runframe": "^0.0.1123",
14
14
  "@tscircuit/schematic-match-adapt": "^0.0.22",
15
15
  "@types/bun": "^1.2.2",