@tscircuit/cli 0.1.800 → 0.1.801
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 -150
- package/package.json +1 -1
- package/types/tscircuit.config.schema.json +4 -0
package/dist/main.js
CHANGED
|
@@ -73386,6 +73386,7 @@ var projectConfigSchema = z.object({
|
|
|
73386
73386
|
prebuildCommand: z.string().optional(),
|
|
73387
73387
|
buildCommand: z.string().optional(),
|
|
73388
73388
|
kicadLibraryEntrypointPath: z.string().optional(),
|
|
73389
|
+
kicadLibraryName: z.string().optional(),
|
|
73389
73390
|
alwaysUseLatestTscircuitOnCloud: z.boolean().optional(),
|
|
73390
73391
|
build: z.object({
|
|
73391
73392
|
circuitJson: z.boolean().optional(),
|
|
@@ -74266,7 +74267,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
74266
74267
|
import { execSync as execSync2 } from "node:child_process";
|
|
74267
74268
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
74268
74269
|
// package.json
|
|
74269
|
-
var version = "0.1.
|
|
74270
|
+
var version = "0.1.800";
|
|
74270
74271
|
var package_default = {
|
|
74271
74272
|
name: "@tscircuit/cli",
|
|
74272
74273
|
version,
|
|
@@ -172826,8 +172827,8 @@ var registerRemove = (program3) => {
|
|
|
172826
172827
|
};
|
|
172827
172828
|
|
|
172828
172829
|
// cli/build/register.ts
|
|
172829
|
-
import
|
|
172830
|
-
import
|
|
172830
|
+
import path50 from "node:path";
|
|
172831
|
+
import fs50 from "node:fs";
|
|
172831
172832
|
|
|
172832
172833
|
// cli/build/build-file.ts
|
|
172833
172834
|
import path36 from "node:path";
|
|
@@ -173556,8 +173557,8 @@ var generateKicadProject = async ({
|
|
|
173556
173557
|
};
|
|
173557
173558
|
|
|
173558
173559
|
// cli/build/build-kicad-pcm.ts
|
|
173559
|
-
import
|
|
173560
|
-
import
|
|
173560
|
+
import path45 from "node:path";
|
|
173561
|
+
import fs45 from "node:fs";
|
|
173561
173562
|
|
|
173562
173563
|
// lib/shared/generate-pcm-assets.ts
|
|
173563
173564
|
var import_jszip3 = __toESM2(require_lib4(), 1);
|
|
@@ -173569,19 +173570,20 @@ async function generatePcmAssets(options) {
|
|
|
173569
173570
|
packageName,
|
|
173570
173571
|
version: version2,
|
|
173571
173572
|
author,
|
|
173572
|
-
description =
|
|
173573
|
-
descriptionFull = `
|
|
173573
|
+
description = "",
|
|
173574
|
+
descriptionFull = `Visit https://tscircuit.com/${author}/${packageName} for more information.`,
|
|
173574
173575
|
license = "MIT",
|
|
173575
173576
|
kicadLibraryPath,
|
|
173576
173577
|
outputDir,
|
|
173577
|
-
baseUrl
|
|
173578
|
+
baseUrl,
|
|
173579
|
+
displayName = `${author}/${packageName}`
|
|
173578
173580
|
} = options;
|
|
173579
173581
|
const identifier = `com.tscircuit.${author}.${packageName}`.toLowerCase().replace(/[^a-z0-9.-]/g, "-").slice(0, 50);
|
|
173580
173582
|
fs43.mkdirSync(outputDir, { recursive: true });
|
|
173581
173583
|
console.log("Creating metadata.json...");
|
|
173582
173584
|
const metadata = {
|
|
173583
173585
|
$schema: "https://go.kicad.org/pcm/schemas/v1",
|
|
173584
|
-
name:
|
|
173586
|
+
name: displayName,
|
|
173585
173587
|
description: description.slice(0, 500),
|
|
173586
173588
|
description_full: descriptionFull.slice(0, 5000),
|
|
173587
173589
|
identifier,
|
|
@@ -173617,7 +173619,7 @@ async function generatePcmAssets(options) {
|
|
|
173617
173619
|
packages: [
|
|
173618
173620
|
{
|
|
173619
173621
|
identifier,
|
|
173620
|
-
name:
|
|
173622
|
+
name: displayName,
|
|
173621
173623
|
description: description.slice(0, 500),
|
|
173622
173624
|
description_full: descriptionFull.slice(0, 5000),
|
|
173623
173625
|
type: "library",
|
|
@@ -173650,7 +173652,7 @@ async function generatePcmAssets(options) {
|
|
|
173650
173652
|
const packagesJsonUrl = baseUrl ? `${baseUrl}/pcm/packages.json` : "./packages.json";
|
|
173651
173653
|
const repositoryJson = {
|
|
173652
173654
|
$schema: "https://go.kicad.org/pcm/schemas/v1",
|
|
173653
|
-
name:
|
|
173655
|
+
name: displayName,
|
|
173654
173656
|
maintainer: {
|
|
173655
173657
|
name: author,
|
|
173656
173658
|
contact: {
|
|
@@ -173716,24 +173718,46 @@ async function createPcmZip(options) {
|
|
|
173716
173718
|
fs43.writeFileSync(outputPath, zipBuffer);
|
|
173717
173719
|
}
|
|
173718
173720
|
|
|
173721
|
+
// lib/utils/resolve-kicad-library-name.ts
|
|
173722
|
+
import path44 from "node:path";
|
|
173723
|
+
import fs44 from "node:fs";
|
|
173724
|
+
function resolveKicadLibraryName({
|
|
173725
|
+
projectDir
|
|
173726
|
+
}) {
|
|
173727
|
+
const projectConfig2 = loadProjectConfig(projectDir);
|
|
173728
|
+
if (projectConfig2?.kicadLibraryName) {
|
|
173729
|
+
return projectConfig2.kicadLibraryName;
|
|
173730
|
+
}
|
|
173731
|
+
const packageJsonPath = path44.join(projectDir, "package.json");
|
|
173732
|
+
if (fs44.existsSync(packageJsonPath)) {
|
|
173733
|
+
const packageJson = JSON.parse(fs44.readFileSync(packageJsonPath, "utf-8"));
|
|
173734
|
+
const unscopedName = getUnscopedPackageName(packageJson.name || "");
|
|
173735
|
+
if (unscopedName) {
|
|
173736
|
+
return unscopedName.replace("@tsci/", "").replace(/\./g, "-");
|
|
173737
|
+
}
|
|
173738
|
+
}
|
|
173739
|
+
throw new Error(`Couldn't resolve KiCad library name. Please set kicadLibraryName in tscircuit.config.json or add the "name" field to package.json`);
|
|
173740
|
+
}
|
|
173741
|
+
|
|
173719
173742
|
// cli/build/build-kicad-pcm.ts
|
|
173720
173743
|
async function buildKicadPcm({
|
|
173721
173744
|
entryFile,
|
|
173722
173745
|
projectDir,
|
|
173723
173746
|
distDir
|
|
173724
173747
|
}) {
|
|
173725
|
-
const packageJsonPath =
|
|
173726
|
-
if (!
|
|
173748
|
+
const packageJsonPath = path45.join(projectDir, "package.json");
|
|
173749
|
+
if (!fs45.existsSync(packageJsonPath)) {
|
|
173727
173750
|
throw new Error("No package.json found for KiCad PCM generation");
|
|
173728
173751
|
}
|
|
173729
|
-
const packageJson = JSON.parse(
|
|
173730
|
-
const
|
|
173752
|
+
const packageJson = JSON.parse(fs45.readFileSync(packageJsonPath, "utf-8"));
|
|
173753
|
+
const projectConfig2 = loadProjectConfig(projectDir);
|
|
173754
|
+
const packageName = packageJson.name?.split("/").pop()?.split(".").pop() || path45.basename(projectDir);
|
|
173731
173755
|
const version2 = packageJson.version || "1.0.0";
|
|
173732
173756
|
const author = getPackageAuthor(packageJson.name || "") || "tscircuit";
|
|
173733
173757
|
const description = packageJson.description || "";
|
|
173734
|
-
const libraryName =
|
|
173735
|
-
const kicadLibOutputDir =
|
|
173736
|
-
if (!
|
|
173758
|
+
const libraryName = resolveKicadLibraryName({ projectDir });
|
|
173759
|
+
const kicadLibOutputDir = path45.join(distDir, "kicad-library");
|
|
173760
|
+
if (!fs45.existsSync(kicadLibOutputDir)) {
|
|
173737
173761
|
console.log("Converting to KiCad library...");
|
|
173738
173762
|
await convertToKicadLibrary({
|
|
173739
173763
|
filePath: entryFile,
|
|
@@ -173741,7 +173765,7 @@ async function buildKicadPcm({
|
|
|
173741
173765
|
outputDir: kicadLibOutputDir
|
|
173742
173766
|
});
|
|
173743
173767
|
}
|
|
173744
|
-
const pcmOutputDir =
|
|
173768
|
+
const pcmOutputDir = path45.join(distDir, "pcm");
|
|
173745
173769
|
const envDeploymentUrl = process.env.TSCIRCUIT_DEPLOYMENT_URL?.replace(/\/+$/, "");
|
|
173746
173770
|
const baseUrl = envDeploymentUrl ?? `https://${author}--${packageName}.tscircuit.app`;
|
|
173747
173771
|
console.log("Generating PCM assets...");
|
|
@@ -173752,15 +173776,16 @@ async function buildKicadPcm({
|
|
|
173752
173776
|
description,
|
|
173753
173777
|
kicadLibraryPath: kicadLibOutputDir,
|
|
173754
173778
|
outputDir: pcmOutputDir,
|
|
173755
|
-
baseUrl
|
|
173779
|
+
baseUrl,
|
|
173780
|
+
displayName: projectConfig2?.kicadLibraryName || undefined
|
|
173756
173781
|
});
|
|
173757
|
-
console.log(` KiCad PCM assets generated at ${kleur_default.dim(
|
|
173782
|
+
console.log(` KiCad PCM assets generated at ${kleur_default.dim(path45.relative(process.cwd(), pcmOutputDir))}`);
|
|
173758
173783
|
console.log(` Repository URL: ${kleur_default.cyan(`${baseUrl}/pcm/repository.json`)}`);
|
|
173759
173784
|
}
|
|
173760
173785
|
|
|
173761
173786
|
// cli/build/transpile/index.ts
|
|
173762
|
-
import
|
|
173763
|
-
import
|
|
173787
|
+
import path47 from "node:path";
|
|
173788
|
+
import fs47 from "node:fs";
|
|
173764
173789
|
import { rollup } from "rollup";
|
|
173765
173790
|
import typescript from "@rollup/plugin-typescript";
|
|
173766
173791
|
import resolve11 from "@rollup/plugin-node-resolve";
|
|
@@ -173769,11 +173794,11 @@ import json from "@rollup/plugin-json";
|
|
|
173769
173794
|
import dts from "rollup-plugin-dts";
|
|
173770
173795
|
|
|
173771
173796
|
// cli/build/transpile/static-asset-plugin.ts
|
|
173772
|
-
import
|
|
173773
|
-
import
|
|
173797
|
+
import fs46 from "node:fs";
|
|
173798
|
+
import path46 from "node:path";
|
|
173774
173799
|
import { createHash } from "node:crypto";
|
|
173775
173800
|
function normalizePathSeparators(filePath) {
|
|
173776
|
-
return filePath.split(
|
|
173801
|
+
return filePath.split(path46.sep).join("/");
|
|
173777
173802
|
}
|
|
173778
173803
|
var STATIC_ASSET_EXTENSIONS = new Set([
|
|
173779
173804
|
".glb",
|
|
@@ -173804,24 +173829,24 @@ var createStaticAssetPlugin = ({
|
|
|
173804
173829
|
return {
|
|
173805
173830
|
name: "tsci-static-assets",
|
|
173806
173831
|
resolveId(source, importer) {
|
|
173807
|
-
const ext =
|
|
173832
|
+
const ext = path46.extname(source).toLowerCase();
|
|
173808
173833
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
173809
173834
|
return null;
|
|
173810
|
-
if (
|
|
173811
|
-
return
|
|
173835
|
+
if (path46.isAbsolute(source)) {
|
|
173836
|
+
return fs46.existsSync(source) ? { id: normalizePathSeparators(source), external: true } : null;
|
|
173812
173837
|
}
|
|
173813
173838
|
if (importer) {
|
|
173814
|
-
const importerNative = importer.split("/").join(
|
|
173815
|
-
const resolvedFromImporter =
|
|
173816
|
-
if (
|
|
173839
|
+
const importerNative = importer.split("/").join(path46.sep);
|
|
173840
|
+
const resolvedFromImporter = path46.resolve(path46.dirname(importerNative), source);
|
|
173841
|
+
if (fs46.existsSync(resolvedFromImporter)) {
|
|
173817
173842
|
return {
|
|
173818
173843
|
id: normalizePathSeparators(resolvedFromImporter),
|
|
173819
173844
|
external: true
|
|
173820
173845
|
};
|
|
173821
173846
|
}
|
|
173822
173847
|
}
|
|
173823
|
-
const resolvedFromProject =
|
|
173824
|
-
if (
|
|
173848
|
+
const resolvedFromProject = path46.resolve(resolvedBaseUrl, source);
|
|
173849
|
+
if (fs46.existsSync(resolvedFromProject)) {
|
|
173825
173850
|
return {
|
|
173826
173851
|
id: normalizePathSeparators(resolvedFromProject),
|
|
173827
173852
|
external: true
|
|
@@ -173834,8 +173859,8 @@ var createStaticAssetPlugin = ({
|
|
|
173834
173859
|
const wildcard = isWildcard ? source.slice(patternPrefix.length) : "";
|
|
173835
173860
|
for (const target of targets) {
|
|
173836
173861
|
const targetPath = isWildcard ? target.replace("*", wildcard) : target;
|
|
173837
|
-
const resolvedTarget =
|
|
173838
|
-
if (
|
|
173862
|
+
const resolvedTarget = path46.resolve(resolvedBaseUrl, targetPath);
|
|
173863
|
+
if (fs46.existsSync(resolvedTarget)) {
|
|
173839
173864
|
return {
|
|
173840
173865
|
id: normalizePathSeparators(resolvedTarget),
|
|
173841
173866
|
external: true
|
|
@@ -173861,18 +173886,18 @@ var createStaticAssetPlugin = ({
|
|
|
173861
173886
|
if (chunk.type !== "chunk")
|
|
173862
173887
|
continue;
|
|
173863
173888
|
for (const importedId of chunk.imports) {
|
|
173864
|
-
const ext =
|
|
173889
|
+
const ext = path46.extname(importedId).toLowerCase();
|
|
173865
173890
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
173866
173891
|
continue;
|
|
173867
173892
|
if (!copiedAssets.has(importedId)) {
|
|
173868
|
-
const assetDir =
|
|
173869
|
-
|
|
173870
|
-
const nativePath = importedId.split("/").join(
|
|
173871
|
-
const fileBuffer =
|
|
173893
|
+
const assetDir = path46.join(outputDir, "assets");
|
|
173894
|
+
fs46.mkdirSync(assetDir, { recursive: true });
|
|
173895
|
+
const nativePath = importedId.split("/").join(path46.sep);
|
|
173896
|
+
const fileBuffer = fs46.readFileSync(nativePath);
|
|
173872
173897
|
const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
|
|
173873
|
-
const fileName = `${
|
|
173874
|
-
const outputFilePath =
|
|
173875
|
-
|
|
173898
|
+
const fileName = `${path46.basename(importedId, ext)}-${hash}${ext}`;
|
|
173899
|
+
const outputFilePath = path46.join(assetDir, fileName);
|
|
173900
|
+
fs46.writeFileSync(outputFilePath, fileBuffer);
|
|
173876
173901
|
copiedAssets.set(importedId, `./assets/${fileName}`);
|
|
173877
173902
|
assetIdToOutputPath.set(importedId, `./assets/${fileName}`);
|
|
173878
173903
|
}
|
|
@@ -173894,17 +173919,17 @@ function escapeRegExp(string) {
|
|
|
173894
173919
|
|
|
173895
173920
|
// cli/build/transpile/index.ts
|
|
173896
173921
|
var createExternalFunction = (projectDir, tsconfigPath) => (id) => {
|
|
173897
|
-
if (id.startsWith(".") || id.startsWith("/") ||
|
|
173922
|
+
if (id.startsWith(".") || id.startsWith("/") || path47.isAbsolute(id)) {
|
|
173898
173923
|
return false;
|
|
173899
173924
|
}
|
|
173900
173925
|
let baseUrl = projectDir;
|
|
173901
173926
|
let pathMappings = {};
|
|
173902
|
-
if (tsconfigPath &&
|
|
173927
|
+
if (tsconfigPath && fs47.existsSync(tsconfigPath)) {
|
|
173903
173928
|
try {
|
|
173904
|
-
const tsconfigContent =
|
|
173929
|
+
const tsconfigContent = fs47.readFileSync(tsconfigPath, "utf-8");
|
|
173905
173930
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
173906
173931
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
173907
|
-
baseUrl =
|
|
173932
|
+
baseUrl = path47.resolve(path47.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
173908
173933
|
}
|
|
173909
173934
|
if (tsconfig.compilerOptions?.paths) {
|
|
173910
173935
|
pathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -173918,17 +173943,17 @@ var createExternalFunction = (projectDir, tsconfigPath) => (id) => {
|
|
|
173918
173943
|
}
|
|
173919
173944
|
}
|
|
173920
173945
|
const potentialPaths = [
|
|
173921
|
-
|
|
173922
|
-
|
|
173923
|
-
|
|
173924
|
-
|
|
173925
|
-
|
|
173926
|
-
|
|
173927
|
-
|
|
173928
|
-
|
|
173929
|
-
|
|
173946
|
+
path47.join(baseUrl, id),
|
|
173947
|
+
path47.join(baseUrl, `${id}.ts`),
|
|
173948
|
+
path47.join(baseUrl, `${id}.tsx`),
|
|
173949
|
+
path47.join(baseUrl, `${id}.js`),
|
|
173950
|
+
path47.join(baseUrl, `${id}.jsx`),
|
|
173951
|
+
path47.join(baseUrl, id, "index.ts"),
|
|
173952
|
+
path47.join(baseUrl, id, "index.tsx"),
|
|
173953
|
+
path47.join(baseUrl, id, "index.js"),
|
|
173954
|
+
path47.join(baseUrl, id, "index.jsx")
|
|
173930
173955
|
];
|
|
173931
|
-
if (potentialPaths.some((p4) =>
|
|
173956
|
+
if (potentialPaths.some((p4) => fs47.existsSync(p4))) {
|
|
173932
173957
|
return false;
|
|
173933
173958
|
}
|
|
173934
173959
|
return true;
|
|
@@ -173939,17 +173964,17 @@ var transpileFile = async ({
|
|
|
173939
173964
|
projectDir
|
|
173940
173965
|
}) => {
|
|
173941
173966
|
try {
|
|
173942
|
-
|
|
173943
|
-
const tsconfigPath =
|
|
173944
|
-
const hasTsConfig =
|
|
173967
|
+
fs47.mkdirSync(outputDir, { recursive: true });
|
|
173968
|
+
const tsconfigPath = path47.join(projectDir, "tsconfig.json");
|
|
173969
|
+
const hasTsConfig = fs47.existsSync(tsconfigPath);
|
|
173945
173970
|
let tsconfigBaseUrl = projectDir;
|
|
173946
173971
|
let tsconfigPathMappings;
|
|
173947
173972
|
if (hasTsConfig) {
|
|
173948
173973
|
try {
|
|
173949
|
-
const tsconfigContent =
|
|
173974
|
+
const tsconfigContent = fs47.readFileSync(tsconfigPath, "utf-8");
|
|
173950
173975
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
173951
173976
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
173952
|
-
tsconfigBaseUrl =
|
|
173977
|
+
tsconfigBaseUrl = path47.resolve(path47.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
173953
173978
|
}
|
|
173954
173979
|
if (tsconfig.compilerOptions?.paths) {
|
|
173955
173980
|
tsconfigPathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -174004,27 +174029,27 @@ var transpileFile = async ({
|
|
|
174004
174029
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
174005
174030
|
plugins: getPlugins()
|
|
174006
174031
|
});
|
|
174007
|
-
const esmOutputPath =
|
|
174032
|
+
const esmOutputPath = path47.join(outputDir, "index.js");
|
|
174008
174033
|
await esmBundle.write({
|
|
174009
174034
|
file: esmOutputPath,
|
|
174010
174035
|
format: "es",
|
|
174011
174036
|
sourcemap: false
|
|
174012
174037
|
});
|
|
174013
|
-
console.log(`ESM bundle written to ${
|
|
174038
|
+
console.log(`ESM bundle written to ${path47.relative(projectDir, esmOutputPath)}`);
|
|
174014
174039
|
console.log("Building CommonJS bundle...");
|
|
174015
174040
|
const cjsBundle = await rollup({
|
|
174016
174041
|
input,
|
|
174017
174042
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
174018
174043
|
plugins: getPlugins()
|
|
174019
174044
|
});
|
|
174020
|
-
const cjsOutputPath =
|
|
174045
|
+
const cjsOutputPath = path47.join(outputDir, "index.cjs");
|
|
174021
174046
|
console.log("Writing CJS bundle to:", cjsOutputPath);
|
|
174022
174047
|
await cjsBundle.write({
|
|
174023
174048
|
file: cjsOutputPath,
|
|
174024
174049
|
format: "cjs",
|
|
174025
174050
|
sourcemap: false
|
|
174026
174051
|
});
|
|
174027
|
-
console.log(`CommonJS bundle written to ${
|
|
174052
|
+
console.log(`CommonJS bundle written to ${path47.relative(projectDir, cjsOutputPath)}`);
|
|
174028
174053
|
console.log("Generating type declarations...");
|
|
174029
174054
|
const dtsBundle = await rollup({
|
|
174030
174055
|
input,
|
|
@@ -174049,9 +174074,9 @@ var transpileFile = async ({
|
|
|
174049
174074
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
174050
174075
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
174051
174076
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
174052
|
-
const dtsOutputPath =
|
|
174053
|
-
|
|
174054
|
-
console.log(`Type declarations written to ${
|
|
174077
|
+
const dtsOutputPath = path47.join(outputDir, "index.d.ts");
|
|
174078
|
+
fs47.writeFileSync(dtsOutputPath, dtsContent);
|
|
174079
|
+
console.log(`Type declarations written to ${path47.relative(projectDir, dtsOutputPath)}`);
|
|
174055
174080
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
174056
174081
|
return true;
|
|
174057
174082
|
} catch (err) {
|
|
@@ -174064,17 +174089,17 @@ var transpileFile = async ({
|
|
|
174064
174089
|
};
|
|
174065
174090
|
|
|
174066
174091
|
// cli/utils/validate-main-in-dist.ts
|
|
174067
|
-
import
|
|
174068
|
-
import
|
|
174092
|
+
import fs48 from "node:fs";
|
|
174093
|
+
import path48 from "node:path";
|
|
174069
174094
|
var validateMainInDist = (projectDir, distDir) => {
|
|
174070
|
-
const packageJsonPath =
|
|
174071
|
-
if (!
|
|
174095
|
+
const packageJsonPath = path48.join(projectDir, "package.json");
|
|
174096
|
+
if (!fs48.existsSync(packageJsonPath))
|
|
174072
174097
|
return;
|
|
174073
|
-
const packageJson = JSON.parse(
|
|
174098
|
+
const packageJson = JSON.parse(fs48.readFileSync(packageJsonPath, "utf-8"));
|
|
174074
174099
|
if (typeof packageJson.main !== "string")
|
|
174075
174100
|
return;
|
|
174076
|
-
const resolvedMainPath =
|
|
174077
|
-
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${
|
|
174101
|
+
const resolvedMainPath = path48.resolve(projectDir, packageJson.main);
|
|
174102
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path48.sep}`);
|
|
174078
174103
|
if (!isMainInDist) {
|
|
174079
174104
|
console.warn('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
174080
174105
|
}
|
|
@@ -174096,19 +174121,19 @@ async function getLatestTscircuitCdnUrl() {
|
|
|
174096
174121
|
}
|
|
174097
174122
|
|
|
174098
174123
|
// cli/build/worker-pool.ts
|
|
174099
|
-
import
|
|
174100
|
-
import
|
|
174124
|
+
import path49 from "node:path";
|
|
174125
|
+
import fs49 from "node:fs";
|
|
174101
174126
|
import { Worker } from "node:worker_threads";
|
|
174102
174127
|
var getWorkerEntrypointPath = () => {
|
|
174103
|
-
const tsPath =
|
|
174104
|
-
if (
|
|
174128
|
+
const tsPath = path49.join(import.meta.dir, "build-worker-entrypoint.ts");
|
|
174129
|
+
if (fs49.existsSync(tsPath)) {
|
|
174105
174130
|
return tsPath;
|
|
174106
174131
|
}
|
|
174107
|
-
const jsBundledPath =
|
|
174108
|
-
if (
|
|
174132
|
+
const jsBundledPath = path49.join(import.meta.dir, "build", "build-worker-entrypoint.js");
|
|
174133
|
+
if (fs49.existsSync(jsBundledPath)) {
|
|
174109
174134
|
return jsBundledPath;
|
|
174110
174135
|
}
|
|
174111
|
-
return
|
|
174136
|
+
return path49.join(import.meta.dir, "build-worker-entrypoint.js");
|
|
174112
174137
|
};
|
|
174113
174138
|
|
|
174114
174139
|
class WorkerPool {
|
|
@@ -174264,7 +174289,7 @@ async function buildFilesWithWorkerPool(options) {
|
|
|
174264
174289
|
}
|
|
174265
174290
|
|
|
174266
174291
|
// cli/build/register.ts
|
|
174267
|
-
var normalizeRelativePath = (projectDir, targetPath) =>
|
|
174292
|
+
var normalizeRelativePath = (projectDir, targetPath) => path50.relative(projectDir, targetPath).split(path50.sep).join("/");
|
|
174268
174293
|
var registerBuild = (program3) => {
|
|
174269
174294
|
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").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("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").action(async (file, options) => {
|
|
174270
174295
|
try {
|
|
@@ -174297,8 +174322,8 @@ var registerBuild = (program3) => {
|
|
|
174297
174322
|
}
|
|
174298
174323
|
return config;
|
|
174299
174324
|
})();
|
|
174300
|
-
const distDir =
|
|
174301
|
-
|
|
174325
|
+
const distDir = path50.join(projectDir, "dist");
|
|
174326
|
+
fs50.mkdirSync(distDir, { recursive: true });
|
|
174302
174327
|
const concurrencyValue = Math.max(1, Number.parseInt(resolvedOptions?.concurrency || "1", 10));
|
|
174303
174328
|
if (concurrencyValue > 1) {
|
|
174304
174329
|
console.log(`Building ${circuitFiles.length} file(s) with concurrency ${concurrencyValue}...`);
|
|
@@ -174316,7 +174341,7 @@ var registerBuild = (program3) => {
|
|
|
174316
174341
|
platformConfig: platformConfig2
|
|
174317
174342
|
};
|
|
174318
174343
|
const processBuildResult = async (filePath, outputPath, buildOutcome) => {
|
|
174319
|
-
const relative10 =
|
|
174344
|
+
const relative10 = path50.relative(projectDir, filePath);
|
|
174320
174345
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174321
174346
|
builtFiles.push({
|
|
174322
174347
|
sourcePath: filePath,
|
|
@@ -174326,9 +174351,9 @@ var registerBuild = (program3) => {
|
|
|
174326
174351
|
if (!buildOutcome.ok) {
|
|
174327
174352
|
hasErrors = true;
|
|
174328
174353
|
} else if (resolvedOptions?.site) {
|
|
174329
|
-
const normalizedSourcePath = relative10.split(
|
|
174330
|
-
const relativeOutputPath =
|
|
174331
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
174354
|
+
const normalizedSourcePath = relative10.split(path50.sep).join("/");
|
|
174355
|
+
const relativeOutputPath = path50.join(outputDirName, "circuit.json");
|
|
174356
|
+
const normalizedOutputPath = relativeOutputPath.split(path50.sep).join("/");
|
|
174332
174357
|
staticFileReferences.push({
|
|
174333
174358
|
filePath: normalizedSourcePath,
|
|
174334
174359
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
@@ -174336,12 +174361,12 @@ var registerBuild = (program3) => {
|
|
|
174336
174361
|
}
|
|
174337
174362
|
if (buildOutcome.ok && shouldGenerateKicad) {
|
|
174338
174363
|
let circuitJson = buildOutcome.circuitJson;
|
|
174339
|
-
if (!circuitJson &&
|
|
174340
|
-
circuitJson = JSON.parse(
|
|
174364
|
+
if (!circuitJson && fs50.existsSync(outputPath)) {
|
|
174365
|
+
circuitJson = JSON.parse(fs50.readFileSync(outputPath, "utf-8"));
|
|
174341
174366
|
}
|
|
174342
174367
|
if (circuitJson) {
|
|
174343
|
-
const projectOutputDir =
|
|
174344
|
-
const projectName =
|
|
174368
|
+
const projectOutputDir = path50.join(distDir, outputDirName, "kicad");
|
|
174369
|
+
const projectName = path50.basename(outputDirName);
|
|
174345
174370
|
const project = await generateKicadProject({
|
|
174346
174371
|
circuitJson,
|
|
174347
174372
|
outputDir: projectOutputDir,
|
|
@@ -174357,19 +174382,19 @@ var registerBuild = (program3) => {
|
|
|
174357
174382
|
};
|
|
174358
174383
|
const buildSequentially = async () => {
|
|
174359
174384
|
for (const filePath of circuitFiles) {
|
|
174360
|
-
const relative10 =
|
|
174385
|
+
const relative10 = path50.relative(projectDir, filePath);
|
|
174361
174386
|
console.log(`Building ${relative10}...`);
|
|
174362
174387
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174363
|
-
const outputPath =
|
|
174388
|
+
const outputPath = path50.join(distDir, outputDirName, "circuit.json");
|
|
174364
174389
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, buildOptions);
|
|
174365
174390
|
await processBuildResult(filePath, outputPath, buildOutcome);
|
|
174366
174391
|
}
|
|
174367
174392
|
};
|
|
174368
174393
|
const buildWithWorkers = async () => {
|
|
174369
174394
|
const filesToBuild = circuitFiles.map((filePath) => {
|
|
174370
|
-
const relative10 =
|
|
174395
|
+
const relative10 = path50.relative(projectDir, filePath);
|
|
174371
174396
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
174372
|
-
const outputPath =
|
|
174397
|
+
const outputPath = path50.join(distDir, outputDirName, "circuit.json");
|
|
174373
174398
|
return { filePath, outputPath };
|
|
174374
174399
|
});
|
|
174375
174400
|
await buildFilesWithWorkerPool({
|
|
@@ -174383,7 +174408,7 @@ var registerBuild = (program3) => {
|
|
|
174383
174408
|
}
|
|
174384
174409
|
},
|
|
174385
174410
|
onJobComplete: async (result) => {
|
|
174386
|
-
const relative10 =
|
|
174411
|
+
const relative10 = path50.relative(projectDir, result.filePath);
|
|
174387
174412
|
if (result.ok) {
|
|
174388
174413
|
console.log(kleur_default.green(`✓ ${relative10}`));
|
|
174389
174414
|
} else {
|
|
@@ -174453,14 +174478,14 @@ var registerBuild = (program3) => {
|
|
|
174453
174478
|
if (resolvedOptions?.useCdnJavascript) {
|
|
174454
174479
|
standaloneScriptSrc = await getLatestTscircuitCdnUrl();
|
|
174455
174480
|
} else {
|
|
174456
|
-
|
|
174481
|
+
fs50.writeFileSync(path50.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
174457
174482
|
}
|
|
174458
174483
|
const indexHtml = getStaticIndexHtmlFile({
|
|
174459
174484
|
files: staticFileReferences,
|
|
174460
174485
|
standaloneScriptSrc,
|
|
174461
174486
|
defaultMainComponentPath: siteDefaultComponentPath ? normalizeRelativePath(projectDir, siteDefaultComponentPath) : undefined
|
|
174462
174487
|
});
|
|
174463
|
-
|
|
174488
|
+
fs50.writeFileSync(path50.join(distDir, "index.html"), indexHtml);
|
|
174464
174489
|
}
|
|
174465
174490
|
if (resolvedOptions?.kicadFootprintLibrary) {
|
|
174466
174491
|
console.log("Generating KiCad footprint library...");
|
|
@@ -174479,15 +174504,15 @@ var registerBuild = (program3) => {
|
|
|
174479
174504
|
process.exit(1);
|
|
174480
174505
|
}
|
|
174481
174506
|
} else {
|
|
174482
|
-
const libraryName =
|
|
174483
|
-
const kicadLibOutputDir =
|
|
174507
|
+
const libraryName = resolveKicadLibraryName({ projectDir });
|
|
174508
|
+
const kicadLibOutputDir = path50.join(distDir, "kicad-library");
|
|
174484
174509
|
try {
|
|
174485
174510
|
await convertToKicadLibrary({
|
|
174486
174511
|
filePath: entryFile,
|
|
174487
174512
|
libraryName,
|
|
174488
174513
|
outputDir: kicadLibOutputDir
|
|
174489
174514
|
});
|
|
174490
|
-
console.log(` KiCad library generated at ${kleur_default.dim(
|
|
174515
|
+
console.log(` KiCad library generated at ${kleur_default.dim(path50.relative(process.cwd(), kicadLibOutputDir))}`);
|
|
174491
174516
|
} catch (err) {
|
|
174492
174517
|
console.error(`Error generating KiCad library: ${err instanceof Error ? err.message : err}`);
|
|
174493
174518
|
if (!resolvedOptions?.ignoreErrors) {
|
|
@@ -174545,7 +174570,7 @@ var registerBuild = (program3) => {
|
|
|
174545
174570
|
if (enabledOpts.length > 0) {
|
|
174546
174571
|
console.log(` Options ${kleur_default.cyan(enabledOpts.join(", "))}`);
|
|
174547
174572
|
}
|
|
174548
|
-
console.log(` Output ${kleur_default.dim(
|
|
174573
|
+
console.log(` Output ${kleur_default.dim(path50.relative(process.cwd(), distDir) || "dist")}`);
|
|
174549
174574
|
console.log(hasErrors ? kleur_default.yellow(`
|
|
174550
174575
|
⚠ Build completed with errors`) : kleur_default.green(`
|
|
174551
174576
|
✓ Done`));
|
|
@@ -174559,8 +174584,8 @@ var registerBuild = (program3) => {
|
|
|
174559
174584
|
};
|
|
174560
174585
|
|
|
174561
174586
|
// lib/shared/snapshot-project.ts
|
|
174562
|
-
import
|
|
174563
|
-
import
|
|
174587
|
+
import fs52 from "node:fs";
|
|
174588
|
+
import path51 from "node:path";
|
|
174564
174589
|
import looksSame2 from "looks-same";
|
|
174565
174590
|
import {
|
|
174566
174591
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -174571,7 +174596,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
174571
174596
|
|
|
174572
174597
|
// lib/shared/compare-images.ts
|
|
174573
174598
|
import looksSame from "looks-same";
|
|
174574
|
-
import
|
|
174599
|
+
import fs51 from "node:fs/promises";
|
|
174575
174600
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
174576
174601
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
174577
174602
|
strict: false,
|
|
@@ -174587,7 +174612,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
174587
174612
|
tolerance: 2
|
|
174588
174613
|
});
|
|
174589
174614
|
} else {
|
|
174590
|
-
await
|
|
174615
|
+
await fs51.writeFile(diffPath, buffer2);
|
|
174591
174616
|
}
|
|
174592
174617
|
}
|
|
174593
174618
|
return { equal: equal2 };
|
|
@@ -174612,7 +174637,7 @@ var snapshotProject = async ({
|
|
|
174612
174637
|
...DEFAULT_IGNORED_PATTERNS,
|
|
174613
174638
|
...ignored.map(normalizeIgnorePattern)
|
|
174614
174639
|
];
|
|
174615
|
-
const resolvedPaths = filePaths.map((f2) =>
|
|
174640
|
+
const resolvedPaths = filePaths.map((f2) => path51.resolve(projectDir, f2));
|
|
174616
174641
|
const boardFiles = findBoardFiles({
|
|
174617
174642
|
projectDir,
|
|
174618
174643
|
ignore,
|
|
@@ -174626,7 +174651,7 @@ var snapshotProject = async ({
|
|
|
174626
174651
|
const mismatches = [];
|
|
174627
174652
|
let didUpdate = false;
|
|
174628
174653
|
for (const file of boardFiles) {
|
|
174629
|
-
const relativeFilePath =
|
|
174654
|
+
const relativeFilePath = path51.relative(projectDir, file);
|
|
174630
174655
|
let circuitJson;
|
|
174631
174656
|
let pcbSvg;
|
|
174632
174657
|
let schSvg;
|
|
@@ -174681,17 +174706,17 @@ var snapshotProject = async ({
|
|
|
174681
174706
|
} catch (error) {
|
|
174682
174707
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
174683
174708
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
174684
|
-
const fileDir =
|
|
174685
|
-
const relativeDir =
|
|
174686
|
-
const snapDir2 = snapshotsDirName ?
|
|
174687
|
-
const base2 =
|
|
174688
|
-
const snap3dPath =
|
|
174689
|
-
const existing3dSnapshot =
|
|
174709
|
+
const fileDir = path51.dirname(file);
|
|
174710
|
+
const relativeDir = path51.relative(projectDir, fileDir);
|
|
174711
|
+
const snapDir2 = snapshotsDirName ? path51.join(projectDir, snapshotsDirName, relativeDir) : path51.join(fileDir, "__snapshots__");
|
|
174712
|
+
const base2 = path51.basename(file).replace(/\.tsx$/, "");
|
|
174713
|
+
const snap3dPath = path51.join(snapDir2, `${base2}-3d.snap.png`);
|
|
174714
|
+
const existing3dSnapshot = fs52.existsSync(snap3dPath);
|
|
174690
174715
|
if (existing3dSnapshot) {
|
|
174691
174716
|
onError(kleur_default.red(`
|
|
174692
174717
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
174693
174718
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
174694
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
174719
|
+
`) + kleur_default.red(` Existing snapshot: ${path51.relative(projectDir, snap3dPath)}
|
|
174695
174720
|
`));
|
|
174696
174721
|
return onExit2(1);
|
|
174697
174722
|
} else {
|
|
@@ -174707,9 +174732,9 @@ var snapshotProject = async ({
|
|
|
174707
174732
|
}
|
|
174708
174733
|
}
|
|
174709
174734
|
}
|
|
174710
|
-
const snapDir = snapshotsDirName ?
|
|
174711
|
-
|
|
174712
|
-
const base =
|
|
174735
|
+
const snapDir = snapshotsDirName ? path51.join(projectDir, snapshotsDirName, path51.relative(projectDir, path51.dirname(file))) : path51.join(path51.dirname(file), "__snapshots__");
|
|
174736
|
+
fs52.mkdirSync(snapDir, { recursive: true });
|
|
174737
|
+
const base = path51.basename(file).replace(/\.tsx$/, "");
|
|
174713
174738
|
const snapshots = [];
|
|
174714
174739
|
if (pcbOnly || !schematicOnly) {
|
|
174715
174740
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -174727,31 +174752,31 @@ var snapshotProject = async ({
|
|
|
174727
174752
|
for (const snapshot of snapshots) {
|
|
174728
174753
|
const { type } = snapshot;
|
|
174729
174754
|
const is3d = type === "3d";
|
|
174730
|
-
const snapPath =
|
|
174731
|
-
const existing =
|
|
174755
|
+
const snapPath = path51.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
174756
|
+
const existing = fs52.existsSync(snapPath);
|
|
174732
174757
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
174733
174758
|
const newContentForFile = snapshot.content;
|
|
174734
174759
|
if (!existing) {
|
|
174735
|
-
|
|
174736
|
-
console.log("✅", kleur_default.gray(
|
|
174760
|
+
fs52.writeFileSync(snapPath, newContentForFile);
|
|
174761
|
+
console.log("✅", kleur_default.gray(path51.relative(projectDir, snapPath)));
|
|
174737
174762
|
didUpdate = true;
|
|
174738
174763
|
continue;
|
|
174739
174764
|
}
|
|
174740
|
-
const oldContentBuffer =
|
|
174765
|
+
const oldContentBuffer = fs52.readFileSync(snapPath);
|
|
174741
174766
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
174742
174767
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
174743
174768
|
if (update) {
|
|
174744
174769
|
if (!forceUpdate && equal2) {
|
|
174745
|
-
console.log("✅", kleur_default.gray(
|
|
174770
|
+
console.log("✅", kleur_default.gray(path51.relative(projectDir, snapPath)));
|
|
174746
174771
|
} else {
|
|
174747
|
-
|
|
174748
|
-
console.log("✅", kleur_default.gray(
|
|
174772
|
+
fs52.writeFileSync(snapPath, newContentForFile);
|
|
174773
|
+
console.log("✅", kleur_default.gray(path51.relative(projectDir, snapPath)));
|
|
174749
174774
|
didUpdate = true;
|
|
174750
174775
|
}
|
|
174751
174776
|
} else if (!equal2) {
|
|
174752
174777
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
174753
174778
|
} else {
|
|
174754
|
-
console.log("✅", kleur_default.gray(
|
|
174779
|
+
console.log("✅", kleur_default.gray(path51.relative(projectDir, snapPath)));
|
|
174755
174780
|
}
|
|
174756
174781
|
}
|
|
174757
174782
|
}
|
|
@@ -174790,22 +174815,22 @@ var registerSnapshot = (program3) => {
|
|
|
174790
174815
|
};
|
|
174791
174816
|
|
|
174792
174817
|
// lib/shared/setup-github-actions.ts
|
|
174793
|
-
import
|
|
174794
|
-
import
|
|
174818
|
+
import fs53 from "node:fs";
|
|
174819
|
+
import path52 from "node:path";
|
|
174795
174820
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
174796
174821
|
const findGitRoot = (startDir) => {
|
|
174797
|
-
let dir =
|
|
174798
|
-
while (dir !==
|
|
174799
|
-
if (
|
|
174822
|
+
let dir = path52.resolve(startDir);
|
|
174823
|
+
while (dir !== path52.parse(dir).root) {
|
|
174824
|
+
if (fs53.existsSync(path52.join(dir, ".git"))) {
|
|
174800
174825
|
return dir;
|
|
174801
174826
|
}
|
|
174802
|
-
dir =
|
|
174827
|
+
dir = path52.dirname(dir);
|
|
174803
174828
|
}
|
|
174804
174829
|
return null;
|
|
174805
174830
|
};
|
|
174806
174831
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
174807
|
-
const workflowsDir =
|
|
174808
|
-
|
|
174832
|
+
const workflowsDir = path52.join(gitRoot, ".github", "workflows");
|
|
174833
|
+
fs53.mkdirSync(workflowsDir, { recursive: true });
|
|
174809
174834
|
const buildWorkflow = `name: tscircuit Build
|
|
174810
174835
|
|
|
174811
174836
|
on:
|
|
@@ -174844,8 +174869,8 @@ jobs:
|
|
|
174844
174869
|
- run: bun install
|
|
174845
174870
|
- run: bunx tsci snapshot
|
|
174846
174871
|
`;
|
|
174847
|
-
writeFileIfNotExists(
|
|
174848
|
-
writeFileIfNotExists(
|
|
174872
|
+
writeFileIfNotExists(path52.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
174873
|
+
writeFileIfNotExists(path52.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
174849
174874
|
};
|
|
174850
174875
|
|
|
174851
174876
|
// cli/setup/register.ts
|
|
@@ -174883,8 +174908,8 @@ function registerAuthSetupNpmrc(program3) {
|
|
|
174883
174908
|
}
|
|
174884
174909
|
|
|
174885
174910
|
// cli/convert/register.ts
|
|
174886
|
-
import
|
|
174887
|
-
import
|
|
174911
|
+
import fs54 from "node:fs/promises";
|
|
174912
|
+
import path53 from "node:path";
|
|
174888
174913
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
174889
174914
|
|
|
174890
174915
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -175005,15 +175030,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
175005
175030
|
var registerConvert = (program3) => {
|
|
175006
175031
|
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) => {
|
|
175007
175032
|
try {
|
|
175008
|
-
const inputPath =
|
|
175009
|
-
const modContent = await
|
|
175033
|
+
const inputPath = path53.resolve(file);
|
|
175034
|
+
const modContent = await fs54.readFile(inputPath, "utf-8");
|
|
175010
175035
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
175011
|
-
const componentName = options.name ??
|
|
175036
|
+
const componentName = options.name ?? path53.basename(inputPath, ".kicad_mod");
|
|
175012
175037
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
175013
175038
|
componentName
|
|
175014
175039
|
});
|
|
175015
|
-
const outputPath = options.output ?
|
|
175016
|
-
await
|
|
175040
|
+
const outputPath = options.output ? path53.resolve(options.output) : path53.join(path53.dirname(inputPath), `${componentName}.tsx`);
|
|
175041
|
+
await fs54.writeFile(outputPath, tsx);
|
|
175017
175042
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
175018
175043
|
} catch (error) {
|
|
175019
175044
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -175129,7 +175154,7 @@ var registerInstall = (program3) => {
|
|
|
175129
175154
|
};
|
|
175130
175155
|
|
|
175131
175156
|
// cli/transpile/register.ts
|
|
175132
|
-
import
|
|
175157
|
+
import path54 from "node:path";
|
|
175133
175158
|
var registerTranspile = (program3) => {
|
|
175134
175159
|
program3.command("transpile").description("Transpile TypeScript/TSX to JavaScript (ESM, CommonJS, and type declarations)").argument("[file]", "Path to the entry file").action(async (file) => {
|
|
175135
175160
|
try {
|
|
@@ -175137,7 +175162,7 @@ var registerTranspile = (program3) => {
|
|
|
175137
175162
|
fileOrDir: file,
|
|
175138
175163
|
includeBoardFiles: false
|
|
175139
175164
|
});
|
|
175140
|
-
const distDir =
|
|
175165
|
+
const distDir = path54.join(projectDir, "dist");
|
|
175141
175166
|
validateMainInDist(projectDir, distDir);
|
|
175142
175167
|
console.log("Transpiling entry file...");
|
|
175143
175168
|
const entryFile = mainEntrypoint || circuitFiles[0];
|
package/package.json
CHANGED
|
@@ -52,6 +52,10 @@
|
|
|
52
52
|
"type": "string",
|
|
53
53
|
"description": "Entry file for KiCad footprint library generation."
|
|
54
54
|
},
|
|
55
|
+
"kicadLibraryName": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "Name for the generated KiCad library. Falls back to package.json name, then directory name."
|
|
58
|
+
},
|
|
55
59
|
"alwaysUseLatestTscircuitOnCloud": {
|
|
56
60
|
"type": "boolean",
|
|
57
61
|
"description": "Always use the latest TSCircuit version when building on the cloud."
|