@tscircuit/cli 0.1.356 → 0.1.357

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 +95 -76
  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.355";
72196
+ var version = "0.1.356";
72197
72197
  var package_default = {
72198
72198
  name: "@tscircuit/cli",
72199
72199
  version,
@@ -195611,21 +195611,26 @@ var buildFile = async (input, output, projectDir, options) => {
195611
195611
  // cli/build/get-build-entrypoints.ts
195612
195612
  import fs29 from "node:fs";
195613
195613
  import path28 from "node:path";
195614
+ var isSubPath2 = (maybeChild, maybeParent) => {
195615
+ const relative9 = path28.relative(maybeParent, maybeChild);
195616
+ return relative9 === "" || !relative9.startsWith("..") && !path28.isAbsolute(relative9);
195617
+ };
195614
195618
  async function getBuildEntrypoints({
195615
195619
  fileOrDir,
195616
195620
  rootDir = process.cwd()
195617
195621
  }) {
195618
195622
  const resolvedRoot = path28.resolve(rootDir);
195619
- const buildFromProjectDir = async (projectDir2) => {
195620
- const files = findBoardFiles({ projectDir: projectDir2 });
195623
+ const includeBoardFiles = getBoardFilePatterns(resolvedRoot);
195624
+ const buildFromProjectDir = async () => {
195625
+ const files = findBoardFiles({ projectDir: resolvedRoot });
195621
195626
  if (files.length > 0) {
195622
195627
  return {
195623
- projectDir: projectDir2,
195628
+ projectDir: resolvedRoot,
195624
195629
  circuitFiles: files
195625
195630
  };
195626
195631
  }
195627
195632
  const mainEntrypoint = await getEntrypoint({
195628
- projectDir: projectDir2,
195633
+ projectDir: resolvedRoot,
195629
195634
  onSuccess: () => {
195630
195635
  return;
195631
195636
  },
@@ -195635,26 +195640,34 @@ async function getBuildEntrypoints({
195635
195640
  });
195636
195641
  if (mainEntrypoint) {
195637
195642
  return {
195638
- projectDir: projectDir2,
195643
+ projectDir: resolvedRoot,
195639
195644
  mainEntrypoint,
195640
195645
  circuitFiles: [mainEntrypoint]
195641
195646
  };
195642
195647
  }
195643
195648
  return {
195644
- projectDir: projectDir2,
195649
+ projectDir: resolvedRoot,
195645
195650
  circuitFiles: []
195646
195651
  };
195647
195652
  };
195648
195653
  if (fileOrDir) {
195649
195654
  const resolved = path28.resolve(resolvedRoot, fileOrDir);
195650
195655
  if (fs29.existsSync(resolved) && fs29.statSync(resolved).isDirectory()) {
195651
- const projectDir2 = resolved;
195652
- return buildFromProjectDir(projectDir2);
195656
+ const circuitFiles = findBoardFiles({
195657
+ projectDir: resolvedRoot,
195658
+ filePaths: [resolved]
195659
+ }).filter((file) => isSubPath2(file, resolved));
195660
+ if (circuitFiles.length === 0) {
195661
+ throw new Error(`There were no files to build found matching the includeBoardFiles globs: ${JSON.stringify(includeBoardFiles)}`);
195662
+ }
195663
+ return {
195664
+ projectDir: resolvedRoot,
195665
+ circuitFiles
195666
+ };
195653
195667
  }
195654
195668
  return { projectDir: path28.dirname(resolved), circuitFiles: [resolved] };
195655
195669
  }
195656
- const projectDir = resolvedRoot;
195657
- return buildFromProjectDir(projectDir);
195670
+ return buildFromProjectDir();
195658
195671
  }
195659
195672
 
195660
195673
  // lib/site/getStaticIndexHtmlFile.ts
@@ -195807,77 +195820,83 @@ var buildPreviewImages = async ({
195807
195820
  // cli/build/register.ts
195808
195821
  var registerBuild = (program3) => {
195809
195822
  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;
195823
+ try {
195824
+ const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
195825
+ fileOrDir: file
195826
+ });
195827
+ const platformConfig2 = (() => {
195828
+ if (!options?.disablePcb && !options?.disablePartsEngine)
195829
+ return;
195830
+ const config = {};
195831
+ if (options?.disablePcb) {
195832
+ config.pcbDisabled = true;
195833
+ }
195834
+ if (options?.disablePartsEngine) {
195835
+ config.partsEngineDisabled = true;
195836
+ }
195837
+ return config;
195838
+ })();
195839
+ const distDir = path30.join(projectDir, "dist");
195840
+ fs31.mkdirSync(distDir, { recursive: true });
195841
+ console.log(`Building ${circuitFiles.length} file(s)...`);
195842
+ let hasErrors = false;
195843
+ const staticFileReferences = [];
195844
+ const builtFiles = [];
195845
+ for (const filePath of circuitFiles) {
195846
+ const relative9 = path30.relative(projectDir, filePath);
195847
+ console.log(`Building ${relative9}...`);
195848
+ const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
195849
+ const outputPath = path30.join(distDir, outputDirName, "circuit.json");
195850
+ const ok = await buildFile(filePath, outputPath, projectDir, {
195851
+ ignoreErrors: options?.ignoreErrors,
195852
+ ignoreWarnings: options?.ignoreWarnings,
195853
+ platformConfig: platformConfig2
195854
+ });
195855
+ builtFiles.push({
195856
+ sourcePath: filePath,
195857
+ outputPath,
195858
+ ok
195859
+ });
195860
+ if (!ok) {
195861
+ hasErrors = true;
195862
+ } else if (options?.site) {
195863
+ const normalizedSourcePath = relative9.split(path30.sep).join("/");
195864
+ const relativeOutputPath = path30.join(outputDirName, "circuit.json");
195865
+ const normalizedOutputPath = relativeOutputPath.split(path30.sep).join("/");
195866
+ staticFileReferences.push({
195867
+ filePath: normalizedSourcePath,
195868
+ fileStaticAssetUrl: `./${normalizedOutputPath}`
195869
+ });
195870
+ }
195819
195871
  }
195820
- if (options?.disablePartsEngine) {
195821
- config.partsEngineDisabled = true;
195872
+ if (hasErrors && !options?.ignoreErrors) {
195873
+ process.exit(1);
195822
195874
  }
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}`
195875
+ const shouldGeneratePreviewImages = options?.previewImages || options?.allImages;
195876
+ if (shouldGeneratePreviewImages) {
195877
+ console.log(options?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
195878
+ await buildPreviewImages({
195879
+ builtFiles,
195880
+ distDir,
195881
+ mainEntrypoint,
195882
+ allImages: options?.allImages
195855
195883
  });
195856
195884
  }
195857
- }
195858
- if (hasErrors && !options?.ignoreErrors) {
195885
+ if (options?.site) {
195886
+ const indexHtml = getStaticIndexHtmlFile({
195887
+ files: staticFileReferences,
195888
+ standaloneScriptSrc: "./standalone.min.js"
195889
+ });
195890
+ fs31.writeFileSync(path30.join(distDir, "index.html"), indexHtml);
195891
+ fs31.writeFileSync(path30.join(distDir, "standalone.min.js"), standalone_min_default);
195892
+ }
195893
+ console.log("Build complete!");
195894
+ process.exit(0);
195895
+ } catch (error) {
195896
+ const message = error instanceof Error ? error.message : String(error);
195897
+ console.error(message);
195859
195898
  process.exit(1);
195860
195899
  }
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
195900
  });
195882
195901
  };
195883
195902
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.356",
3
+ "version": "0.1.357",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",