@tscircuit/cli 0.1.355 → 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.
- package/dist/main.js +186 -104
- 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.
|
|
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
|
|
195620
|
-
|
|
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:
|
|
195628
|
+
projectDir: resolvedRoot,
|
|
195624
195629
|
circuitFiles: files
|
|
195625
195630
|
};
|
|
195626
195631
|
}
|
|
195627
195632
|
const mainEntrypoint = await getEntrypoint({
|
|
195628
|
-
projectDir:
|
|
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:
|
|
195643
|
+
projectDir: resolvedRoot,
|
|
195639
195644
|
mainEntrypoint,
|
|
195640
195645
|
circuitFiles: [mainEntrypoint]
|
|
195641
195646
|
};
|
|
195642
195647
|
}
|
|
195643
195648
|
return {
|
|
195644
|
-
projectDir:
|
|
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
|
|
195652
|
-
|
|
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
|
-
|
|
195657
|
-
return buildFromProjectDir(projectDir);
|
|
195670
|
+
return buildFromProjectDir();
|
|
195658
195671
|
}
|
|
195659
195672
|
|
|
195660
195673
|
// lib/site/getStaticIndexHtmlFile.ts
|
|
@@ -195694,13 +195707,97 @@ import {
|
|
|
195694
195707
|
} from "circuit-to-svg";
|
|
195695
195708
|
import { renderGLTFToPNGBufferFromGLBBuffer } from "poppygl";
|
|
195696
195709
|
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf2 } from "circuit-json-to-gltf";
|
|
195710
|
+
var viewToArrayBuffer = (view) => {
|
|
195711
|
+
const copy = new Uint8Array(view.byteLength);
|
|
195712
|
+
copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
195713
|
+
return copy.buffer;
|
|
195714
|
+
};
|
|
195715
|
+
var normalizeToArrayBuffer = async (value) => {
|
|
195716
|
+
if (value instanceof ArrayBuffer) {
|
|
195717
|
+
return value;
|
|
195718
|
+
}
|
|
195719
|
+
if (ArrayBuffer.isView(value)) {
|
|
195720
|
+
return viewToArrayBuffer(value);
|
|
195721
|
+
}
|
|
195722
|
+
if (value && typeof value === "object") {
|
|
195723
|
+
const maybeArrayBufferLike = value;
|
|
195724
|
+
if (typeof maybeArrayBufferLike.arrayBuffer === "function") {
|
|
195725
|
+
const result = maybeArrayBufferLike.arrayBuffer();
|
|
195726
|
+
return result instanceof Promise ? await result : result;
|
|
195727
|
+
}
|
|
195728
|
+
}
|
|
195729
|
+
throw new Error("Expected ArrayBuffer, ArrayBufferView, or Buffer-compatible object");
|
|
195730
|
+
};
|
|
195731
|
+
var normalizeToUint8Array = (value) => {
|
|
195732
|
+
if (value instanceof Uint8Array) {
|
|
195733
|
+
return value;
|
|
195734
|
+
}
|
|
195735
|
+
if (value instanceof ArrayBuffer) {
|
|
195736
|
+
return new Uint8Array(value);
|
|
195737
|
+
}
|
|
195738
|
+
if (ArrayBuffer.isView(value)) {
|
|
195739
|
+
return new Uint8Array(viewToArrayBuffer(value));
|
|
195740
|
+
}
|
|
195741
|
+
throw new Error("Expected Uint8Array, ArrayBuffer, or ArrayBufferView for PNG");
|
|
195742
|
+
};
|
|
195743
|
+
var generatePreviewAssets = async ({
|
|
195744
|
+
build,
|
|
195745
|
+
outputDir,
|
|
195746
|
+
distDir
|
|
195747
|
+
}) => {
|
|
195748
|
+
const prefixRelative = path29.relative(distDir, outputDir) || ".";
|
|
195749
|
+
const prefix = prefixRelative === "." ? "" : `[${prefixRelative}] `;
|
|
195750
|
+
try {
|
|
195751
|
+
const circuitJsonRaw = fs30.readFileSync(build.outputPath, "utf-8");
|
|
195752
|
+
const circuitJson = JSON.parse(circuitJsonRaw);
|
|
195753
|
+
console.log(`${prefix}Generating PCB SVG...`);
|
|
195754
|
+
const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
|
|
195755
|
+
console.log(`${prefix}Generating schematic SVG...`);
|
|
195756
|
+
const schematicSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
|
|
195757
|
+
console.log(`${prefix}Converting circuit to GLB...`);
|
|
195758
|
+
const glbBuffer = await convertCircuitJsonToGltf2(circuitJson, {
|
|
195759
|
+
format: "glb"
|
|
195760
|
+
});
|
|
195761
|
+
console.log(`${prefix}Rendering GLB to PNG buffer...`);
|
|
195762
|
+
const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
|
|
195763
|
+
const pngBuffer = await renderGLTFToPNGBufferFromGLBBuffer(glbArrayBuffer, {
|
|
195764
|
+
camPos: [10, 10, 10],
|
|
195765
|
+
lookAt: [0, 0, 0]
|
|
195766
|
+
});
|
|
195767
|
+
fs30.mkdirSync(outputDir, { recursive: true });
|
|
195768
|
+
fs30.writeFileSync(path29.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
|
|
195769
|
+
console.log(`${prefix}Written pcb.svg`);
|
|
195770
|
+
fs30.writeFileSync(path29.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
|
|
195771
|
+
console.log(`${prefix}Written schematic.svg`);
|
|
195772
|
+
fs30.writeFileSync(path29.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
|
|
195773
|
+
console.log(`${prefix}Written 3d.png`);
|
|
195774
|
+
} catch (error) {
|
|
195775
|
+
console.error(`${prefix}Failed to generate preview images:`, error);
|
|
195776
|
+
}
|
|
195777
|
+
};
|
|
195697
195778
|
var buildPreviewImages = async ({
|
|
195698
195779
|
builtFiles,
|
|
195699
195780
|
distDir,
|
|
195700
|
-
mainEntrypoint
|
|
195781
|
+
mainEntrypoint,
|
|
195782
|
+
allImages
|
|
195701
195783
|
}) => {
|
|
195702
195784
|
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
195703
195785
|
const normalizedMainEntrypoint = mainEntrypoint ? path29.resolve(mainEntrypoint) : undefined;
|
|
195786
|
+
if (allImages) {
|
|
195787
|
+
if (successfulBuilds.length === 0) {
|
|
195788
|
+
console.warn("No successful build output available for preview image generation.");
|
|
195789
|
+
return;
|
|
195790
|
+
}
|
|
195791
|
+
for (const build of successfulBuilds) {
|
|
195792
|
+
const outputDir = path29.dirname(build.outputPath);
|
|
195793
|
+
await generatePreviewAssets({
|
|
195794
|
+
build,
|
|
195795
|
+
outputDir,
|
|
195796
|
+
distDir
|
|
195797
|
+
});
|
|
195798
|
+
}
|
|
195799
|
+
return;
|
|
195800
|
+
}
|
|
195704
195801
|
const previewBuild = (() => {
|
|
195705
195802
|
if (normalizedMainEntrypoint) {
|
|
195706
195803
|
const match = successfulBuilds.find((built) => path29.resolve(built.sourcePath) === normalizedMainEntrypoint);
|
|
@@ -195713,108 +195810,93 @@ var buildPreviewImages = async ({
|
|
|
195713
195810
|
console.warn("No successful build output available for preview image generation.");
|
|
195714
195811
|
return;
|
|
195715
195812
|
}
|
|
195716
|
-
|
|
195717
|
-
|
|
195718
|
-
|
|
195719
|
-
|
|
195720
|
-
|
|
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
|
-
}
|
|
195813
|
+
await generatePreviewAssets({
|
|
195814
|
+
build: previewBuild,
|
|
195815
|
+
outputDir: distDir,
|
|
195816
|
+
distDir
|
|
195817
|
+
});
|
|
195744
195818
|
};
|
|
195745
195819
|
|
|
195746
195820
|
// cli/build/register.ts
|
|
195747
195821
|
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) => {
|
|
195749
|
-
|
|
195750
|
-
|
|
195751
|
-
|
|
195752
|
-
|
|
195753
|
-
|
|
195754
|
-
|
|
195755
|
-
|
|
195756
|
-
|
|
195757
|
-
|
|
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) => {
|
|
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
|
+
}
|
|
195758
195871
|
}
|
|
195759
|
-
if (options?.
|
|
195760
|
-
|
|
195872
|
+
if (hasErrors && !options?.ignoreErrors) {
|
|
195873
|
+
process.exit(1);
|
|
195761
195874
|
}
|
|
195762
|
-
|
|
195763
|
-
|
|
195764
|
-
|
|
195765
|
-
|
|
195766
|
-
|
|
195767
|
-
|
|
195768
|
-
|
|
195769
|
-
|
|
195770
|
-
for (const filePath of circuitFiles) {
|
|
195771
|
-
const relative9 = path30.relative(projectDir, filePath);
|
|
195772
|
-
console.log(`Building ${relative9}...`);
|
|
195773
|
-
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
195774
|
-
const outputPath = path30.join(distDir, outputDirName, "circuit.json");
|
|
195775
|
-
const ok = await buildFile(filePath, outputPath, projectDir, {
|
|
195776
|
-
ignoreErrors: options?.ignoreErrors,
|
|
195777
|
-
ignoreWarnings: options?.ignoreWarnings,
|
|
195778
|
-
platformConfig: platformConfig2
|
|
195779
|
-
});
|
|
195780
|
-
builtFiles.push({
|
|
195781
|
-
sourcePath: filePath,
|
|
195782
|
-
outputPath,
|
|
195783
|
-
ok
|
|
195784
|
-
});
|
|
195785
|
-
if (!ok) {
|
|
195786
|
-
hasErrors = true;
|
|
195787
|
-
} else if (options?.site) {
|
|
195788
|
-
const normalizedSourcePath = relative9.split(path30.sep).join("/");
|
|
195789
|
-
const relativeOutputPath = path30.join(outputDirName, "circuit.json");
|
|
195790
|
-
const normalizedOutputPath = relativeOutputPath.split(path30.sep).join("/");
|
|
195791
|
-
staticFileReferences.push({
|
|
195792
|
-
filePath: normalizedSourcePath,
|
|
195793
|
-
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
|
|
195794
195883
|
});
|
|
195795
195884
|
}
|
|
195796
|
-
|
|
195797
|
-
|
|
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);
|
|
195798
195898
|
process.exit(1);
|
|
195799
195899
|
}
|
|
195800
|
-
if (options?.previewImages) {
|
|
195801
|
-
console.log("Generating preview images...");
|
|
195802
|
-
await buildPreviewImages({
|
|
195803
|
-
builtFiles,
|
|
195804
|
-
distDir,
|
|
195805
|
-
mainEntrypoint
|
|
195806
|
-
});
|
|
195807
|
-
}
|
|
195808
|
-
if (options?.site) {
|
|
195809
|
-
const indexHtml = getStaticIndexHtmlFile({
|
|
195810
|
-
files: staticFileReferences,
|
|
195811
|
-
standaloneScriptSrc: "./standalone.min.js"
|
|
195812
|
-
});
|
|
195813
|
-
fs31.writeFileSync(path30.join(distDir, "index.html"), indexHtml);
|
|
195814
|
-
fs31.writeFileSync(path30.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
195815
|
-
}
|
|
195816
|
-
console.log("Build complete!");
|
|
195817
|
-
process.exit(0);
|
|
195818
195900
|
});
|
|
195819
195901
|
};
|
|
195820
195902
|
|