@tscircuit/cli 0.1.504 → 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 +195 -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";
|
|
@@ -196292,9 +196293,29 @@ var buildFile = async (input, output, projectDir, options) => {
|
|
|
196292
196293
|
}
|
|
196293
196294
|
} catch (err) {
|
|
196294
196295
|
console.error(`Build failed: ${err}`);
|
|
196296
|
+
if (err instanceof Error) {
|
|
196297
|
+
logTypeReexportHint(err, input);
|
|
196298
|
+
}
|
|
196295
196299
|
return { ok: false };
|
|
196296
196300
|
}
|
|
196297
196301
|
};
|
|
196302
|
+
var TYPE_REEXPORT_ERROR_REGEX = /SyntaxError: export '([^']+)' not found in '([^']+)'/;
|
|
196303
|
+
var logTypeReexportHint = (error, entryFilePath) => {
|
|
196304
|
+
const match = String(error).match(TYPE_REEXPORT_ERROR_REGEX);
|
|
196305
|
+
if (!match)
|
|
196306
|
+
return;
|
|
196307
|
+
const [, exportName, fromSpecifier] = match;
|
|
196308
|
+
const entryFileName = path30.basename(entryFilePath);
|
|
196309
|
+
console.error([
|
|
196310
|
+
"",
|
|
196311
|
+
`It looks like "${entryFileName}" re-exports the type-only symbol "${exportName}" from "${fromSpecifier}" without the "type" modifier.`,
|
|
196312
|
+
"Type-only exports must be re-exported with `export type { ... }`.",
|
|
196313
|
+
"Try rewriting the statement as:",
|
|
196314
|
+
` export type { ${exportName} } from "${fromSpecifier}"`,
|
|
196315
|
+
""
|
|
196316
|
+
].join(`
|
|
196317
|
+
`));
|
|
196318
|
+
};
|
|
196298
196319
|
|
|
196299
196320
|
// cli/build/get-build-entrypoints.ts
|
|
196300
196321
|
import fs32 from "node:fs";
|
|
@@ -196663,90 +196684,138 @@ ${libTableEntries.join(`
|
|
|
196663
196684
|
}
|
|
196664
196685
|
};
|
|
196665
196686
|
|
|
196666
|
-
// cli/build/transpile.ts
|
|
196667
|
-
import
|
|
196668
|
-
import
|
|
196687
|
+
// cli/build/transpile/index.ts
|
|
196688
|
+
import path36 from "node:path";
|
|
196689
|
+
import fs37 from "node:fs";
|
|
196669
196690
|
import { rollup } from "rollup";
|
|
196670
196691
|
import typescript from "@rollup/plugin-typescript";
|
|
196671
196692
|
import resolve12 from "@rollup/plugin-node-resolve";
|
|
196672
196693
|
import commonjs from "@rollup/plugin-commonjs";
|
|
196673
196694
|
import json from "@rollup/plugin-json";
|
|
196674
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");
|
|
196675
196746
|
var transpileFile = async ({
|
|
196676
196747
|
input,
|
|
196677
196748
|
outputDir,
|
|
196678
196749
|
projectDir
|
|
196679
196750
|
}) => {
|
|
196680
196751
|
try {
|
|
196681
|
-
|
|
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))));
|
|
196682
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
|
+
];
|
|
196683
196792
|
const esmBundle = await rollup({
|
|
196684
196793
|
input,
|
|
196685
196794
|
external: (id2) => {
|
|
196686
196795
|
return !id2.startsWith(".") && !id2.startsWith("/");
|
|
196687
196796
|
},
|
|
196688
|
-
plugins:
|
|
196689
|
-
resolve12({
|
|
196690
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"]
|
|
196691
|
-
}),
|
|
196692
|
-
commonjs(),
|
|
196693
|
-
json(),
|
|
196694
|
-
typescript({
|
|
196695
|
-
jsx: "react",
|
|
196696
|
-
tsconfig: false,
|
|
196697
|
-
compilerOptions: {
|
|
196698
|
-
target: "ES2020",
|
|
196699
|
-
module: "ESNext",
|
|
196700
|
-
jsx: "react",
|
|
196701
|
-
declaration: false,
|
|
196702
|
-
sourceMap: false,
|
|
196703
|
-
skipLibCheck: true,
|
|
196704
|
-
resolveJsonModule: true,
|
|
196705
|
-
allowSyntheticDefaultImports: true
|
|
196706
|
-
}
|
|
196707
|
-
})
|
|
196708
|
-
]
|
|
196797
|
+
plugins: getPlugins("ESNext")
|
|
196709
196798
|
});
|
|
196710
196799
|
await esmBundle.write({
|
|
196711
|
-
file:
|
|
196800
|
+
file: path36.join(outputDir, "index.js"),
|
|
196712
196801
|
format: "es",
|
|
196713
196802
|
sourcemap: false
|
|
196714
196803
|
});
|
|
196715
|
-
console.log(`ESM bundle written to ${
|
|
196804
|
+
console.log(`ESM bundle written to ${path36.relative(projectDir, path36.join(outputDir, "index.js"))}`);
|
|
196716
196805
|
console.log("Building CommonJS bundle...");
|
|
196717
196806
|
const cjsBundle = await rollup({
|
|
196718
196807
|
input,
|
|
196719
196808
|
external: (id2) => {
|
|
196720
196809
|
return !id2.startsWith(".") && !id2.startsWith("/");
|
|
196721
196810
|
},
|
|
196722
|
-
plugins:
|
|
196723
|
-
resolve12({
|
|
196724
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"]
|
|
196725
|
-
}),
|
|
196726
|
-
commonjs(),
|
|
196727
|
-
json(),
|
|
196728
|
-
typescript({
|
|
196729
|
-
jsx: "react",
|
|
196730
|
-
tsconfig: false,
|
|
196731
|
-
compilerOptions: {
|
|
196732
|
-
target: "ES2020",
|
|
196733
|
-
module: "CommonJS",
|
|
196734
|
-
jsx: "react",
|
|
196735
|
-
declaration: false,
|
|
196736
|
-
sourceMap: false,
|
|
196737
|
-
skipLibCheck: true,
|
|
196738
|
-
resolveJsonModule: true,
|
|
196739
|
-
allowSyntheticDefaultImports: true
|
|
196740
|
-
}
|
|
196741
|
-
})
|
|
196742
|
-
]
|
|
196811
|
+
plugins: getPlugins("CommonJS")
|
|
196743
196812
|
});
|
|
196744
196813
|
await cjsBundle.write({
|
|
196745
|
-
file:
|
|
196814
|
+
file: path36.join(outputDir, "index.cjs"),
|
|
196746
196815
|
format: "cjs",
|
|
196747
196816
|
sourcemap: false
|
|
196748
196817
|
});
|
|
196749
|
-
console.log(`CommonJS bundle written to ${
|
|
196818
|
+
console.log(`CommonJS bundle written to ${path36.relative(projectDir, path36.join(outputDir, "index.cjs"))}`);
|
|
196750
196819
|
console.log("Generating type declarations...");
|
|
196751
196820
|
const dtsBundle = await rollup({
|
|
196752
196821
|
input,
|
|
@@ -196766,8 +196835,8 @@ var transpileFile = async ({
|
|
|
196766
196835
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
196767
196836
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
196768
196837
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
196769
|
-
|
|
196770
|
-
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"))}`);
|
|
196771
196840
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
196772
196841
|
return true;
|
|
196773
196842
|
} catch (err) {
|
|
@@ -196798,8 +196867,8 @@ var registerBuild = (program3) => {
|
|
|
196798
196867
|
}
|
|
196799
196868
|
return config;
|
|
196800
196869
|
})();
|
|
196801
|
-
const distDir =
|
|
196802
|
-
|
|
196870
|
+
const distDir = path37.join(projectDir, "dist");
|
|
196871
|
+
fs38.mkdirSync(distDir, { recursive: true });
|
|
196803
196872
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
196804
196873
|
let hasErrors = false;
|
|
196805
196874
|
const staticFileReferences = [];
|
|
@@ -196807,10 +196876,10 @@ var registerBuild = (program3) => {
|
|
|
196807
196876
|
const kicadProjects = [];
|
|
196808
196877
|
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
196809
196878
|
for (const filePath of circuitFiles) {
|
|
196810
|
-
const relative9 =
|
|
196879
|
+
const relative9 = path37.relative(projectDir, filePath);
|
|
196811
196880
|
console.log(`Building ${relative9}...`);
|
|
196812
196881
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
196813
|
-
const outputPath =
|
|
196882
|
+
const outputPath = path37.join(distDir, outputDirName, "circuit.json");
|
|
196814
196883
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
196815
196884
|
ignoreErrors: options?.ignoreErrors,
|
|
196816
196885
|
ignoreWarnings: options?.ignoreWarnings,
|
|
@@ -196824,17 +196893,17 @@ var registerBuild = (program3) => {
|
|
|
196824
196893
|
if (!buildOutcome.ok) {
|
|
196825
196894
|
hasErrors = true;
|
|
196826
196895
|
} else if (options?.site) {
|
|
196827
|
-
const normalizedSourcePath = relative9.split(
|
|
196828
|
-
const relativeOutputPath =
|
|
196829
|
-
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("/");
|
|
196830
196899
|
staticFileReferences.push({
|
|
196831
196900
|
filePath: normalizedSourcePath,
|
|
196832
196901
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
196833
196902
|
});
|
|
196834
196903
|
}
|
|
196835
196904
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
196836
|
-
const projectOutputDir =
|
|
196837
|
-
const projectName =
|
|
196905
|
+
const projectOutputDir = path37.join(distDir, outputDirName, "kicad");
|
|
196906
|
+
const projectName = path37.basename(outputDirName);
|
|
196838
196907
|
const project = await generateKicadProject({
|
|
196839
196908
|
circuitJson: buildOutcome.circuitJson,
|
|
196840
196909
|
outputDir: projectOutputDir,
|
|
@@ -196882,8 +196951,8 @@ var registerBuild = (program3) => {
|
|
|
196882
196951
|
files: staticFileReferences,
|
|
196883
196952
|
standaloneScriptSrc: "./standalone.min.js"
|
|
196884
196953
|
});
|
|
196885
|
-
|
|
196886
|
-
|
|
196954
|
+
fs38.writeFileSync(path37.join(distDir, "index.html"), indexHtml);
|
|
196955
|
+
fs38.writeFileSync(path37.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
196887
196956
|
}
|
|
196888
196957
|
if (options?.kicadFootprintLibrary) {
|
|
196889
196958
|
if (kicadProjects.length === 0) {
|
|
@@ -196906,8 +196975,8 @@ var registerBuild = (program3) => {
|
|
|
196906
196975
|
};
|
|
196907
196976
|
|
|
196908
196977
|
// lib/shared/snapshot-project.ts
|
|
196909
|
-
import
|
|
196910
|
-
import
|
|
196978
|
+
import fs40 from "node:fs";
|
|
196979
|
+
import path38 from "node:path";
|
|
196911
196980
|
import looksSame2 from "looks-same";
|
|
196912
196981
|
import {
|
|
196913
196982
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -196918,7 +196987,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
196918
196987
|
|
|
196919
196988
|
// lib/shared/compare-images.ts
|
|
196920
196989
|
import looksSame from "looks-same";
|
|
196921
|
-
import
|
|
196990
|
+
import fs39 from "node:fs/promises";
|
|
196922
196991
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
196923
196992
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
196924
196993
|
strict: false,
|
|
@@ -196934,7 +197003,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
196934
197003
|
tolerance: 2
|
|
196935
197004
|
});
|
|
196936
197005
|
} else {
|
|
196937
|
-
await
|
|
197006
|
+
await fs39.writeFile(diffPath, buffer2);
|
|
196938
197007
|
}
|
|
196939
197008
|
}
|
|
196940
197009
|
return { equal: equal2 };
|
|
@@ -196959,7 +197028,7 @@ var snapshotProject = async ({
|
|
|
196959
197028
|
...DEFAULT_IGNORED_PATTERNS,
|
|
196960
197029
|
...ignored.map(normalizeIgnorePattern)
|
|
196961
197030
|
];
|
|
196962
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
197031
|
+
const resolvedPaths = filePaths.map((f) => path38.resolve(projectDir, f));
|
|
196963
197032
|
const boardFiles = findBoardFiles({
|
|
196964
197033
|
projectDir,
|
|
196965
197034
|
ignore,
|
|
@@ -196973,7 +197042,7 @@ var snapshotProject = async ({
|
|
|
196973
197042
|
const mismatches = [];
|
|
196974
197043
|
let didUpdate = false;
|
|
196975
197044
|
for (const file of boardFiles) {
|
|
196976
|
-
const relativeFilePath =
|
|
197045
|
+
const relativeFilePath = path38.relative(projectDir, file);
|
|
196977
197046
|
let circuitJson;
|
|
196978
197047
|
let pcbSvg;
|
|
196979
197048
|
let schSvg;
|
|
@@ -197027,17 +197096,17 @@ var snapshotProject = async ({
|
|
|
197027
197096
|
} catch (error) {
|
|
197028
197097
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197029
197098
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
197030
|
-
const fileDir =
|
|
197031
|
-
const relativeDir =
|
|
197032
|
-
const snapDir2 = snapshotsDirName ?
|
|
197033
|
-
const base2 =
|
|
197034
|
-
const snap3dPath =
|
|
197035
|
-
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);
|
|
197036
197105
|
if (existing3dSnapshot) {
|
|
197037
197106
|
onError(kleur_default.red(`
|
|
197038
197107
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
197039
197108
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
197040
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
197109
|
+
`) + kleur_default.red(` Existing snapshot: ${path38.relative(projectDir, snap3dPath)}
|
|
197041
197110
|
`));
|
|
197042
197111
|
return onExit(1);
|
|
197043
197112
|
} else {
|
|
@@ -197053,9 +197122,9 @@ var snapshotProject = async ({
|
|
|
197053
197122
|
}
|
|
197054
197123
|
}
|
|
197055
197124
|
}
|
|
197056
|
-
const snapDir = snapshotsDirName ?
|
|
197057
|
-
|
|
197058
|
-
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$/, "");
|
|
197059
197128
|
const snapshots = [];
|
|
197060
197129
|
if (pcbOnly || !schematicOnly) {
|
|
197061
197130
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -197073,31 +197142,31 @@ var snapshotProject = async ({
|
|
|
197073
197142
|
for (const snapshot of snapshots) {
|
|
197074
197143
|
const { type } = snapshot;
|
|
197075
197144
|
const is3d = type === "3d";
|
|
197076
|
-
const snapPath =
|
|
197077
|
-
const existing =
|
|
197145
|
+
const snapPath = path38.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
197146
|
+
const existing = fs40.existsSync(snapPath);
|
|
197078
197147
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
197079
197148
|
const newContentForFile = snapshot.content;
|
|
197080
197149
|
if (!existing) {
|
|
197081
|
-
|
|
197082
|
-
console.log("✅", kleur_default.gray(
|
|
197150
|
+
fs40.writeFileSync(snapPath, newContentForFile);
|
|
197151
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197083
197152
|
didUpdate = true;
|
|
197084
197153
|
continue;
|
|
197085
197154
|
}
|
|
197086
|
-
const oldContentBuffer =
|
|
197155
|
+
const oldContentBuffer = fs40.readFileSync(snapPath);
|
|
197087
197156
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
197088
197157
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
197089
197158
|
if (update) {
|
|
197090
197159
|
if (!forceUpdate && equal2) {
|
|
197091
|
-
console.log("✅", kleur_default.gray(
|
|
197160
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197092
197161
|
} else {
|
|
197093
|
-
|
|
197094
|
-
console.log("✅", kleur_default.gray(
|
|
197162
|
+
fs40.writeFileSync(snapPath, newContentForFile);
|
|
197163
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197095
197164
|
didUpdate = true;
|
|
197096
197165
|
}
|
|
197097
197166
|
} else if (!equal2) {
|
|
197098
197167
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
197099
197168
|
} else {
|
|
197100
|
-
console.log("✅", kleur_default.gray(
|
|
197169
|
+
console.log("✅", kleur_default.gray(path38.relative(projectDir, snapPath)));
|
|
197101
197170
|
}
|
|
197102
197171
|
}
|
|
197103
197172
|
}
|
|
@@ -197136,22 +197205,22 @@ var registerSnapshot = (program3) => {
|
|
|
197136
197205
|
};
|
|
197137
197206
|
|
|
197138
197207
|
// lib/shared/setup-github-actions.ts
|
|
197139
|
-
import
|
|
197140
|
-
import
|
|
197208
|
+
import fs41 from "node:fs";
|
|
197209
|
+
import path39 from "node:path";
|
|
197141
197210
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
197142
197211
|
const findGitRoot = (startDir) => {
|
|
197143
|
-
let dir =
|
|
197144
|
-
while (dir !==
|
|
197145
|
-
if (
|
|
197212
|
+
let dir = path39.resolve(startDir);
|
|
197213
|
+
while (dir !== path39.parse(dir).root) {
|
|
197214
|
+
if (fs41.existsSync(path39.join(dir, ".git"))) {
|
|
197146
197215
|
return dir;
|
|
197147
197216
|
}
|
|
197148
|
-
dir =
|
|
197217
|
+
dir = path39.dirname(dir);
|
|
197149
197218
|
}
|
|
197150
197219
|
return null;
|
|
197151
197220
|
};
|
|
197152
197221
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
197153
|
-
const workflowsDir =
|
|
197154
|
-
|
|
197222
|
+
const workflowsDir = path39.join(gitRoot, ".github", "workflows");
|
|
197223
|
+
fs41.mkdirSync(workflowsDir, { recursive: true });
|
|
197155
197224
|
const buildWorkflow = `name: tscircuit Build
|
|
197156
197225
|
|
|
197157
197226
|
on:
|
|
@@ -197190,8 +197259,8 @@ jobs:
|
|
|
197190
197259
|
- run: bun install
|
|
197191
197260
|
- run: bunx tsci snapshot
|
|
197192
197261
|
`;
|
|
197193
|
-
writeFileIfNotExists(
|
|
197194
|
-
writeFileIfNotExists(
|
|
197262
|
+
writeFileIfNotExists(path39.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
197263
|
+
writeFileIfNotExists(path39.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
197195
197264
|
};
|
|
197196
197265
|
|
|
197197
197266
|
// cli/setup/register.ts
|
|
@@ -197217,8 +197286,8 @@ var registerSetup = (program3) => {
|
|
|
197217
197286
|
};
|
|
197218
197287
|
|
|
197219
197288
|
// cli/convert/register.ts
|
|
197220
|
-
import
|
|
197221
|
-
import
|
|
197289
|
+
import fs42 from "node:fs/promises";
|
|
197290
|
+
import path40 from "node:path";
|
|
197222
197291
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
197223
197292
|
|
|
197224
197293
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -197338,15 +197407,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
197338
197407
|
var registerConvert = (program3) => {
|
|
197339
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) => {
|
|
197340
197409
|
try {
|
|
197341
|
-
const inputPath =
|
|
197342
|
-
const modContent = await
|
|
197410
|
+
const inputPath = path40.resolve(file);
|
|
197411
|
+
const modContent = await fs42.readFile(inputPath, "utf-8");
|
|
197343
197412
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
197344
|
-
const componentName = options.name ??
|
|
197413
|
+
const componentName = options.name ?? path40.basename(inputPath, ".kicad_mod");
|
|
197345
197414
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
197346
197415
|
componentName
|
|
197347
197416
|
});
|
|
197348
|
-
const outputPath = options.output ?
|
|
197349
|
-
await
|
|
197417
|
+
const outputPath = options.output ? path40.resolve(options.output) : path40.join(path40.dirname(inputPath), `${componentName}.tsx`);
|
|
197418
|
+
await fs42.writeFile(outputPath, tsx);
|
|
197350
197419
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
197351
197420
|
} catch (error) {
|
|
197352
197421
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -197441,12 +197510,12 @@ var registerSimulate = (program3) => {
|
|
|
197441
197510
|
};
|
|
197442
197511
|
|
|
197443
197512
|
// lib/shared/install-project-dependencies.ts
|
|
197444
|
-
import
|
|
197445
|
-
import
|
|
197513
|
+
import fs44 from "node:fs";
|
|
197514
|
+
import path42 from "node:path";
|
|
197446
197515
|
|
|
197447
197516
|
// lib/shared/collect-tsci-dependencies.ts
|
|
197448
|
-
import
|
|
197449
|
-
import
|
|
197517
|
+
import fs43 from "node:fs";
|
|
197518
|
+
import path41 from "node:path";
|
|
197450
197519
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
197451
197520
|
var DEFAULT_IGNORES = [
|
|
197452
197521
|
"**/node_modules/**",
|
|
@@ -197461,7 +197530,7 @@ function collectTsciDependencies({
|
|
|
197461
197530
|
patterns = DEFAULT_PATTERNS,
|
|
197462
197531
|
ignore = DEFAULT_IGNORES
|
|
197463
197532
|
} = {}) {
|
|
197464
|
-
const searchRoot =
|
|
197533
|
+
const searchRoot = path41.resolve(cwd);
|
|
197465
197534
|
const files = globbySync(patterns, {
|
|
197466
197535
|
cwd: searchRoot,
|
|
197467
197536
|
absolute: true,
|
|
@@ -197471,7 +197540,7 @@ function collectTsciDependencies({
|
|
|
197471
197540
|
const dependencies2 = new Set;
|
|
197472
197541
|
for (const filePath of files) {
|
|
197473
197542
|
try {
|
|
197474
|
-
const fileContents =
|
|
197543
|
+
const fileContents = fs43.readFileSync(filePath, "utf-8");
|
|
197475
197544
|
let match;
|
|
197476
197545
|
while (true) {
|
|
197477
197546
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -197488,26 +197557,26 @@ function collectTsciDependencies({
|
|
|
197488
197557
|
async function installProjectDependencies({
|
|
197489
197558
|
cwd = process.cwd()
|
|
197490
197559
|
} = {}) {
|
|
197491
|
-
const projectRoot =
|
|
197492
|
-
const packageJsonPath =
|
|
197493
|
-
const npmrcPath =
|
|
197560
|
+
const projectRoot = path42.resolve(cwd);
|
|
197561
|
+
const packageJsonPath = path42.join(projectRoot, "package.json");
|
|
197562
|
+
const npmrcPath = path42.join(projectRoot, ".npmrc");
|
|
197494
197563
|
const packageManager = getPackageManager();
|
|
197495
|
-
if (!
|
|
197564
|
+
if (!fs44.existsSync(projectRoot)) {
|
|
197496
197565
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
197497
197566
|
}
|
|
197498
197567
|
let packageJsonCreated = false;
|
|
197499
|
-
if (!
|
|
197568
|
+
if (!fs44.existsSync(packageJsonPath)) {
|
|
197500
197569
|
console.log("No package.json found. Generating a new one.");
|
|
197501
197570
|
generatePackageJson(projectRoot);
|
|
197502
197571
|
packageJsonCreated = true;
|
|
197503
197572
|
} else {
|
|
197504
197573
|
console.log("Found existing package.json.");
|
|
197505
197574
|
}
|
|
197506
|
-
if (!
|
|
197575
|
+
if (!fs44.existsSync(npmrcPath)) {
|
|
197507
197576
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
197508
|
-
|
|
197577
|
+
fs44.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
197509
197578
|
}
|
|
197510
|
-
const packageJson = JSON.parse(
|
|
197579
|
+
const packageJson = JSON.parse(fs44.readFileSync(packageJsonPath, "utf-8"));
|
|
197511
197580
|
if (packageJsonCreated) {
|
|
197512
197581
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
197513
197582
|
if (tsciDependencies.length > 0) {
|
|
@@ -197522,7 +197591,7 @@ async function installProjectDependencies({
|
|
|
197522
197591
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
197523
197592
|
}
|
|
197524
197593
|
}
|
|
197525
|
-
|
|
197594
|
+
fs44.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
197526
197595
|
`);
|
|
197527
197596
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
197528
197597
|
try {
|
|
@@ -197552,14 +197621,14 @@ var registerInstall = (program3) => {
|
|
|
197552
197621
|
};
|
|
197553
197622
|
|
|
197554
197623
|
// cli/transpile/register.ts
|
|
197555
|
-
import
|
|
197624
|
+
import path43 from "node:path";
|
|
197556
197625
|
var registerTranspile = (program3) => {
|
|
197557
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) => {
|
|
197558
197627
|
try {
|
|
197559
197628
|
const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
|
|
197560
197629
|
fileOrDir: file
|
|
197561
197630
|
});
|
|
197562
|
-
const distDir =
|
|
197631
|
+
const distDir = path43.join(projectDir, "dist");
|
|
197563
197632
|
console.log("Transpiling entry file...");
|
|
197564
197633
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
|
197565
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
|
+
}
|