@tscircuit/cli 0.1.691 → 0.1.692
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 +229 -166
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -74113,7 +74113,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
74113
74113
|
import { execSync as execSync2 } from "node:child_process";
|
|
74114
74114
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
74115
74115
|
// package.json
|
|
74116
|
-
var version = "0.1.
|
|
74116
|
+
var version = "0.1.691";
|
|
74117
74117
|
var package_default = {
|
|
74118
74118
|
name: "@tscircuit/cli",
|
|
74119
74119
|
version,
|
|
@@ -74139,7 +74139,7 @@ var package_default = {
|
|
|
74139
74139
|
"bun-match-svg": "^0.0.12",
|
|
74140
74140
|
chokidar: "4.0.1",
|
|
74141
74141
|
"circuit-json": "0.0.325",
|
|
74142
|
-
"circuit-json-to-gltf": "^0.0.
|
|
74142
|
+
"circuit-json-to-gltf": "^0.0.58",
|
|
74143
74143
|
"circuit-json-to-kicad": "^0.0.31",
|
|
74144
74144
|
"circuit-json-to-readable-netlist": "^0.0.13",
|
|
74145
74145
|
"circuit-json-to-spice": "^0.0.10",
|
|
@@ -187379,8 +187379,8 @@ var registerRemove = (program3) => {
|
|
|
187379
187379
|
};
|
|
187380
187380
|
|
|
187381
187381
|
// cli/build/register.ts
|
|
187382
|
-
import
|
|
187383
|
-
import
|
|
187382
|
+
import path42 from "node:path";
|
|
187383
|
+
import fs41 from "node:fs";
|
|
187384
187384
|
|
|
187385
187385
|
// cli/build/build-file.ts
|
|
187386
187386
|
import path34 from "node:path";
|
|
@@ -187656,13 +187656,43 @@ ${scriptBlock} <script src="https://cdn.tailwindcss.com"></script>
|
|
|
187656
187656
|
// cli/build/build-preview-images.ts
|
|
187657
187657
|
import fs35 from "node:fs";
|
|
187658
187658
|
import path36 from "node:path";
|
|
187659
|
-
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
187660
187659
|
import {
|
|
187661
187660
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg2,
|
|
187662
187661
|
convertCircuitJsonToSchematicSvg as convertCircuitJsonToSchematicSvg2
|
|
187663
187662
|
} from "circuit-to-svg";
|
|
187664
187663
|
import { renderGLTFToPNGBufferFromGLBBuffer } from "poppygl";
|
|
187665
187664
|
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf2 } from "circuit-json-to-gltf";
|
|
187665
|
+
|
|
187666
|
+
// cli/build/convert-model-urls-to-file-urls.ts
|
|
187667
|
+
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
187668
|
+
var convertModelUrlsToFileUrls = (circuitJson) => {
|
|
187669
|
+
const modelUrlKeys = [
|
|
187670
|
+
"model_glb_url",
|
|
187671
|
+
"glb_model_url",
|
|
187672
|
+
"model_stl_url",
|
|
187673
|
+
"stl_model_url",
|
|
187674
|
+
"model_obj_url",
|
|
187675
|
+
"obj_model_url",
|
|
187676
|
+
"model_gltf_url",
|
|
187677
|
+
"gltf_model_url"
|
|
187678
|
+
];
|
|
187679
|
+
return circuitJson.map((element) => {
|
|
187680
|
+
if (!element || typeof element !== "object")
|
|
187681
|
+
return element;
|
|
187682
|
+
const updated = { ...element };
|
|
187683
|
+
for (const key of modelUrlKeys) {
|
|
187684
|
+
const value = updated[key];
|
|
187685
|
+
if (typeof value === "string" && value.length > 0) {
|
|
187686
|
+
if (!value.match(/^[a-zA-Z]+:\/\//) && (value.startsWith("/") || value.match(/^[a-zA-Z]:\\/))) {
|
|
187687
|
+
updated[key] = pathToFileURL2(value).href;
|
|
187688
|
+
}
|
|
187689
|
+
}
|
|
187690
|
+
}
|
|
187691
|
+
return updated;
|
|
187692
|
+
});
|
|
187693
|
+
};
|
|
187694
|
+
|
|
187695
|
+
// cli/build/build-preview-images.ts
|
|
187666
187696
|
var viewToArrayBuffer = (view) => {
|
|
187667
187697
|
const copy = new Uint8Array(view.byteLength);
|
|
187668
187698
|
copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
@@ -187696,33 +187726,6 @@ var normalizeToUint8Array = (value) => {
|
|
|
187696
187726
|
}
|
|
187697
187727
|
throw new Error("Expected Uint8Array, ArrayBuffer, or ArrayBufferView for PNG");
|
|
187698
187728
|
};
|
|
187699
|
-
var convertModelUrlsToFileUrls = (circuitJson) => {
|
|
187700
|
-
const modelUrlKeys = [
|
|
187701
|
-
"model_glb_url",
|
|
187702
|
-
"glb_model_url",
|
|
187703
|
-
"model_stl_url",
|
|
187704
|
-
"stl_model_url",
|
|
187705
|
-
"model_obj_url",
|
|
187706
|
-
"obj_model_url",
|
|
187707
|
-
"model_gltf_url",
|
|
187708
|
-
"gltf_model_url"
|
|
187709
|
-
];
|
|
187710
|
-
return circuitJson.map((element) => {
|
|
187711
|
-
if (!element || typeof element !== "object")
|
|
187712
|
-
return element;
|
|
187713
|
-
const updated = { ...element };
|
|
187714
|
-
for (const key of modelUrlKeys) {
|
|
187715
|
-
const value = updated[key];
|
|
187716
|
-
if (typeof value === "string" && value.length > 0) {
|
|
187717
|
-
console.log("value", value);
|
|
187718
|
-
if (!value.match(/^[a-zA-Z]+:\/\//) && (value.startsWith("/") || value.match(/^[a-zA-Z]:\\/))) {
|
|
187719
|
-
updated[key] = pathToFileURL2(value).href;
|
|
187720
|
-
}
|
|
187721
|
-
}
|
|
187722
|
-
}
|
|
187723
|
-
return updated;
|
|
187724
|
-
});
|
|
187725
|
-
};
|
|
187726
187729
|
var generatePreviewAssets = async ({
|
|
187727
187730
|
build,
|
|
187728
187731
|
outputDir,
|
|
@@ -187817,9 +187820,60 @@ var buildPreviewImages = async ({
|
|
|
187817
187820
|
});
|
|
187818
187821
|
};
|
|
187819
187822
|
|
|
187820
|
-
// cli/build/
|
|
187823
|
+
// cli/build/build-preview-gltf.ts
|
|
187821
187824
|
import fs36 from "node:fs";
|
|
187822
187825
|
import path37 from "node:path";
|
|
187826
|
+
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf3 } from "circuit-json-to-gltf";
|
|
187827
|
+
var buildPreviewGltf = async ({
|
|
187828
|
+
builtFiles,
|
|
187829
|
+
distDir,
|
|
187830
|
+
mainEntrypoint,
|
|
187831
|
+
previewComponentPath
|
|
187832
|
+
}) => {
|
|
187833
|
+
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
187834
|
+
const previewEntrypoint = previewComponentPath || mainEntrypoint;
|
|
187835
|
+
const resolvedPreviewEntrypoint = previewEntrypoint ? path37.resolve(previewEntrypoint) : undefined;
|
|
187836
|
+
const previewBuild = (() => {
|
|
187837
|
+
if (resolvedPreviewEntrypoint) {
|
|
187838
|
+
const match = successfulBuilds.find((built) => path37.resolve(built.sourcePath) === resolvedPreviewEntrypoint);
|
|
187839
|
+
if (match)
|
|
187840
|
+
return match;
|
|
187841
|
+
}
|
|
187842
|
+
return successfulBuilds[0];
|
|
187843
|
+
})();
|
|
187844
|
+
if (!previewBuild) {
|
|
187845
|
+
console.warn("No successful build output available for preview GLTF generation.");
|
|
187846
|
+
return;
|
|
187847
|
+
}
|
|
187848
|
+
let circuitJson;
|
|
187849
|
+
try {
|
|
187850
|
+
const circuitJsonRaw = fs36.readFileSync(previewBuild.outputPath, "utf-8");
|
|
187851
|
+
circuitJson = JSON.parse(circuitJsonRaw);
|
|
187852
|
+
} catch (error) {
|
|
187853
|
+
console.error("Failed to read circuit JSON:", error);
|
|
187854
|
+
return;
|
|
187855
|
+
}
|
|
187856
|
+
const sourcePath = previewBuild.sourcePath;
|
|
187857
|
+
const sourceBasename = path37.basename(sourcePath);
|
|
187858
|
+
const gltfFilename = sourceBasename.replace(/(\.(board|circuit))?\.tsx?$/, ".gltf");
|
|
187859
|
+
const outputPath = path37.join(distDir, gltfFilename);
|
|
187860
|
+
try {
|
|
187861
|
+
console.log("Converting circuit to GLTF...");
|
|
187862
|
+
const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
|
|
187863
|
+
const gltfData = await convertCircuitJsonToGltf3(circuitJsonWithFileUrls, {
|
|
187864
|
+
format: "gltf"
|
|
187865
|
+
});
|
|
187866
|
+
const gltfContent = JSON.stringify(gltfData, null, 2);
|
|
187867
|
+
fs36.writeFileSync(outputPath, gltfContent, "utf-8");
|
|
187868
|
+
console.log(`Written ${gltfFilename}`);
|
|
187869
|
+
} catch (error) {
|
|
187870
|
+
console.error("Failed to generate GLTF:", error);
|
|
187871
|
+
}
|
|
187872
|
+
};
|
|
187873
|
+
|
|
187874
|
+
// cli/build/generate-kicad-project.ts
|
|
187875
|
+
import fs37 from "node:fs";
|
|
187876
|
+
import path38 from "node:path";
|
|
187823
187877
|
var createKicadProContent = ({
|
|
187824
187878
|
projectName,
|
|
187825
187879
|
schematicFileName,
|
|
@@ -187859,10 +187913,10 @@ var generateKicadProject = async ({
|
|
|
187859
187913
|
boardFileName
|
|
187860
187914
|
});
|
|
187861
187915
|
if (writeFiles) {
|
|
187862
|
-
|
|
187863
|
-
|
|
187864
|
-
|
|
187865
|
-
|
|
187916
|
+
fs37.mkdirSync(outputDir, { recursive: true });
|
|
187917
|
+
fs37.writeFileSync(path38.join(outputDir, schematicFileName), schContent);
|
|
187918
|
+
fs37.writeFileSync(path38.join(outputDir, boardFileName), pcbContent);
|
|
187919
|
+
fs37.writeFileSync(path38.join(outputDir, projectFileName), proContent);
|
|
187866
187920
|
}
|
|
187867
187921
|
return {
|
|
187868
187922
|
pcbContent,
|
|
@@ -187874,8 +187928,8 @@ var generateKicadProject = async ({
|
|
|
187874
187928
|
};
|
|
187875
187929
|
|
|
187876
187930
|
// cli/build/transpile/index.ts
|
|
187877
|
-
import
|
|
187878
|
-
import
|
|
187931
|
+
import path40 from "node:path";
|
|
187932
|
+
import fs39 from "node:fs";
|
|
187879
187933
|
import { rollup } from "rollup";
|
|
187880
187934
|
import typescript from "@rollup/plugin-typescript";
|
|
187881
187935
|
import resolve11 from "@rollup/plugin-node-resolve";
|
|
@@ -187884,11 +187938,11 @@ import json from "@rollup/plugin-json";
|
|
|
187884
187938
|
import dts from "rollup-plugin-dts";
|
|
187885
187939
|
|
|
187886
187940
|
// cli/build/transpile/static-asset-plugin.ts
|
|
187887
|
-
import
|
|
187888
|
-
import
|
|
187941
|
+
import fs38 from "node:fs";
|
|
187942
|
+
import path39 from "node:path";
|
|
187889
187943
|
import { createHash } from "node:crypto";
|
|
187890
187944
|
function normalizePathSeparators(filePath) {
|
|
187891
|
-
return filePath.split(
|
|
187945
|
+
return filePath.split(path39.sep).join("/");
|
|
187892
187946
|
}
|
|
187893
187947
|
var STATIC_ASSET_EXTENSIONS = new Set([
|
|
187894
187948
|
".glb",
|
|
@@ -187919,24 +187973,24 @@ var createStaticAssetPlugin = ({
|
|
|
187919
187973
|
return {
|
|
187920
187974
|
name: "tsci-static-assets",
|
|
187921
187975
|
resolveId(source, importer) {
|
|
187922
|
-
const ext =
|
|
187976
|
+
const ext = path39.extname(source).toLowerCase();
|
|
187923
187977
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
187924
187978
|
return null;
|
|
187925
|
-
if (
|
|
187926
|
-
return
|
|
187979
|
+
if (path39.isAbsolute(source)) {
|
|
187980
|
+
return fs38.existsSync(source) ? { id: normalizePathSeparators(source), external: true } : null;
|
|
187927
187981
|
}
|
|
187928
187982
|
if (importer) {
|
|
187929
|
-
const importerNative = importer.split("/").join(
|
|
187930
|
-
const resolvedFromImporter =
|
|
187931
|
-
if (
|
|
187983
|
+
const importerNative = importer.split("/").join(path39.sep);
|
|
187984
|
+
const resolvedFromImporter = path39.resolve(path39.dirname(importerNative), source);
|
|
187985
|
+
if (fs38.existsSync(resolvedFromImporter)) {
|
|
187932
187986
|
return {
|
|
187933
187987
|
id: normalizePathSeparators(resolvedFromImporter),
|
|
187934
187988
|
external: true
|
|
187935
187989
|
};
|
|
187936
187990
|
}
|
|
187937
187991
|
}
|
|
187938
|
-
const resolvedFromProject =
|
|
187939
|
-
if (
|
|
187992
|
+
const resolvedFromProject = path39.resolve(resolvedBaseUrl, source);
|
|
187993
|
+
if (fs38.existsSync(resolvedFromProject)) {
|
|
187940
187994
|
return {
|
|
187941
187995
|
id: normalizePathSeparators(resolvedFromProject),
|
|
187942
187996
|
external: true
|
|
@@ -187949,8 +188003,8 @@ var createStaticAssetPlugin = ({
|
|
|
187949
188003
|
const wildcard = isWildcard ? source.slice(patternPrefix.length) : "";
|
|
187950
188004
|
for (const target of targets) {
|
|
187951
188005
|
const targetPath = isWildcard ? target.replace("*", wildcard) : target;
|
|
187952
|
-
const resolvedTarget =
|
|
187953
|
-
if (
|
|
188006
|
+
const resolvedTarget = path39.resolve(resolvedBaseUrl, targetPath);
|
|
188007
|
+
if (fs38.existsSync(resolvedTarget)) {
|
|
187954
188008
|
return {
|
|
187955
188009
|
id: normalizePathSeparators(resolvedTarget),
|
|
187956
188010
|
external: true
|
|
@@ -187976,18 +188030,18 @@ var createStaticAssetPlugin = ({
|
|
|
187976
188030
|
if (chunk.type !== "chunk")
|
|
187977
188031
|
continue;
|
|
187978
188032
|
for (const importedId of chunk.imports) {
|
|
187979
|
-
const ext =
|
|
188033
|
+
const ext = path39.extname(importedId).toLowerCase();
|
|
187980
188034
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
187981
188035
|
continue;
|
|
187982
188036
|
if (!copiedAssets.has(importedId)) {
|
|
187983
|
-
const assetDir =
|
|
187984
|
-
|
|
187985
|
-
const nativePath = importedId.split("/").join(
|
|
187986
|
-
const fileBuffer =
|
|
188037
|
+
const assetDir = path39.join(outputDir, "assets");
|
|
188038
|
+
fs38.mkdirSync(assetDir, { recursive: true });
|
|
188039
|
+
const nativePath = importedId.split("/").join(path39.sep);
|
|
188040
|
+
const fileBuffer = fs38.readFileSync(nativePath);
|
|
187987
188041
|
const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
|
|
187988
|
-
const fileName = `${
|
|
187989
|
-
const outputFilePath =
|
|
187990
|
-
|
|
188042
|
+
const fileName = `${path39.basename(importedId, ext)}-${hash}${ext}`;
|
|
188043
|
+
const outputFilePath = path39.join(assetDir, fileName);
|
|
188044
|
+
fs38.writeFileSync(outputFilePath, fileBuffer);
|
|
187991
188045
|
copiedAssets.set(importedId, `./assets/${fileName}`);
|
|
187992
188046
|
assetIdToOutputPath.set(importedId, `./assets/${fileName}`);
|
|
187993
188047
|
}
|
|
@@ -188009,17 +188063,17 @@ function escapeRegExp(string) {
|
|
|
188009
188063
|
|
|
188010
188064
|
// cli/build/transpile/index.ts
|
|
188011
188065
|
var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
|
|
188012
|
-
if (id2.startsWith(".") || id2.startsWith("/") ||
|
|
188066
|
+
if (id2.startsWith(".") || id2.startsWith("/") || path40.isAbsolute(id2)) {
|
|
188013
188067
|
return false;
|
|
188014
188068
|
}
|
|
188015
188069
|
let baseUrl = projectDir;
|
|
188016
188070
|
let pathMappings = {};
|
|
188017
|
-
if (tsconfigPath &&
|
|
188071
|
+
if (tsconfigPath && fs39.existsSync(tsconfigPath)) {
|
|
188018
188072
|
try {
|
|
188019
|
-
const tsconfigContent =
|
|
188073
|
+
const tsconfigContent = fs39.readFileSync(tsconfigPath, "utf-8");
|
|
188020
188074
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
188021
188075
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
188022
|
-
baseUrl =
|
|
188076
|
+
baseUrl = path40.resolve(path40.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
188023
188077
|
}
|
|
188024
188078
|
if (tsconfig.compilerOptions?.paths) {
|
|
188025
188079
|
pathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -188033,17 +188087,17 @@ var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
|
|
|
188033
188087
|
}
|
|
188034
188088
|
}
|
|
188035
188089
|
const potentialPaths = [
|
|
188036
|
-
|
|
188037
|
-
|
|
188038
|
-
|
|
188039
|
-
|
|
188040
|
-
|
|
188041
|
-
|
|
188042
|
-
|
|
188043
|
-
|
|
188044
|
-
|
|
188090
|
+
path40.join(baseUrl, id2),
|
|
188091
|
+
path40.join(baseUrl, `${id2}.ts`),
|
|
188092
|
+
path40.join(baseUrl, `${id2}.tsx`),
|
|
188093
|
+
path40.join(baseUrl, `${id2}.js`),
|
|
188094
|
+
path40.join(baseUrl, `${id2}.jsx`),
|
|
188095
|
+
path40.join(baseUrl, id2, "index.ts"),
|
|
188096
|
+
path40.join(baseUrl, id2, "index.tsx"),
|
|
188097
|
+
path40.join(baseUrl, id2, "index.js"),
|
|
188098
|
+
path40.join(baseUrl, id2, "index.jsx")
|
|
188045
188099
|
];
|
|
188046
|
-
if (potentialPaths.some((p) =>
|
|
188100
|
+
if (potentialPaths.some((p) => fs39.existsSync(p))) {
|
|
188047
188101
|
return false;
|
|
188048
188102
|
}
|
|
188049
188103
|
return true;
|
|
@@ -188054,17 +188108,17 @@ var transpileFile = async ({
|
|
|
188054
188108
|
projectDir
|
|
188055
188109
|
}) => {
|
|
188056
188110
|
try {
|
|
188057
|
-
|
|
188058
|
-
const tsconfigPath =
|
|
188059
|
-
const hasTsConfig =
|
|
188111
|
+
fs39.mkdirSync(outputDir, { recursive: true });
|
|
188112
|
+
const tsconfigPath = path40.join(projectDir, "tsconfig.json");
|
|
188113
|
+
const hasTsConfig = fs39.existsSync(tsconfigPath);
|
|
188060
188114
|
let tsconfigBaseUrl = projectDir;
|
|
188061
188115
|
let tsconfigPathMappings;
|
|
188062
188116
|
if (hasTsConfig) {
|
|
188063
188117
|
try {
|
|
188064
|
-
const tsconfigContent =
|
|
188118
|
+
const tsconfigContent = fs39.readFileSync(tsconfigPath, "utf-8");
|
|
188065
188119
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
188066
188120
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
188067
|
-
tsconfigBaseUrl =
|
|
188121
|
+
tsconfigBaseUrl = path40.resolve(path40.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
188068
188122
|
}
|
|
188069
188123
|
if (tsconfig.compilerOptions?.paths) {
|
|
188070
188124
|
tsconfigPathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -188119,27 +188173,27 @@ var transpileFile = async ({
|
|
|
188119
188173
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
188120
188174
|
plugins: getPlugins()
|
|
188121
188175
|
});
|
|
188122
|
-
const esmOutputPath =
|
|
188176
|
+
const esmOutputPath = path40.join(outputDir, "index.js");
|
|
188123
188177
|
await esmBundle.write({
|
|
188124
188178
|
file: esmOutputPath,
|
|
188125
188179
|
format: "es",
|
|
188126
188180
|
sourcemap: false
|
|
188127
188181
|
});
|
|
188128
|
-
console.log(`ESM bundle written to ${
|
|
188182
|
+
console.log(`ESM bundle written to ${path40.relative(projectDir, esmOutputPath)}`);
|
|
188129
188183
|
console.log("Building CommonJS bundle...");
|
|
188130
188184
|
const cjsBundle = await rollup({
|
|
188131
188185
|
input,
|
|
188132
188186
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
188133
188187
|
plugins: getPlugins()
|
|
188134
188188
|
});
|
|
188135
|
-
const cjsOutputPath =
|
|
188189
|
+
const cjsOutputPath = path40.join(outputDir, "index.cjs");
|
|
188136
188190
|
console.log("Writing CJS bundle to:", cjsOutputPath);
|
|
188137
188191
|
await cjsBundle.write({
|
|
188138
188192
|
file: cjsOutputPath,
|
|
188139
188193
|
format: "cjs",
|
|
188140
188194
|
sourcemap: false
|
|
188141
188195
|
});
|
|
188142
|
-
console.log(`CommonJS bundle written to ${
|
|
188196
|
+
console.log(`CommonJS bundle written to ${path40.relative(projectDir, cjsOutputPath)}`);
|
|
188143
188197
|
console.log("Generating type declarations...");
|
|
188144
188198
|
const dtsBundle = await rollup({
|
|
188145
188199
|
input,
|
|
@@ -188164,9 +188218,9 @@ var transpileFile = async ({
|
|
|
188164
188218
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
188165
188219
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
188166
188220
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
188167
|
-
const dtsOutputPath =
|
|
188168
|
-
|
|
188169
|
-
console.log(`Type declarations written to ${
|
|
188221
|
+
const dtsOutputPath = path40.join(outputDir, "index.d.ts");
|
|
188222
|
+
fs39.writeFileSync(dtsOutputPath, dtsContent);
|
|
188223
|
+
console.log(`Type declarations written to ${path40.relative(projectDir, dtsOutputPath)}`);
|
|
188170
188224
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
188171
188225
|
return true;
|
|
188172
188226
|
} catch (err) {
|
|
@@ -188179,17 +188233,17 @@ var transpileFile = async ({
|
|
|
188179
188233
|
};
|
|
188180
188234
|
|
|
188181
188235
|
// cli/utils/validate-main-in-dist.ts
|
|
188182
|
-
import
|
|
188183
|
-
import
|
|
188236
|
+
import fs40 from "node:fs";
|
|
188237
|
+
import path41 from "node:path";
|
|
188184
188238
|
var validateMainInDist = (projectDir, distDir) => {
|
|
188185
|
-
const packageJsonPath =
|
|
188186
|
-
if (!
|
|
188239
|
+
const packageJsonPath = path41.join(projectDir, "package.json");
|
|
188240
|
+
if (!fs40.existsSync(packageJsonPath))
|
|
188187
188241
|
return;
|
|
188188
|
-
const packageJson = JSON.parse(
|
|
188242
|
+
const packageJson = JSON.parse(fs40.readFileSync(packageJsonPath, "utf-8"));
|
|
188189
188243
|
if (typeof packageJson.main !== "string")
|
|
188190
188244
|
return;
|
|
188191
|
-
const resolvedMainPath =
|
|
188192
|
-
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${
|
|
188245
|
+
const resolvedMainPath = path41.resolve(projectDir, packageJson.main);
|
|
188246
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path41.sep}`);
|
|
188193
188247
|
if (!isMainInDist) {
|
|
188194
188248
|
console.warn('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
188195
188249
|
}
|
|
@@ -188197,7 +188251,7 @@ var validateMainInDist = (projectDir, distDir) => {
|
|
|
188197
188251
|
|
|
188198
188252
|
// cli/build/register.ts
|
|
188199
188253
|
var registerBuild = (program3) => {
|
|
188200
|
-
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("--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", "Generate KiCad project directories for each successful build output").option("--kicad-footprint-library", "Generate a KiCad footprint library from all successful build outputs").action(async (file, options) => {
|
|
188254
|
+
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("--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", "Generate KiCad project directories for each successful build output").option("--kicad-footprint-library", "Generate a KiCad footprint library from all successful build outputs").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").action(async (file, options) => {
|
|
188201
188255
|
try {
|
|
188202
188256
|
const {
|
|
188203
188257
|
projectDir,
|
|
@@ -188219,8 +188273,8 @@ var registerBuild = (program3) => {
|
|
|
188219
188273
|
}
|
|
188220
188274
|
return config;
|
|
188221
188275
|
})();
|
|
188222
|
-
const distDir =
|
|
188223
|
-
|
|
188276
|
+
const distDir = path42.join(projectDir, "dist");
|
|
188277
|
+
fs41.mkdirSync(distDir, { recursive: true });
|
|
188224
188278
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
188225
188279
|
let hasErrors = false;
|
|
188226
188280
|
const staticFileReferences = [];
|
|
@@ -188228,10 +188282,10 @@ var registerBuild = (program3) => {
|
|
|
188228
188282
|
const kicadProjects = [];
|
|
188229
188283
|
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
188230
188284
|
for (const filePath of circuitFiles) {
|
|
188231
|
-
const relative9 =
|
|
188285
|
+
const relative9 = path42.relative(projectDir, filePath);
|
|
188232
188286
|
console.log(`Building ${relative9}...`);
|
|
188233
188287
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
188234
|
-
const outputPath =
|
|
188288
|
+
const outputPath = path42.join(distDir, outputDirName, "circuit.json");
|
|
188235
188289
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
188236
188290
|
ignoreErrors: options?.ignoreErrors,
|
|
188237
188291
|
ignoreWarnings: options?.ignoreWarnings,
|
|
@@ -188245,17 +188299,17 @@ var registerBuild = (program3) => {
|
|
|
188245
188299
|
if (!buildOutcome.ok) {
|
|
188246
188300
|
hasErrors = true;
|
|
188247
188301
|
} else if (options?.site) {
|
|
188248
|
-
const normalizedSourcePath = relative9.split(
|
|
188249
|
-
const relativeOutputPath =
|
|
188250
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
188302
|
+
const normalizedSourcePath = relative9.split(path42.sep).join("/");
|
|
188303
|
+
const relativeOutputPath = path42.join(outputDirName, "circuit.json");
|
|
188304
|
+
const normalizedOutputPath = relativeOutputPath.split(path42.sep).join("/");
|
|
188251
188305
|
staticFileReferences.push({
|
|
188252
188306
|
filePath: normalizedSourcePath,
|
|
188253
188307
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
188254
188308
|
});
|
|
188255
188309
|
}
|
|
188256
188310
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
188257
|
-
const projectOutputDir =
|
|
188258
|
-
const projectName =
|
|
188311
|
+
const projectOutputDir = path42.join(distDir, outputDirName, "kicad");
|
|
188312
|
+
const projectName = path42.basename(outputDirName);
|
|
188259
188313
|
const project = await generateKicadProject({
|
|
188260
188314
|
circuitJson: buildOutcome.circuitJson,
|
|
188261
188315
|
outputDir: projectOutputDir,
|
|
@@ -188282,6 +188336,15 @@ var registerBuild = (program3) => {
|
|
|
188282
188336
|
allImages: options?.allImages
|
|
188283
188337
|
});
|
|
188284
188338
|
}
|
|
188339
|
+
if (options?.previewGltf) {
|
|
188340
|
+
console.log("Generating preview GLTF...");
|
|
188341
|
+
await buildPreviewGltf({
|
|
188342
|
+
builtFiles,
|
|
188343
|
+
distDir,
|
|
188344
|
+
mainEntrypoint,
|
|
188345
|
+
previewComponentPath
|
|
188346
|
+
});
|
|
188347
|
+
}
|
|
188285
188348
|
if (options?.transpile) {
|
|
188286
188349
|
validateMainInDist(projectDir, distDir);
|
|
188287
188350
|
console.log("Transpiling entry file...");
|
|
@@ -188309,8 +188372,8 @@ var registerBuild = (program3) => {
|
|
|
188309
188372
|
files: staticFileReferences,
|
|
188310
188373
|
standaloneScriptSrc: "./standalone.min.js"
|
|
188311
188374
|
});
|
|
188312
|
-
|
|
188313
|
-
|
|
188375
|
+
fs41.writeFileSync(path42.join(distDir, "index.html"), indexHtml);
|
|
188376
|
+
fs41.writeFileSync(path42.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
188314
188377
|
}
|
|
188315
188378
|
if (options?.kicadFootprintLibrary) {
|
|
188316
188379
|
if (kicadProjects.length === 0) {
|
|
@@ -188333,19 +188396,19 @@ var registerBuild = (program3) => {
|
|
|
188333
188396
|
};
|
|
188334
188397
|
|
|
188335
188398
|
// lib/shared/snapshot-project.ts
|
|
188336
|
-
import
|
|
188337
|
-
import
|
|
188399
|
+
import fs43 from "node:fs";
|
|
188400
|
+
import path43 from "node:path";
|
|
188338
188401
|
import looksSame2 from "looks-same";
|
|
188339
188402
|
import {
|
|
188340
188403
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
188341
188404
|
convertCircuitJsonToSchematicSvg as convertCircuitJsonToSchematicSvg3
|
|
188342
188405
|
} from "circuit-to-svg";
|
|
188343
|
-
import { convertCircuitJsonToGltf as
|
|
188406
|
+
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf4 } from "circuit-json-to-gltf";
|
|
188344
188407
|
import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffer2 } from "poppygl";
|
|
188345
188408
|
|
|
188346
188409
|
// lib/shared/compare-images.ts
|
|
188347
188410
|
import looksSame from "looks-same";
|
|
188348
|
-
import
|
|
188411
|
+
import fs42 from "node:fs/promises";
|
|
188349
188412
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
188350
188413
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
188351
188414
|
strict: false,
|
|
@@ -188361,7 +188424,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
188361
188424
|
tolerance: 2
|
|
188362
188425
|
});
|
|
188363
188426
|
} else {
|
|
188364
|
-
await
|
|
188427
|
+
await fs42.writeFile(diffPath, buffer2);
|
|
188365
188428
|
}
|
|
188366
188429
|
}
|
|
188367
188430
|
return { equal: equal2 };
|
|
@@ -188386,7 +188449,7 @@ var snapshotProject = async ({
|
|
|
188386
188449
|
...DEFAULT_IGNORED_PATTERNS,
|
|
188387
188450
|
...ignored.map(normalizeIgnorePattern)
|
|
188388
188451
|
];
|
|
188389
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
188452
|
+
const resolvedPaths = filePaths.map((f) => path43.resolve(projectDir, f));
|
|
188390
188453
|
const boardFiles = findBoardFiles({
|
|
188391
188454
|
projectDir,
|
|
188392
188455
|
ignore,
|
|
@@ -188400,7 +188463,7 @@ var snapshotProject = async ({
|
|
|
188400
188463
|
const mismatches = [];
|
|
188401
188464
|
let didUpdate = false;
|
|
188402
188465
|
for (const file of boardFiles) {
|
|
188403
|
-
const relativeFilePath =
|
|
188466
|
+
const relativeFilePath = path43.relative(projectDir, file);
|
|
188404
188467
|
let circuitJson;
|
|
188405
188468
|
let pcbSvg;
|
|
188406
188469
|
let schSvg;
|
|
@@ -188442,7 +188505,7 @@ var snapshotProject = async ({
|
|
|
188442
188505
|
let png3d = null;
|
|
188443
188506
|
if (threeD) {
|
|
188444
188507
|
try {
|
|
188445
|
-
const glbBuffer = await
|
|
188508
|
+
const glbBuffer = await convertCircuitJsonToGltf4(circuitJson, {
|
|
188446
188509
|
format: "glb"
|
|
188447
188510
|
});
|
|
188448
188511
|
if (!(glbBuffer instanceof ArrayBuffer)) {
|
|
@@ -188455,17 +188518,17 @@ var snapshotProject = async ({
|
|
|
188455
188518
|
} catch (error) {
|
|
188456
188519
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
188457
188520
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
188458
|
-
const fileDir =
|
|
188459
|
-
const relativeDir =
|
|
188460
|
-
const snapDir2 = snapshotsDirName ?
|
|
188461
|
-
const base2 =
|
|
188462
|
-
const snap3dPath =
|
|
188463
|
-
const existing3dSnapshot =
|
|
188521
|
+
const fileDir = path43.dirname(file);
|
|
188522
|
+
const relativeDir = path43.relative(projectDir, fileDir);
|
|
188523
|
+
const snapDir2 = snapshotsDirName ? path43.join(projectDir, snapshotsDirName, relativeDir) : path43.join(fileDir, "__snapshots__");
|
|
188524
|
+
const base2 = path43.basename(file).replace(/\.tsx$/, "");
|
|
188525
|
+
const snap3dPath = path43.join(snapDir2, `${base2}-3d.snap.png`);
|
|
188526
|
+
const existing3dSnapshot = fs43.existsSync(snap3dPath);
|
|
188464
188527
|
if (existing3dSnapshot) {
|
|
188465
188528
|
onError(kleur_default.red(`
|
|
188466
188529
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
188467
188530
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
188468
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
188531
|
+
`) + kleur_default.red(` Existing snapshot: ${path43.relative(projectDir, snap3dPath)}
|
|
188469
188532
|
`));
|
|
188470
188533
|
return onExit2(1);
|
|
188471
188534
|
} else {
|
|
@@ -188481,9 +188544,9 @@ var snapshotProject = async ({
|
|
|
188481
188544
|
}
|
|
188482
188545
|
}
|
|
188483
188546
|
}
|
|
188484
|
-
const snapDir = snapshotsDirName ?
|
|
188485
|
-
|
|
188486
|
-
const base =
|
|
188547
|
+
const snapDir = snapshotsDirName ? path43.join(projectDir, snapshotsDirName, path43.relative(projectDir, path43.dirname(file))) : path43.join(path43.dirname(file), "__snapshots__");
|
|
188548
|
+
fs43.mkdirSync(snapDir, { recursive: true });
|
|
188549
|
+
const base = path43.basename(file).replace(/\.tsx$/, "");
|
|
188487
188550
|
const snapshots = [];
|
|
188488
188551
|
if (pcbOnly || !schematicOnly) {
|
|
188489
188552
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -188501,31 +188564,31 @@ var snapshotProject = async ({
|
|
|
188501
188564
|
for (const snapshot of snapshots) {
|
|
188502
188565
|
const { type } = snapshot;
|
|
188503
188566
|
const is3d = type === "3d";
|
|
188504
|
-
const snapPath =
|
|
188505
|
-
const existing =
|
|
188567
|
+
const snapPath = path43.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
188568
|
+
const existing = fs43.existsSync(snapPath);
|
|
188506
188569
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
188507
188570
|
const newContentForFile = snapshot.content;
|
|
188508
188571
|
if (!existing) {
|
|
188509
|
-
|
|
188510
|
-
console.log("✅", kleur_default.gray(
|
|
188572
|
+
fs43.writeFileSync(snapPath, newContentForFile);
|
|
188573
|
+
console.log("✅", kleur_default.gray(path43.relative(projectDir, snapPath)));
|
|
188511
188574
|
didUpdate = true;
|
|
188512
188575
|
continue;
|
|
188513
188576
|
}
|
|
188514
|
-
const oldContentBuffer =
|
|
188577
|
+
const oldContentBuffer = fs43.readFileSync(snapPath);
|
|
188515
188578
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
188516
188579
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
188517
188580
|
if (update) {
|
|
188518
188581
|
if (!forceUpdate && equal2) {
|
|
188519
|
-
console.log("✅", kleur_default.gray(
|
|
188582
|
+
console.log("✅", kleur_default.gray(path43.relative(projectDir, snapPath)));
|
|
188520
188583
|
} else {
|
|
188521
|
-
|
|
188522
|
-
console.log("✅", kleur_default.gray(
|
|
188584
|
+
fs43.writeFileSync(snapPath, newContentForFile);
|
|
188585
|
+
console.log("✅", kleur_default.gray(path43.relative(projectDir, snapPath)));
|
|
188523
188586
|
didUpdate = true;
|
|
188524
188587
|
}
|
|
188525
188588
|
} else if (!equal2) {
|
|
188526
188589
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
188527
188590
|
} else {
|
|
188528
|
-
console.log("✅", kleur_default.gray(
|
|
188591
|
+
console.log("✅", kleur_default.gray(path43.relative(projectDir, snapPath)));
|
|
188529
188592
|
}
|
|
188530
188593
|
}
|
|
188531
188594
|
}
|
|
@@ -188564,22 +188627,22 @@ var registerSnapshot = (program3) => {
|
|
|
188564
188627
|
};
|
|
188565
188628
|
|
|
188566
188629
|
// lib/shared/setup-github-actions.ts
|
|
188567
|
-
import
|
|
188568
|
-
import
|
|
188630
|
+
import fs44 from "node:fs";
|
|
188631
|
+
import path44 from "node:path";
|
|
188569
188632
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
188570
188633
|
const findGitRoot = (startDir) => {
|
|
188571
|
-
let dir =
|
|
188572
|
-
while (dir !==
|
|
188573
|
-
if (
|
|
188634
|
+
let dir = path44.resolve(startDir);
|
|
188635
|
+
while (dir !== path44.parse(dir).root) {
|
|
188636
|
+
if (fs44.existsSync(path44.join(dir, ".git"))) {
|
|
188574
188637
|
return dir;
|
|
188575
188638
|
}
|
|
188576
|
-
dir =
|
|
188639
|
+
dir = path44.dirname(dir);
|
|
188577
188640
|
}
|
|
188578
188641
|
return null;
|
|
188579
188642
|
};
|
|
188580
188643
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
188581
|
-
const workflowsDir =
|
|
188582
|
-
|
|
188644
|
+
const workflowsDir = path44.join(gitRoot, ".github", "workflows");
|
|
188645
|
+
fs44.mkdirSync(workflowsDir, { recursive: true });
|
|
188583
188646
|
const buildWorkflow = `name: tscircuit Build
|
|
188584
188647
|
|
|
188585
188648
|
on:
|
|
@@ -188618,8 +188681,8 @@ jobs:
|
|
|
188618
188681
|
- run: bun install
|
|
188619
188682
|
- run: bunx tsci snapshot
|
|
188620
188683
|
`;
|
|
188621
|
-
writeFileIfNotExists(
|
|
188622
|
-
writeFileIfNotExists(
|
|
188684
|
+
writeFileIfNotExists(path44.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
188685
|
+
writeFileIfNotExists(path44.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
188623
188686
|
};
|
|
188624
188687
|
|
|
188625
188688
|
// cli/setup/register.ts
|
|
@@ -188657,8 +188720,8 @@ function registerAuthSetupNpmrc(program3) {
|
|
|
188657
188720
|
}
|
|
188658
188721
|
|
|
188659
188722
|
// cli/convert/register.ts
|
|
188660
|
-
import
|
|
188661
|
-
import
|
|
188723
|
+
import fs45 from "node:fs/promises";
|
|
188724
|
+
import path45 from "node:path";
|
|
188662
188725
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
188663
188726
|
|
|
188664
188727
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -188778,15 +188841,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
188778
188841
|
var registerConvert = (program3) => {
|
|
188779
188842
|
program3.command("convert").description("Convert a .kicad_mod footprint to a tscircuit component").argument("<file>", "Path to the .kicad_mod file").option("-o, --output <path>", "Output TSX file path").option("-n, --name <component>", "Component name for export").action(async (file, options) => {
|
|
188780
188843
|
try {
|
|
188781
|
-
const inputPath =
|
|
188782
|
-
const modContent = await
|
|
188844
|
+
const inputPath = path45.resolve(file);
|
|
188845
|
+
const modContent = await fs45.readFile(inputPath, "utf-8");
|
|
188783
188846
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
188784
|
-
const componentName = options.name ??
|
|
188847
|
+
const componentName = options.name ?? path45.basename(inputPath, ".kicad_mod");
|
|
188785
188848
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
188786
188849
|
componentName
|
|
188787
188850
|
});
|
|
188788
|
-
const outputPath = options.output ?
|
|
188789
|
-
await
|
|
188851
|
+
const outputPath = options.output ? path45.resolve(options.output) : path45.join(path45.dirname(inputPath), `${componentName}.tsx`);
|
|
188852
|
+
await fs45.writeFile(outputPath, tsx);
|
|
188790
188853
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
188791
188854
|
} catch (error) {
|
|
188792
188855
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -188882,12 +188945,12 @@ var registerSimulate = (program3) => {
|
|
|
188882
188945
|
};
|
|
188883
188946
|
|
|
188884
188947
|
// lib/shared/install-project-dependencies.ts
|
|
188885
|
-
import
|
|
188886
|
-
import
|
|
188948
|
+
import fs47 from "node:fs";
|
|
188949
|
+
import path47 from "node:path";
|
|
188887
188950
|
|
|
188888
188951
|
// lib/shared/collect-tsci-dependencies.ts
|
|
188889
|
-
import
|
|
188890
|
-
import
|
|
188952
|
+
import fs46 from "node:fs";
|
|
188953
|
+
import path46 from "node:path";
|
|
188891
188954
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
188892
188955
|
var DEFAULT_IGNORES = [
|
|
188893
188956
|
"**/node_modules/**",
|
|
@@ -188902,7 +188965,7 @@ function collectTsciDependencies({
|
|
|
188902
188965
|
patterns = DEFAULT_PATTERNS,
|
|
188903
188966
|
ignore = DEFAULT_IGNORES
|
|
188904
188967
|
} = {}) {
|
|
188905
|
-
const searchRoot =
|
|
188968
|
+
const searchRoot = path46.resolve(cwd);
|
|
188906
188969
|
const files = globbySync(patterns, {
|
|
188907
188970
|
cwd: searchRoot,
|
|
188908
188971
|
absolute: true,
|
|
@@ -188912,7 +188975,7 @@ function collectTsciDependencies({
|
|
|
188912
188975
|
const dependencies2 = new Set;
|
|
188913
188976
|
for (const filePath of files) {
|
|
188914
188977
|
try {
|
|
188915
|
-
const fileContents =
|
|
188978
|
+
const fileContents = fs46.readFileSync(filePath, "utf-8");
|
|
188916
188979
|
let match;
|
|
188917
188980
|
while (true) {
|
|
188918
188981
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -188929,26 +188992,26 @@ function collectTsciDependencies({
|
|
|
188929
188992
|
async function installProjectDependencies({
|
|
188930
188993
|
cwd = process.cwd()
|
|
188931
188994
|
} = {}) {
|
|
188932
|
-
const projectRoot =
|
|
188933
|
-
const packageJsonPath =
|
|
188934
|
-
const npmrcPath =
|
|
188995
|
+
const projectRoot = path47.resolve(cwd);
|
|
188996
|
+
const packageJsonPath = path47.join(projectRoot, "package.json");
|
|
188997
|
+
const npmrcPath = path47.join(projectRoot, ".npmrc");
|
|
188935
188998
|
const packageManager = getPackageManager();
|
|
188936
|
-
if (!
|
|
188999
|
+
if (!fs47.existsSync(projectRoot)) {
|
|
188937
189000
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
188938
189001
|
}
|
|
188939
189002
|
let packageJsonCreated = false;
|
|
188940
|
-
if (!
|
|
189003
|
+
if (!fs47.existsSync(packageJsonPath)) {
|
|
188941
189004
|
console.log("No package.json found. Generating a new one.");
|
|
188942
189005
|
generatePackageJson(projectRoot);
|
|
188943
189006
|
packageJsonCreated = true;
|
|
188944
189007
|
} else {
|
|
188945
189008
|
console.log("Found existing package.json.");
|
|
188946
189009
|
}
|
|
188947
|
-
if (!
|
|
189010
|
+
if (!fs47.existsSync(npmrcPath)) {
|
|
188948
189011
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
188949
|
-
|
|
189012
|
+
fs47.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
188950
189013
|
}
|
|
188951
|
-
const packageJson = JSON.parse(
|
|
189014
|
+
const packageJson = JSON.parse(fs47.readFileSync(packageJsonPath, "utf-8"));
|
|
188952
189015
|
if (packageJsonCreated) {
|
|
188953
189016
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
188954
189017
|
if (tsciDependencies.length > 0) {
|
|
@@ -188963,7 +189026,7 @@ async function installProjectDependencies({
|
|
|
188963
189026
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
188964
189027
|
}
|
|
188965
189028
|
}
|
|
188966
|
-
|
|
189029
|
+
fs47.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
188967
189030
|
`);
|
|
188968
189031
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
188969
189032
|
try {
|
|
@@ -188998,7 +189061,7 @@ var registerInstall = (program3) => {
|
|
|
188998
189061
|
};
|
|
188999
189062
|
|
|
189000
189063
|
// cli/transpile/register.ts
|
|
189001
|
-
import
|
|
189064
|
+
import path48 from "node:path";
|
|
189002
189065
|
var registerTranspile = (program3) => {
|
|
189003
189066
|
program3.command("transpile").description("Transpile TypeScript/TSX to JavaScript (ESM, CommonJS, and type declarations)").argument("[file]", "Path to the entry file").action(async (file) => {
|
|
189004
189067
|
try {
|
|
@@ -189006,7 +189069,7 @@ var registerTranspile = (program3) => {
|
|
|
189006
189069
|
fileOrDir: file,
|
|
189007
189070
|
includeBoardFiles: false
|
|
189008
189071
|
});
|
|
189009
|
-
const distDir =
|
|
189072
|
+
const distDir = path48.join(projectDir, "dist");
|
|
189010
189073
|
validateMainInDist(projectDir, distDir);
|
|
189011
189074
|
console.log("Transpiling entry file...");
|
|
189012
189075
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.692",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/standalone": "^7.26.9",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"bun-match-svg": "^0.0.12",
|
|
24
24
|
"chokidar": "4.0.1",
|
|
25
25
|
"circuit-json": "0.0.325",
|
|
26
|
-
"circuit-json-to-gltf": "^0.0.
|
|
26
|
+
"circuit-json-to-gltf": "^0.0.58",
|
|
27
27
|
"circuit-json-to-kicad": "^0.0.31",
|
|
28
28
|
"circuit-json-to-readable-netlist": "^0.0.13",
|
|
29
29
|
"circuit-json-to-spice": "^0.0.10",
|