@tscircuit/cli 0.1.505 → 0.1.506
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 +175 -126
- package/package.json +3 -2
- package/types/fake-snippets.d.ts +6 -0
- package/types/static-assets/index.d.ts +69 -0
package/dist/main.js
CHANGED
|
@@ -72387,7 +72387,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
72387
72387
|
import { execSync as execSync2 } from "node:child_process";
|
|
72388
72388
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
72389
72389
|
// package.json
|
|
72390
|
-
var version = "0.1.
|
|
72390
|
+
var version = "0.1.505";
|
|
72391
72391
|
var package_default = {
|
|
72392
72392
|
name: "@tscircuit/cli",
|
|
72393
72393
|
version,
|
|
@@ -72465,7 +72465,8 @@ var package_default = {
|
|
|
72465
72465
|
},
|
|
72466
72466
|
files: [
|
|
72467
72467
|
"dist",
|
|
72468
|
-
"cli/entrypoint.js"
|
|
72468
|
+
"cli/entrypoint.js",
|
|
72469
|
+
"types"
|
|
72469
72470
|
],
|
|
72470
72471
|
scripts: {
|
|
72471
72472
|
start: "bun run dev",
|
|
@@ -196227,8 +196228,8 @@ var registerRemove = (program3) => {
|
|
|
196227
196228
|
};
|
|
196228
196229
|
|
|
196229
196230
|
// cli/build/register.ts
|
|
196230
|
-
import
|
|
196231
|
-
import
|
|
196231
|
+
import path37 from "node:path";
|
|
196232
|
+
import fs38 from "node:fs";
|
|
196232
196233
|
|
|
196233
196234
|
// cli/build/build-file.ts
|
|
196234
196235
|
import path30 from "node:path";
|
|
@@ -196683,90 +196684,138 @@ ${libTableEntries.join(`
|
|
|
196683
196684
|
}
|
|
196684
196685
|
};
|
|
196685
196686
|
|
|
196686
|
-
// cli/build/transpile.ts
|
|
196687
|
-
import
|
|
196688
|
-
import
|
|
196687
|
+
// cli/build/transpile/index.ts
|
|
196688
|
+
import path36 from "node:path";
|
|
196689
|
+
import fs37 from "node:fs";
|
|
196689
196690
|
import { rollup } from "rollup";
|
|
196690
196691
|
import typescript from "@rollup/plugin-typescript";
|
|
196691
196692
|
import resolve12 from "@rollup/plugin-node-resolve";
|
|
196692
196693
|
import commonjs from "@rollup/plugin-commonjs";
|
|
196693
196694
|
import json from "@rollup/plugin-json";
|
|
196694
196695
|
import dts from "rollup-plugin-dts";
|
|
196696
|
+
|
|
196697
|
+
// cli/build/transpile/static-asset-plugin.ts
|
|
196698
|
+
import fs36 from "node:fs";
|
|
196699
|
+
import path35 from "node:path";
|
|
196700
|
+
import { createHash } from "node:crypto";
|
|
196701
|
+
var STATIC_ASSET_EXTENSIONS = new Set([
|
|
196702
|
+
".glb",
|
|
196703
|
+
".gltf",
|
|
196704
|
+
".png",
|
|
196705
|
+
".jpg",
|
|
196706
|
+
".jpeg",
|
|
196707
|
+
".svg",
|
|
196708
|
+
".webp",
|
|
196709
|
+
".gif",
|
|
196710
|
+
".bmp",
|
|
196711
|
+
".step",
|
|
196712
|
+
".kicad_mod",
|
|
196713
|
+
".kicad_pcb",
|
|
196714
|
+
".kicad_pro",
|
|
196715
|
+
".kicad_sch"
|
|
196716
|
+
]);
|
|
196717
|
+
var createStaticAssetPlugin = ({
|
|
196718
|
+
outputDir
|
|
196719
|
+
}) => {
|
|
196720
|
+
const copiedAssets = new Map;
|
|
196721
|
+
return {
|
|
196722
|
+
name: "tsci-static-assets",
|
|
196723
|
+
load(id2) {
|
|
196724
|
+
const ext = path35.extname(id2).toLowerCase();
|
|
196725
|
+
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
196726
|
+
return null;
|
|
196727
|
+
const assetDir = path35.join(outputDir, "assets");
|
|
196728
|
+
fs36.mkdirSync(assetDir, { recursive: true });
|
|
196729
|
+
const fileBuffer = fs36.readFileSync(id2);
|
|
196730
|
+
const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
|
|
196731
|
+
const fileName = `${path35.basename(id2, ext)}-${hash}${ext}`;
|
|
196732
|
+
const outputPath = path35.join(assetDir, fileName);
|
|
196733
|
+
if (!copiedAssets.has(id2)) {
|
|
196734
|
+
fs36.writeFileSync(outputPath, fileBuffer);
|
|
196735
|
+
copiedAssets.set(id2, outputPath);
|
|
196736
|
+
}
|
|
196737
|
+
const relativePath = `./assets/${fileName}`;
|
|
196738
|
+
return `export default ${JSON.stringify(relativePath)};`;
|
|
196739
|
+
}
|
|
196740
|
+
};
|
|
196741
|
+
};
|
|
196742
|
+
|
|
196743
|
+
// cli/build/transpile/index.ts
|
|
196744
|
+
var __dirname = "/home/runner/work/cli/cli/cli/build/transpile";
|
|
196745
|
+
var CLI_TYPES_ROOT = path36.resolve(__dirname, "../../../types");
|
|
196695
196746
|
var transpileFile = async ({
|
|
196696
196747
|
input,
|
|
196697
196748
|
outputDir,
|
|
196698
196749
|
projectDir
|
|
196699
196750
|
}) => {
|
|
196700
196751
|
try {
|
|
196701
|
-
|
|
196752
|
+
fs37.mkdirSync(outputDir, { recursive: true });
|
|
196753
|
+
const typeRootCandidates = [
|
|
196754
|
+
path36.join(projectDir, "node_modules", "@types"),
|
|
196755
|
+
path36.join(projectDir, "types"),
|
|
196756
|
+
CLI_TYPES_ROOT
|
|
196757
|
+
];
|
|
196758
|
+
const typeRoots = Array.from(new Set(typeRootCandidates.filter((candidate) => fs37.existsSync(candidate))));
|
|
196702
196759
|
console.log("Building ESM bundle...");
|
|
196760
|
+
const staticAssetExtensions = Array.from(STATIC_ASSET_EXTENSIONS);
|
|
196761
|
+
const getPlugins = (moduleKind) => [
|
|
196762
|
+
createStaticAssetPlugin({ outputDir }),
|
|
196763
|
+
resolve12({
|
|
196764
|
+
extensions: [
|
|
196765
|
+
".ts",
|
|
196766
|
+
".tsx",
|
|
196767
|
+
".js",
|
|
196768
|
+
".jsx",
|
|
196769
|
+
".json",
|
|
196770
|
+
...staticAssetExtensions
|
|
196771
|
+
]
|
|
196772
|
+
}),
|
|
196773
|
+
commonjs(),
|
|
196774
|
+
json(),
|
|
196775
|
+
typescript({
|
|
196776
|
+
jsx: "react",
|
|
196777
|
+
tsconfig: false,
|
|
196778
|
+
compilerOptions: {
|
|
196779
|
+
target: "ES2020",
|
|
196780
|
+
module: moduleKind,
|
|
196781
|
+
jsx: "react",
|
|
196782
|
+
declaration: false,
|
|
196783
|
+
sourceMap: false,
|
|
196784
|
+
skipLibCheck: true,
|
|
196785
|
+
resolveJsonModule: true,
|
|
196786
|
+
allowSyntheticDefaultImports: true,
|
|
196787
|
+
allowArbitraryExtensions: true,
|
|
196788
|
+
...typeRoots.length ? { typeRoots } : {}
|
|
196789
|
+
}
|
|
196790
|
+
})
|
|
196791
|
+
];
|
|
196703
196792
|
const esmBundle = await rollup({
|
|
196704
196793
|
input,
|
|
196705
196794
|
external: (id2) => {
|
|
196706
196795
|
return !id2.startsWith(".") && !id2.startsWith("/");
|
|
196707
196796
|
},
|
|
196708
|
-
plugins:
|
|
196709
|
-
resolve12({
|
|
196710
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"]
|
|
196711
|
-
}),
|
|
196712
|
-
commonjs(),
|
|
196713
|
-
json(),
|
|
196714
|
-
typescript({
|
|
196715
|
-
jsx: "react",
|
|
196716
|
-
tsconfig: false,
|
|
196717
|
-
compilerOptions: {
|
|
196718
|
-
target: "ES2020",
|
|
196719
|
-
module: "ESNext",
|
|
196720
|
-
jsx: "react",
|
|
196721
|
-
declaration: false,
|
|
196722
|
-
sourceMap: false,
|
|
196723
|
-
skipLibCheck: true,
|
|
196724
|
-
resolveJsonModule: true,
|
|
196725
|
-
allowSyntheticDefaultImports: true
|
|
196726
|
-
}
|
|
196727
|
-
})
|
|
196728
|
-
]
|
|
196797
|
+
plugins: getPlugins("ESNext")
|
|
196729
196798
|
});
|
|
196730
196799
|
await esmBundle.write({
|
|
196731
|
-
file:
|
|
196800
|
+
file: path36.join(outputDir, "index.js"),
|
|
196732
196801
|
format: "es",
|
|
196733
196802
|
sourcemap: false
|
|
196734
196803
|
});
|
|
196735
|
-
console.log(`ESM bundle written to ${
|
|
196804
|
+
console.log(`ESM bundle written to ${path36.relative(projectDir, path36.join(outputDir, "index.js"))}`);
|
|
196736
196805
|
console.log("Building CommonJS bundle...");
|
|
196737
196806
|
const cjsBundle = await rollup({
|
|
196738
196807
|
input,
|
|
196739
196808
|
external: (id2) => {
|
|
196740
196809
|
return !id2.startsWith(".") && !id2.startsWith("/");
|
|
196741
196810
|
},
|
|
196742
|
-
plugins:
|
|
196743
|
-
resolve12({
|
|
196744
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"]
|
|
196745
|
-
}),
|
|
196746
|
-
commonjs(),
|
|
196747
|
-
json(),
|
|
196748
|
-
typescript({
|
|
196749
|
-
jsx: "react",
|
|
196750
|
-
tsconfig: false,
|
|
196751
|
-
compilerOptions: {
|
|
196752
|
-
target: "ES2020",
|
|
196753
|
-
module: "CommonJS",
|
|
196754
|
-
jsx: "react",
|
|
196755
|
-
declaration: false,
|
|
196756
|
-
sourceMap: false,
|
|
196757
|
-
skipLibCheck: true,
|
|
196758
|
-
resolveJsonModule: true,
|
|
196759
|
-
allowSyntheticDefaultImports: true
|
|
196760
|
-
}
|
|
196761
|
-
})
|
|
196762
|
-
]
|
|
196811
|
+
plugins: getPlugins("CommonJS")
|
|
196763
196812
|
});
|
|
196764
196813
|
await cjsBundle.write({
|
|
196765
|
-
file:
|
|
196814
|
+
file: path36.join(outputDir, "index.cjs"),
|
|
196766
196815
|
format: "cjs",
|
|
196767
196816
|
sourcemap: false
|
|
196768
196817
|
});
|
|
196769
|
-
console.log(`CommonJS bundle written to ${
|
|
196818
|
+
console.log(`CommonJS bundle written to ${path36.relative(projectDir, path36.join(outputDir, "index.cjs"))}`);
|
|
196770
196819
|
console.log("Generating type declarations...");
|
|
196771
196820
|
const dtsBundle = await rollup({
|
|
196772
196821
|
input,
|
|
@@ -196786,8 +196835,8 @@ var transpileFile = async ({
|
|
|
196786
196835
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
196787
196836
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
196788
196837
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
196789
|
-
|
|
196790
|
-
console.log(`Type declarations written to ${
|
|
196838
|
+
fs37.writeFileSync(path36.join(outputDir, "index.d.ts"), dtsContent);
|
|
196839
|
+
console.log(`Type declarations written to ${path36.relative(projectDir, path36.join(outputDir, "index.d.ts"))}`);
|
|
196791
196840
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
196792
196841
|
return true;
|
|
196793
196842
|
} catch (err) {
|
|
@@ -196818,8 +196867,8 @@ var registerBuild = (program3) => {
|
|
|
196818
196867
|
}
|
|
196819
196868
|
return config;
|
|
196820
196869
|
})();
|
|
196821
|
-
const distDir =
|
|
196822
|
-
|
|
196870
|
+
const distDir = path37.join(projectDir, "dist");
|
|
196871
|
+
fs38.mkdirSync(distDir, { recursive: true });
|
|
196823
196872
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
196824
196873
|
let hasErrors = false;
|
|
196825
196874
|
const staticFileReferences = [];
|
|
@@ -196827,10 +196876,10 @@ var registerBuild = (program3) => {
|
|
|
196827
196876
|
const kicadProjects = [];
|
|
196828
196877
|
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
196829
196878
|
for (const filePath of circuitFiles) {
|
|
196830
|
-
const relative9 =
|
|
196879
|
+
const relative9 = path37.relative(projectDir, filePath);
|
|
196831
196880
|
console.log(`Building ${relative9}...`);
|
|
196832
196881
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
196833
|
-
const outputPath =
|
|
196882
|
+
const outputPath = path37.join(distDir, outputDirName, "circuit.json");
|
|
196834
196883
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
196835
196884
|
ignoreErrors: options?.ignoreErrors,
|
|
196836
196885
|
ignoreWarnings: options?.ignoreWarnings,
|
|
@@ -196844,17 +196893,17 @@ var registerBuild = (program3) => {
|
|
|
196844
196893
|
if (!buildOutcome.ok) {
|
|
196845
196894
|
hasErrors = true;
|
|
196846
196895
|
} else if (options?.site) {
|
|
196847
|
-
const normalizedSourcePath = relative9.split(
|
|
196848
|
-
const relativeOutputPath =
|
|
196849
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
196896
|
+
const normalizedSourcePath = relative9.split(path37.sep).join("/");
|
|
196897
|
+
const relativeOutputPath = path37.join(outputDirName, "circuit.json");
|
|
196898
|
+
const normalizedOutputPath = relativeOutputPath.split(path37.sep).join("/");
|
|
196850
196899
|
staticFileReferences.push({
|
|
196851
196900
|
filePath: normalizedSourcePath,
|
|
196852
196901
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
196853
196902
|
});
|
|
196854
196903
|
}
|
|
196855
196904
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
196856
|
-
const projectOutputDir =
|
|
196857
|
-
const projectName =
|
|
196905
|
+
const projectOutputDir = path37.join(distDir, outputDirName, "kicad");
|
|
196906
|
+
const projectName = path37.basename(outputDirName);
|
|
196858
196907
|
const project = await generateKicadProject({
|
|
196859
196908
|
circuitJson: buildOutcome.circuitJson,
|
|
196860
196909
|
outputDir: projectOutputDir,
|
|
@@ -196902,8 +196951,8 @@ var registerBuild = (program3) => {
|
|
|
196902
196951
|
files: staticFileReferences,
|
|
196903
196952
|
standaloneScriptSrc: "./standalone.min.js"
|
|
196904
196953
|
});
|
|
196905
|
-
|
|
196906
|
-
|
|
196954
|
+
fs38.writeFileSync(path37.join(distDir, "index.html"), indexHtml);
|
|
196955
|
+
fs38.writeFileSync(path37.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
196907
196956
|
}
|
|
196908
196957
|
if (options?.kicadFootprintLibrary) {
|
|
196909
196958
|
if (kicadProjects.length === 0) {
|
|
@@ -196926,8 +196975,8 @@ var registerBuild = (program3) => {
|
|
|
196926
196975
|
};
|
|
196927
196976
|
|
|
196928
196977
|
// lib/shared/snapshot-project.ts
|
|
196929
|
-
import
|
|
196930
|
-
import
|
|
196978
|
+
import fs40 from "node:fs";
|
|
196979
|
+
import path38 from "node:path";
|
|
196931
196980
|
import looksSame2 from "looks-same";
|
|
196932
196981
|
import {
|
|
196933
196982
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -196938,7 +196987,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
196938
196987
|
|
|
196939
196988
|
// lib/shared/compare-images.ts
|
|
196940
196989
|
import looksSame from "looks-same";
|
|
196941
|
-
import
|
|
196990
|
+
import fs39 from "node:fs/promises";
|
|
196942
196991
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
196943
196992
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
196944
196993
|
strict: false,
|
|
@@ -196954,7 +197003,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
196954
197003
|
tolerance: 2
|
|
196955
197004
|
});
|
|
196956
197005
|
} else {
|
|
196957
|
-
await
|
|
197006
|
+
await fs39.writeFile(diffPath, buffer2);
|
|
196958
197007
|
}
|
|
196959
197008
|
}
|
|
196960
197009
|
return { equal: equal2 };
|
|
@@ -196979,7 +197028,7 @@ var snapshotProject = async ({
|
|
|
196979
197028
|
...DEFAULT_IGNORED_PATTERNS,
|
|
196980
197029
|
...ignored.map(normalizeIgnorePattern)
|
|
196981
197030
|
];
|
|
196982
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
197031
|
+
const resolvedPaths = filePaths.map((f) => path38.resolve(projectDir, f));
|
|
196983
197032
|
const boardFiles = findBoardFiles({
|
|
196984
197033
|
projectDir,
|
|
196985
197034
|
ignore,
|
|
@@ -196993,7 +197042,7 @@ var snapshotProject = async ({
|
|
|
196993
197042
|
const mismatches = [];
|
|
196994
197043
|
let didUpdate = false;
|
|
196995
197044
|
for (const file of boardFiles) {
|
|
196996
|
-
const relativeFilePath =
|
|
197045
|
+
const relativeFilePath = path38.relative(projectDir, file);
|
|
196997
197046
|
let circuitJson;
|
|
196998
197047
|
let pcbSvg;
|
|
196999
197048
|
let schSvg;
|
|
@@ -197047,17 +197096,17 @@ var snapshotProject = async ({
|
|
|
197047
197096
|
} catch (error) {
|
|
197048
197097
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197049
197098
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
197050
|
-
const fileDir =
|
|
197051
|
-
const relativeDir =
|
|
197052
|
-
const snapDir2 = snapshotsDirName ?
|
|
197053
|
-
const base2 =
|
|
197054
|
-
const snap3dPath =
|
|
197055
|
-
const existing3dSnapshot =
|
|
197099
|
+
const fileDir = path38.dirname(file);
|
|
197100
|
+
const relativeDir = path38.relative(projectDir, fileDir);
|
|
197101
|
+
const snapDir2 = snapshotsDirName ? path38.join(projectDir, snapshotsDirName, relativeDir) : path38.join(fileDir, "__snapshots__");
|
|
197102
|
+
const base2 = path38.basename(file).replace(/\.tsx$/, "");
|
|
197103
|
+
const snap3dPath = path38.join(snapDir2, `${base2}-3d.snap.png`);
|
|
197104
|
+
const existing3dSnapshot = fs40.existsSync(snap3dPath);
|
|
197056
197105
|
if (existing3dSnapshot) {
|
|
197057
197106
|
onError(kleur_default.red(`
|
|
197058
197107
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
197059
197108
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
197060
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
197109
|
+
`) + kleur_default.red(` Existing snapshot: ${path38.relative(projectDir, snap3dPath)}
|
|
197061
197110
|
`));
|
|
197062
197111
|
return onExit(1);
|
|
197063
197112
|
} else {
|
|
@@ -197073,9 +197122,9 @@ var snapshotProject = async ({
|
|
|
197073
197122
|
}
|
|
197074
197123
|
}
|
|
197075
197124
|
}
|
|
197076
|
-
const snapDir = snapshotsDirName ?
|
|
197077
|
-
|
|
197078
|
-
const base =
|
|
197125
|
+
const snapDir = snapshotsDirName ? path38.join(projectDir, snapshotsDirName, path38.relative(projectDir, path38.dirname(file))) : path38.join(path38.dirname(file), "__snapshots__");
|
|
197126
|
+
fs40.mkdirSync(snapDir, { recursive: true });
|
|
197127
|
+
const base = path38.basename(file).replace(/\.tsx$/, "");
|
|
197079
197128
|
const snapshots = [];
|
|
197080
197129
|
if (pcbOnly || !schematicOnly) {
|
|
197081
197130
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -197093,31 +197142,31 @@ var snapshotProject = async ({
|
|
|
197093
197142
|
for (const snapshot of snapshots) {
|
|
197094
197143
|
const { type } = snapshot;
|
|
197095
197144
|
const is3d = type === "3d";
|
|
197096
|
-
const snapPath =
|
|
197097
|
-
const existing =
|
|
197145
|
+
const snapPath = path38.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
197146
|
+
const existing = fs40.existsSync(snapPath);
|
|
197098
197147
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
197099
197148
|
const newContentForFile = snapshot.content;
|
|
197100
197149
|
if (!existing) {
|
|
197101
|
-
|
|
197102
|
-
console.log("✅", kleur_default.gray(
|
|
197150
|
+
fs40.writeFileSync(snapPath, newContentForFile);
|
|
197151
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197103
197152
|
didUpdate = true;
|
|
197104
197153
|
continue;
|
|
197105
197154
|
}
|
|
197106
|
-
const oldContentBuffer =
|
|
197155
|
+
const oldContentBuffer = fs40.readFileSync(snapPath);
|
|
197107
197156
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
197108
197157
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
197109
197158
|
if (update) {
|
|
197110
197159
|
if (!forceUpdate && equal2) {
|
|
197111
|
-
console.log("✅", kleur_default.gray(
|
|
197160
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197112
197161
|
} else {
|
|
197113
|
-
|
|
197114
|
-
console.log("✅", kleur_default.gray(
|
|
197162
|
+
fs40.writeFileSync(snapPath, newContentForFile);
|
|
197163
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197115
197164
|
didUpdate = true;
|
|
197116
197165
|
}
|
|
197117
197166
|
} else if (!equal2) {
|
|
197118
197167
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
197119
197168
|
} else {
|
|
197120
|
-
console.log("✅", kleur_default.gray(
|
|
197169
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197121
197170
|
}
|
|
197122
197171
|
}
|
|
197123
197172
|
}
|
|
@@ -197156,22 +197205,22 @@ var registerSnapshot = (program3) => {
|
|
|
197156
197205
|
};
|
|
197157
197206
|
|
|
197158
197207
|
// lib/shared/setup-github-actions.ts
|
|
197159
|
-
import
|
|
197160
|
-
import
|
|
197208
|
+
import fs41 from "node:fs";
|
|
197209
|
+
import path39 from "node:path";
|
|
197161
197210
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
197162
197211
|
const findGitRoot = (startDir) => {
|
|
197163
|
-
let dir =
|
|
197164
|
-
while (dir !==
|
|
197165
|
-
if (
|
|
197212
|
+
let dir = path39.resolve(startDir);
|
|
197213
|
+
while (dir !== path39.parse(dir).root) {
|
|
197214
|
+
if (fs41.existsSync(path39.join(dir, ".git"))) {
|
|
197166
197215
|
return dir;
|
|
197167
197216
|
}
|
|
197168
|
-
dir =
|
|
197217
|
+
dir = path39.dirname(dir);
|
|
197169
197218
|
}
|
|
197170
197219
|
return null;
|
|
197171
197220
|
};
|
|
197172
197221
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
197173
|
-
const workflowsDir =
|
|
197174
|
-
|
|
197222
|
+
const workflowsDir = path39.join(gitRoot, ".github", "workflows");
|
|
197223
|
+
fs41.mkdirSync(workflowsDir, { recursive: true });
|
|
197175
197224
|
const buildWorkflow = `name: tscircuit Build
|
|
197176
197225
|
|
|
197177
197226
|
on:
|
|
@@ -197210,8 +197259,8 @@ jobs:
|
|
|
197210
197259
|
- run: bun install
|
|
197211
197260
|
- run: bunx tsci snapshot
|
|
197212
197261
|
`;
|
|
197213
|
-
writeFileIfNotExists(
|
|
197214
|
-
writeFileIfNotExists(
|
|
197262
|
+
writeFileIfNotExists(path39.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
197263
|
+
writeFileIfNotExists(path39.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
197215
197264
|
};
|
|
197216
197265
|
|
|
197217
197266
|
// cli/setup/register.ts
|
|
@@ -197237,8 +197286,8 @@ var registerSetup = (program3) => {
|
|
|
197237
197286
|
};
|
|
197238
197287
|
|
|
197239
197288
|
// cli/convert/register.ts
|
|
197240
|
-
import
|
|
197241
|
-
import
|
|
197289
|
+
import fs42 from "node:fs/promises";
|
|
197290
|
+
import path40 from "node:path";
|
|
197242
197291
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
197243
197292
|
|
|
197244
197293
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -197358,15 +197407,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
197358
197407
|
var registerConvert = (program3) => {
|
|
197359
197408
|
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) => {
|
|
197360
197409
|
try {
|
|
197361
|
-
const inputPath =
|
|
197362
|
-
const modContent = await
|
|
197410
|
+
const inputPath = path40.resolve(file);
|
|
197411
|
+
const modContent = await fs42.readFile(inputPath, "utf-8");
|
|
197363
197412
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
197364
|
-
const componentName = options.name ??
|
|
197413
|
+
const componentName = options.name ?? path40.basename(inputPath, ".kicad_mod");
|
|
197365
197414
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
197366
197415
|
componentName
|
|
197367
197416
|
});
|
|
197368
|
-
const outputPath = options.output ?
|
|
197369
|
-
await
|
|
197417
|
+
const outputPath = options.output ? path40.resolve(options.output) : path40.join(path40.dirname(inputPath), `${componentName}.tsx`);
|
|
197418
|
+
await fs42.writeFile(outputPath, tsx);
|
|
197370
197419
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
197371
197420
|
} catch (error) {
|
|
197372
197421
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -197461,12 +197510,12 @@ var registerSimulate = (program3) => {
|
|
|
197461
197510
|
};
|
|
197462
197511
|
|
|
197463
197512
|
// lib/shared/install-project-dependencies.ts
|
|
197464
|
-
import
|
|
197465
|
-
import
|
|
197513
|
+
import fs44 from "node:fs";
|
|
197514
|
+
import path42 from "node:path";
|
|
197466
197515
|
|
|
197467
197516
|
// lib/shared/collect-tsci-dependencies.ts
|
|
197468
|
-
import
|
|
197469
|
-
import
|
|
197517
|
+
import fs43 from "node:fs";
|
|
197518
|
+
import path41 from "node:path";
|
|
197470
197519
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
197471
197520
|
var DEFAULT_IGNORES = [
|
|
197472
197521
|
"**/node_modules/**",
|
|
@@ -197481,7 +197530,7 @@ function collectTsciDependencies({
|
|
|
197481
197530
|
patterns = DEFAULT_PATTERNS,
|
|
197482
197531
|
ignore = DEFAULT_IGNORES
|
|
197483
197532
|
} = {}) {
|
|
197484
|
-
const searchRoot =
|
|
197533
|
+
const searchRoot = path41.resolve(cwd);
|
|
197485
197534
|
const files = globbySync(patterns, {
|
|
197486
197535
|
cwd: searchRoot,
|
|
197487
197536
|
absolute: true,
|
|
@@ -197491,7 +197540,7 @@ function collectTsciDependencies({
|
|
|
197491
197540
|
const dependencies2 = new Set;
|
|
197492
197541
|
for (const filePath of files) {
|
|
197493
197542
|
try {
|
|
197494
|
-
const fileContents =
|
|
197543
|
+
const fileContents = fs43.readFileSync(filePath, "utf-8");
|
|
197495
197544
|
let match;
|
|
197496
197545
|
while (true) {
|
|
197497
197546
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -197508,26 +197557,26 @@ function collectTsciDependencies({
|
|
|
197508
197557
|
async function installProjectDependencies({
|
|
197509
197558
|
cwd = process.cwd()
|
|
197510
197559
|
} = {}) {
|
|
197511
|
-
const projectRoot =
|
|
197512
|
-
const packageJsonPath =
|
|
197513
|
-
const npmrcPath =
|
|
197560
|
+
const projectRoot = path42.resolve(cwd);
|
|
197561
|
+
const packageJsonPath = path42.join(projectRoot, "package.json");
|
|
197562
|
+
const npmrcPath = path42.join(projectRoot, ".npmrc");
|
|
197514
197563
|
const packageManager = getPackageManager();
|
|
197515
|
-
if (!
|
|
197564
|
+
if (!fs44.existsSync(projectRoot)) {
|
|
197516
197565
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
197517
197566
|
}
|
|
197518
197567
|
let packageJsonCreated = false;
|
|
197519
|
-
if (!
|
|
197568
|
+
if (!fs44.existsSync(packageJsonPath)) {
|
|
197520
197569
|
console.log("No package.json found. Generating a new one.");
|
|
197521
197570
|
generatePackageJson(projectRoot);
|
|
197522
197571
|
packageJsonCreated = true;
|
|
197523
197572
|
} else {
|
|
197524
197573
|
console.log("Found existing package.json.");
|
|
197525
197574
|
}
|
|
197526
|
-
if (!
|
|
197575
|
+
if (!fs44.existsSync(npmrcPath)) {
|
|
197527
197576
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
197528
|
-
|
|
197577
|
+
fs44.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
197529
197578
|
}
|
|
197530
|
-
const packageJson = JSON.parse(
|
|
197579
|
+
const packageJson = JSON.parse(fs44.readFileSync(packageJsonPath, "utf-8"));
|
|
197531
197580
|
if (packageJsonCreated) {
|
|
197532
197581
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
197533
197582
|
if (tsciDependencies.length > 0) {
|
|
@@ -197542,7 +197591,7 @@ async function installProjectDependencies({
|
|
|
197542
197591
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
197543
197592
|
}
|
|
197544
197593
|
}
|
|
197545
|
-
|
|
197594
|
+
fs44.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
197546
197595
|
`);
|
|
197547
197596
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
197548
197597
|
try {
|
|
@@ -197572,14 +197621,14 @@ var registerInstall = (program3) => {
|
|
|
197572
197621
|
};
|
|
197573
197622
|
|
|
197574
197623
|
// cli/transpile/register.ts
|
|
197575
|
-
import
|
|
197624
|
+
import path43 from "node:path";
|
|
197576
197625
|
var registerTranspile = (program3) => {
|
|
197577
197626
|
program3.command("transpile").description("Transpile TypeScript/TSX to JavaScript (ESM, CommonJS, and type declarations)").argument("[file]", "Path to the entry file").action(async (file) => {
|
|
197578
197627
|
try {
|
|
197579
197628
|
const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
|
|
197580
197629
|
fileOrDir: file
|
|
197581
197630
|
});
|
|
197582
|
-
const distDir =
|
|
197631
|
+
const distDir = path43.join(projectDir, "dist");
|
|
197583
197632
|
console.log("Transpiling entry file...");
|
|
197584
197633
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197585
197634
|
if (!entryFile) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tscircuit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.506",
|
|
4
4
|
"main": "dist/main.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@babel/standalone": "^7.26.9",
|
|
@@ -75,7 +75,8 @@
|
|
|
75
75
|
},
|
|
76
76
|
"files": [
|
|
77
77
|
"dist",
|
|
78
|
-
"cli/entrypoint.js"
|
|
78
|
+
"cli/entrypoint.js",
|
|
79
|
+
"types"
|
|
79
80
|
],
|
|
80
81
|
"scripts": {
|
|
81
82
|
"start": "bun run dev",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
declare module "*.glb" {
|
|
2
|
+
const src: string
|
|
3
|
+
export default src
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module "*.gltf" {
|
|
7
|
+
const src: string
|
|
8
|
+
export default src
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module "*.png" {
|
|
12
|
+
const src: string
|
|
13
|
+
export default src
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module "*.jpg" {
|
|
17
|
+
const src: string
|
|
18
|
+
export default src
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "*.jpeg" {
|
|
22
|
+
const src: string
|
|
23
|
+
export default src
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module "*.svg" {
|
|
27
|
+
const src: string
|
|
28
|
+
export default src
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare module "*.gif" {
|
|
32
|
+
const src: string
|
|
33
|
+
export default src
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare module "*.webp" {
|
|
37
|
+
const src: string
|
|
38
|
+
export default src
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module "*.bmp" {
|
|
42
|
+
const src: string
|
|
43
|
+
export default src
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module "*.step" {
|
|
47
|
+
const src: string
|
|
48
|
+
export default src
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare module "*.kicad_mod" {
|
|
52
|
+
const src: string
|
|
53
|
+
export default src
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module "*.kicad_pcb" {
|
|
57
|
+
const src: string
|
|
58
|
+
export default src
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
declare module "*.kicad_pro" {
|
|
62
|
+
const src: string
|
|
63
|
+
export default src
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare module "*.kicad_sch" {
|
|
67
|
+
const src: string
|
|
68
|
+
export default src
|
|
69
|
+
}
|