@tscircuit/cli 0.1.731 → 0.1.732
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 +318 -271
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -74125,7 +74125,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
74125
74125
|
import { execSync as execSync2 } from "node:child_process";
|
|
74126
74126
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
74127
74127
|
// package.json
|
|
74128
|
-
var version = "0.1.
|
|
74128
|
+
var version = "0.1.731";
|
|
74129
74129
|
var package_default = {
|
|
74130
74130
|
name: "@tscircuit/cli",
|
|
74131
74131
|
version,
|
|
@@ -187292,8 +187292,8 @@ var registerRemove = (program3) => {
|
|
|
187292
187292
|
};
|
|
187293
187293
|
|
|
187294
187294
|
// cli/build/register.ts
|
|
187295
|
-
import
|
|
187296
|
-
import
|
|
187295
|
+
import path44 from "node:path";
|
|
187296
|
+
import fs43 from "node:fs";
|
|
187297
187297
|
|
|
187298
187298
|
// cli/build/build-file.ts
|
|
187299
187299
|
import path34 from "node:path";
|
|
@@ -187427,21 +187427,156 @@ var logTypeReexportHint = (error, entryFilePath) => {
|
|
|
187427
187427
|
`));
|
|
187428
187428
|
};
|
|
187429
187429
|
|
|
187430
|
-
// cli/build/
|
|
187430
|
+
// cli/build/build-ci.ts
|
|
187431
|
+
import { execSync as execSync3 } from "node:child_process";
|
|
187432
|
+
|
|
187433
|
+
// lib/shared/install-project-dependencies.ts
|
|
187434
|
+
import fs35 from "node:fs";
|
|
187435
|
+
import path36 from "node:path";
|
|
187436
|
+
|
|
187437
|
+
// lib/shared/collect-tsci-dependencies.ts
|
|
187431
187438
|
import fs34 from "node:fs";
|
|
187432
187439
|
import path35 from "node:path";
|
|
187440
|
+
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
187441
|
+
var DEFAULT_IGNORES = [
|
|
187442
|
+
"**/node_modules/**",
|
|
187443
|
+
"**/.git/**",
|
|
187444
|
+
"**/dist/**",
|
|
187445
|
+
"**/build/**",
|
|
187446
|
+
"**/.tsci/**"
|
|
187447
|
+
];
|
|
187448
|
+
var IMPORT_PATTERN = /["'`](@tsci\/[A-Za-z0-9._/-]+)["'`]/g;
|
|
187449
|
+
function collectTsciDependencies({
|
|
187450
|
+
cwd = process.cwd(),
|
|
187451
|
+
patterns = DEFAULT_PATTERNS,
|
|
187452
|
+
ignore = DEFAULT_IGNORES
|
|
187453
|
+
} = {}) {
|
|
187454
|
+
const searchRoot = path35.resolve(cwd);
|
|
187455
|
+
const files = globbySync(patterns, {
|
|
187456
|
+
cwd: searchRoot,
|
|
187457
|
+
absolute: true,
|
|
187458
|
+
ignore,
|
|
187459
|
+
gitignore: true
|
|
187460
|
+
});
|
|
187461
|
+
const dependencies2 = new Set;
|
|
187462
|
+
for (const filePath of files) {
|
|
187463
|
+
try {
|
|
187464
|
+
const fileContents = fs34.readFileSync(filePath, "utf-8");
|
|
187465
|
+
let match;
|
|
187466
|
+
while (true) {
|
|
187467
|
+
match = IMPORT_PATTERN.exec(fileContents);
|
|
187468
|
+
if (match === null)
|
|
187469
|
+
break;
|
|
187470
|
+
dependencies2.add(match[1]);
|
|
187471
|
+
}
|
|
187472
|
+
} catch (error) {}
|
|
187473
|
+
}
|
|
187474
|
+
return Array.from(dependencies2);
|
|
187475
|
+
}
|
|
187476
|
+
|
|
187477
|
+
// lib/shared/install-project-dependencies.ts
|
|
187478
|
+
async function installProjectDependencies({
|
|
187479
|
+
cwd = process.cwd()
|
|
187480
|
+
} = {}) {
|
|
187481
|
+
const projectRoot = path36.resolve(cwd);
|
|
187482
|
+
const packageJsonPath = path36.join(projectRoot, "package.json");
|
|
187483
|
+
const npmrcPath = path36.join(projectRoot, ".npmrc");
|
|
187484
|
+
const packageManager = getPackageManager();
|
|
187485
|
+
if (!fs35.existsSync(projectRoot)) {
|
|
187486
|
+
throw new Error(`Directory not found: ${projectRoot}`);
|
|
187487
|
+
}
|
|
187488
|
+
let packageJsonCreated = false;
|
|
187489
|
+
if (!fs35.existsSync(packageJsonPath)) {
|
|
187490
|
+
console.log("No package.json found. Generating a new one.");
|
|
187491
|
+
generatePackageJson(projectRoot);
|
|
187492
|
+
packageJsonCreated = true;
|
|
187493
|
+
} else {
|
|
187494
|
+
console.log("Found existing package.json.");
|
|
187495
|
+
}
|
|
187496
|
+
if (!fs35.existsSync(npmrcPath)) {
|
|
187497
|
+
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
187498
|
+
fs35.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
187499
|
+
}
|
|
187500
|
+
const packageJson = JSON.parse(fs35.readFileSync(packageJsonPath, "utf-8"));
|
|
187501
|
+
if (packageJsonCreated) {
|
|
187502
|
+
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
187503
|
+
if (tsciDependencies.length > 0) {
|
|
187504
|
+
packageJson.dependencies = packageJson.dependencies || {};
|
|
187505
|
+
for (const dependency of tsciDependencies) {
|
|
187506
|
+
if (!packageJson.dependencies[dependency]) {
|
|
187507
|
+
packageJson.dependencies[dependency] = "latest";
|
|
187508
|
+
}
|
|
187509
|
+
}
|
|
187510
|
+
console.log(`Added ${tsciDependencies.length} @tsci dependencies to package.json.`);
|
|
187511
|
+
} else {
|
|
187512
|
+
console.log("No @tsci dependencies detected in circuit files.");
|
|
187513
|
+
}
|
|
187514
|
+
}
|
|
187515
|
+
fs35.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
187516
|
+
`);
|
|
187517
|
+
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
187518
|
+
try {
|
|
187519
|
+
packageManager.installAll({ cwd: projectRoot });
|
|
187520
|
+
console.log("Dependencies installed successfully.");
|
|
187521
|
+
} catch (error) {
|
|
187522
|
+
console.warn("Failed to automatically install dependencies.");
|
|
187523
|
+
console.warn(`Please run \`${packageManager.getInstallAllCommand()}\` manually.`);
|
|
187524
|
+
handleRegistryAuthError({ error, projectDir: projectRoot });
|
|
187525
|
+
throw error;
|
|
187526
|
+
}
|
|
187527
|
+
}
|
|
187528
|
+
|
|
187529
|
+
// cli/build/build-ci.ts
|
|
187530
|
+
var runCommand = (command, cwd) => {
|
|
187531
|
+
console.log(kleur_default.cyan(`Running: ${command}`));
|
|
187532
|
+
execSync3(command, { stdio: "inherit", cwd });
|
|
187533
|
+
};
|
|
187534
|
+
var applyCiBuildOptions = async ({
|
|
187535
|
+
projectDir,
|
|
187536
|
+
options
|
|
187537
|
+
}) => {
|
|
187538
|
+
if (!options?.ci) {
|
|
187539
|
+
return { resolvedOptions: options, handled: false };
|
|
187540
|
+
}
|
|
187541
|
+
await installProjectDependencies({ cwd: projectDir });
|
|
187542
|
+
const projectConfig = loadProjectConfig(projectDir);
|
|
187543
|
+
const prebuildCommand = projectConfig?.prebuildCommand?.trim();
|
|
187544
|
+
const buildCommand = projectConfig?.buildCommand?.trim();
|
|
187545
|
+
if (prebuildCommand) {
|
|
187546
|
+
runCommand(prebuildCommand, projectDir);
|
|
187547
|
+
}
|
|
187548
|
+
if (buildCommand) {
|
|
187549
|
+
runCommand(buildCommand, projectDir);
|
|
187550
|
+
return { resolvedOptions: options, handled: true };
|
|
187551
|
+
}
|
|
187552
|
+
return {
|
|
187553
|
+
resolvedOptions: {
|
|
187554
|
+
...options,
|
|
187555
|
+
previewImages: options?.previewImages ?? true,
|
|
187556
|
+
transpile: options?.transpile ?? true,
|
|
187557
|
+
site: options?.site ?? true,
|
|
187558
|
+
useCdnJavascript: options?.useCdnJavascript ?? true,
|
|
187559
|
+
ignoreErrors: options?.ignoreErrors ?? true
|
|
187560
|
+
},
|
|
187561
|
+
handled: false
|
|
187562
|
+
};
|
|
187563
|
+
};
|
|
187564
|
+
|
|
187565
|
+
// cli/build/get-build-entrypoints.ts
|
|
187566
|
+
import fs36 from "node:fs";
|
|
187567
|
+
import path37 from "node:path";
|
|
187433
187568
|
var isSubPath2 = (maybeChild, maybeParent) => {
|
|
187434
|
-
const relative10 =
|
|
187435
|
-
return relative10 === "" || !relative10.startsWith("..") && !
|
|
187569
|
+
const relative10 = path37.relative(maybeParent, maybeChild);
|
|
187570
|
+
return relative10 === "" || !relative10.startsWith("..") && !path37.isAbsolute(relative10);
|
|
187436
187571
|
};
|
|
187437
187572
|
var findProjectRoot = (startDir) => {
|
|
187438
187573
|
let currentDir = startDir;
|
|
187439
|
-
while (currentDir !==
|
|
187440
|
-
const packageJsonPath =
|
|
187441
|
-
if (
|
|
187574
|
+
while (currentDir !== path37.dirname(currentDir)) {
|
|
187575
|
+
const packageJsonPath = path37.join(currentDir, "package.json");
|
|
187576
|
+
if (fs36.existsSync(packageJsonPath)) {
|
|
187442
187577
|
return currentDir;
|
|
187443
187578
|
}
|
|
187444
|
-
currentDir =
|
|
187579
|
+
currentDir = path37.dirname(currentDir);
|
|
187445
187580
|
}
|
|
187446
187581
|
return startDir;
|
|
187447
187582
|
};
|
|
@@ -187450,11 +187585,11 @@ async function getBuildEntrypoints({
|
|
|
187450
187585
|
rootDir = process.cwd(),
|
|
187451
187586
|
includeBoardFiles = true
|
|
187452
187587
|
}) {
|
|
187453
|
-
const resolvedRoot =
|
|
187588
|
+
const resolvedRoot = path37.resolve(rootDir);
|
|
187454
187589
|
const includeBoardFilePatterns = includeBoardFiles ? getBoardFilePatterns(resolvedRoot) : [];
|
|
187455
187590
|
const buildFromProjectDir = async () => {
|
|
187456
187591
|
const projectConfig = loadProjectConfig(resolvedRoot);
|
|
187457
|
-
const resolvedPreviewComponentPath = projectConfig?.previewComponentPath ?
|
|
187592
|
+
const resolvedPreviewComponentPath = projectConfig?.previewComponentPath ? path37.resolve(resolvedRoot, projectConfig.previewComponentPath) : undefined;
|
|
187458
187593
|
if (includeBoardFiles) {
|
|
187459
187594
|
const files = findBoardFiles({ projectDir: resolvedRoot });
|
|
187460
187595
|
if (files.length > 0) {
|
|
@@ -187489,10 +187624,10 @@ async function getBuildEntrypoints({
|
|
|
187489
187624
|
};
|
|
187490
187625
|
};
|
|
187491
187626
|
if (fileOrDir) {
|
|
187492
|
-
const resolved =
|
|
187493
|
-
if (
|
|
187627
|
+
const resolved = path37.resolve(resolvedRoot, fileOrDir);
|
|
187628
|
+
if (fs36.existsSync(resolved) && fs36.statSync(resolved).isDirectory()) {
|
|
187494
187629
|
const projectConfig2 = loadProjectConfig(resolvedRoot);
|
|
187495
|
-
const resolvedPreviewComponentPath2 = projectConfig2?.previewComponentPath ?
|
|
187630
|
+
const resolvedPreviewComponentPath2 = projectConfig2?.previewComponentPath ? path37.resolve(resolvedRoot, projectConfig2.previewComponentPath) : undefined;
|
|
187496
187631
|
if (includeBoardFiles) {
|
|
187497
187632
|
const circuitFiles = findBoardFiles({
|
|
187498
187633
|
projectDir: resolvedRoot,
|
|
@@ -187524,10 +187659,10 @@ async function getBuildEntrypoints({
|
|
|
187524
187659
|
circuitFiles: mainEntrypoint ? [mainEntrypoint] : []
|
|
187525
187660
|
};
|
|
187526
187661
|
}
|
|
187527
|
-
const fileDir =
|
|
187662
|
+
const fileDir = path37.dirname(resolved);
|
|
187528
187663
|
const projectDir = findProjectRoot(fileDir);
|
|
187529
187664
|
const projectConfig = loadProjectConfig(projectDir);
|
|
187530
|
-
const resolvedPreviewComponentPath = projectConfig?.previewComponentPath ?
|
|
187665
|
+
const resolvedPreviewComponentPath = projectConfig?.previewComponentPath ? path37.resolve(projectDir, projectConfig.previewComponentPath) : undefined;
|
|
187531
187666
|
return {
|
|
187532
187667
|
projectDir,
|
|
187533
187668
|
previewComponentPath: resolvedPreviewComponentPath,
|
|
@@ -187569,8 +187704,8 @@ ${scriptBlock} <script src="https://cdn.tailwindcss.com"></script>
|
|
|
187569
187704
|
};
|
|
187570
187705
|
|
|
187571
187706
|
// cli/build/build-preview-images.ts
|
|
187572
|
-
import
|
|
187573
|
-
import
|
|
187707
|
+
import fs37 from "node:fs";
|
|
187708
|
+
import path38 from "node:path";
|
|
187574
187709
|
import {
|
|
187575
187710
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg2,
|
|
187576
187711
|
convertCircuitJsonToSchematicSvg as convertCircuitJsonToSchematicSvg2
|
|
@@ -187646,21 +187781,21 @@ var generatePreviewAssets = async ({
|
|
|
187646
187781
|
outputDir,
|
|
187647
187782
|
distDir
|
|
187648
187783
|
}) => {
|
|
187649
|
-
const prefixRelative =
|
|
187784
|
+
const prefixRelative = path38.relative(distDir, outputDir) || ".";
|
|
187650
187785
|
const prefix = prefixRelative === "." ? "" : `[${prefixRelative}] `;
|
|
187651
187786
|
let circuitJson;
|
|
187652
187787
|
try {
|
|
187653
|
-
const circuitJsonRaw =
|
|
187788
|
+
const circuitJsonRaw = fs37.readFileSync(build.outputPath, "utf-8");
|
|
187654
187789
|
circuitJson = JSON.parse(circuitJsonRaw);
|
|
187655
187790
|
} catch (error) {
|
|
187656
187791
|
console.error(`${prefix}Failed to read circuit JSON:`, error);
|
|
187657
187792
|
return;
|
|
187658
187793
|
}
|
|
187659
|
-
|
|
187794
|
+
fs37.mkdirSync(outputDir, { recursive: true });
|
|
187660
187795
|
try {
|
|
187661
187796
|
console.log(`${prefix}Generating PCB SVG...`);
|
|
187662
187797
|
const pcbSvg = convertCircuitJsonToPcbSvg2(circuitJson);
|
|
187663
|
-
|
|
187798
|
+
fs37.writeFileSync(path38.join(outputDir, "pcb.svg"), pcbSvg, "utf-8");
|
|
187664
187799
|
console.log(`${prefix}Written pcb.svg`);
|
|
187665
187800
|
} catch (error) {
|
|
187666
187801
|
console.error(`${prefix}Failed to generate PCB SVG:`, error);
|
|
@@ -187668,7 +187803,7 @@ var generatePreviewAssets = async ({
|
|
|
187668
187803
|
try {
|
|
187669
187804
|
console.log(`${prefix}Generating schematic SVG...`);
|
|
187670
187805
|
const schematicSvg = convertCircuitJsonToSchematicSvg2(circuitJson);
|
|
187671
|
-
|
|
187806
|
+
fs37.writeFileSync(path38.join(outputDir, "schematic.svg"), schematicSvg, "utf-8");
|
|
187672
187807
|
console.log(`${prefix}Written schematic.svg`);
|
|
187673
187808
|
} catch (error) {
|
|
187674
187809
|
console.error(`${prefix}Failed to generate schematic SVG:`, error);
|
|
@@ -187685,7 +187820,7 @@ var generatePreviewAssets = async ({
|
|
|
187685
187820
|
camPos: [10, 10, 10],
|
|
187686
187821
|
lookAt: [0, 0, 0]
|
|
187687
187822
|
});
|
|
187688
|
-
|
|
187823
|
+
fs37.writeFileSync(path38.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
|
|
187689
187824
|
console.log(`${prefix}Written 3d.png`);
|
|
187690
187825
|
} catch (error) {
|
|
187691
187826
|
console.error(`${prefix}Failed to generate 3D PNG:`, error);
|
|
@@ -187700,14 +187835,14 @@ var buildPreviewImages = async ({
|
|
|
187700
187835
|
}) => {
|
|
187701
187836
|
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
187702
187837
|
const previewEntrypoint = previewComponentPath || mainEntrypoint;
|
|
187703
|
-
const resolvedPreviewEntrypoint = previewEntrypoint ?
|
|
187838
|
+
const resolvedPreviewEntrypoint = previewEntrypoint ? path38.resolve(previewEntrypoint) : undefined;
|
|
187704
187839
|
if (allImages) {
|
|
187705
187840
|
if (successfulBuilds.length === 0) {
|
|
187706
187841
|
console.warn("No successful build output available for preview image generation.");
|
|
187707
187842
|
return;
|
|
187708
187843
|
}
|
|
187709
187844
|
for (const build of successfulBuilds) {
|
|
187710
|
-
const outputDir =
|
|
187845
|
+
const outputDir = path38.dirname(build.outputPath);
|
|
187711
187846
|
await generatePreviewAssets({
|
|
187712
187847
|
build,
|
|
187713
187848
|
outputDir,
|
|
@@ -187718,7 +187853,7 @@ var buildPreviewImages = async ({
|
|
|
187718
187853
|
}
|
|
187719
187854
|
const previewBuild = (() => {
|
|
187720
187855
|
if (resolvedPreviewEntrypoint) {
|
|
187721
|
-
const match = successfulBuilds.find((built) =>
|
|
187856
|
+
const match = successfulBuilds.find((built) => path38.resolve(built.sourcePath) === resolvedPreviewEntrypoint);
|
|
187722
187857
|
if (match)
|
|
187723
187858
|
return match;
|
|
187724
187859
|
}
|
|
@@ -187736,8 +187871,8 @@ var buildPreviewImages = async ({
|
|
|
187736
187871
|
};
|
|
187737
187872
|
|
|
187738
187873
|
// cli/build/build-preview-gltf.ts
|
|
187739
|
-
import
|
|
187740
|
-
import
|
|
187874
|
+
import fs38 from "node:fs";
|
|
187875
|
+
import path39 from "node:path";
|
|
187741
187876
|
import { convertCircuitJsonToGltf as convertCircuitJsonToGltf3 } from "circuit-json-to-gltf";
|
|
187742
187877
|
var buildPreviewGltf = async ({
|
|
187743
187878
|
builtFiles,
|
|
@@ -187747,10 +187882,10 @@ var buildPreviewGltf = async ({
|
|
|
187747
187882
|
}) => {
|
|
187748
187883
|
const successfulBuilds = builtFiles.filter((file) => file.ok);
|
|
187749
187884
|
const previewEntrypoint = previewComponentPath || mainEntrypoint;
|
|
187750
|
-
const resolvedPreviewEntrypoint = previewEntrypoint ?
|
|
187885
|
+
const resolvedPreviewEntrypoint = previewEntrypoint ? path39.resolve(previewEntrypoint) : undefined;
|
|
187751
187886
|
const previewBuild = (() => {
|
|
187752
187887
|
if (resolvedPreviewEntrypoint) {
|
|
187753
|
-
const match = successfulBuilds.find((built) =>
|
|
187888
|
+
const match = successfulBuilds.find((built) => path39.resolve(built.sourcePath) === resolvedPreviewEntrypoint);
|
|
187754
187889
|
if (match)
|
|
187755
187890
|
return match;
|
|
187756
187891
|
}
|
|
@@ -187762,16 +187897,16 @@ var buildPreviewGltf = async ({
|
|
|
187762
187897
|
}
|
|
187763
187898
|
let circuitJson;
|
|
187764
187899
|
try {
|
|
187765
|
-
const circuitJsonRaw =
|
|
187900
|
+
const circuitJsonRaw = fs38.readFileSync(previewBuild.outputPath, "utf-8");
|
|
187766
187901
|
circuitJson = JSON.parse(circuitJsonRaw);
|
|
187767
187902
|
} catch (error) {
|
|
187768
187903
|
console.error("Failed to read circuit JSON:", error);
|
|
187769
187904
|
return;
|
|
187770
187905
|
}
|
|
187771
187906
|
const sourcePath = previewBuild.sourcePath;
|
|
187772
|
-
const sourceBasename =
|
|
187907
|
+
const sourceBasename = path39.basename(sourcePath);
|
|
187773
187908
|
const gltfFilename = sourceBasename.replace(/(\.(board|circuit))?\.tsx?$/, ".gltf");
|
|
187774
|
-
const outputPath =
|
|
187909
|
+
const outputPath = path39.join(distDir, gltfFilename);
|
|
187775
187910
|
try {
|
|
187776
187911
|
console.log("Converting circuit to GLTF...");
|
|
187777
187912
|
const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
|
|
@@ -187779,7 +187914,7 @@ var buildPreviewGltf = async ({
|
|
|
187779
187914
|
format: "gltf"
|
|
187780
187915
|
});
|
|
187781
187916
|
const gltfContent = JSON.stringify(gltfData, null, 2);
|
|
187782
|
-
|
|
187917
|
+
fs38.writeFileSync(outputPath, gltfContent, "utf-8");
|
|
187783
187918
|
console.log(`Written ${gltfFilename}`);
|
|
187784
187919
|
} catch (error) {
|
|
187785
187920
|
console.error("Failed to generate GLTF:", error);
|
|
@@ -187787,8 +187922,8 @@ var buildPreviewGltf = async ({
|
|
|
187787
187922
|
};
|
|
187788
187923
|
|
|
187789
187924
|
// cli/build/generate-kicad-project.ts
|
|
187790
|
-
import
|
|
187791
|
-
import
|
|
187925
|
+
import fs39 from "node:fs";
|
|
187926
|
+
import path40 from "node:path";
|
|
187792
187927
|
var createKicadProContent = ({
|
|
187793
187928
|
projectName,
|
|
187794
187929
|
schematicFileName,
|
|
@@ -187828,10 +187963,10 @@ var generateKicadProject = async ({
|
|
|
187828
187963
|
boardFileName
|
|
187829
187964
|
});
|
|
187830
187965
|
if (writeFiles) {
|
|
187831
|
-
|
|
187832
|
-
|
|
187833
|
-
|
|
187834
|
-
|
|
187966
|
+
fs39.mkdirSync(outputDir, { recursive: true });
|
|
187967
|
+
fs39.writeFileSync(path40.join(outputDir, schematicFileName), schContent);
|
|
187968
|
+
fs39.writeFileSync(path40.join(outputDir, boardFileName), pcbContent);
|
|
187969
|
+
fs39.writeFileSync(path40.join(outputDir, projectFileName), proContent);
|
|
187835
187970
|
}
|
|
187836
187971
|
return {
|
|
187837
187972
|
pcbContent,
|
|
@@ -187843,8 +187978,8 @@ var generateKicadProject = async ({
|
|
|
187843
187978
|
};
|
|
187844
187979
|
|
|
187845
187980
|
// cli/build/transpile/index.ts
|
|
187846
|
-
import
|
|
187847
|
-
import
|
|
187981
|
+
import path42 from "node:path";
|
|
187982
|
+
import fs41 from "node:fs";
|
|
187848
187983
|
import { rollup } from "rollup";
|
|
187849
187984
|
import typescript from "@rollup/plugin-typescript";
|
|
187850
187985
|
import resolve11 from "@rollup/plugin-node-resolve";
|
|
@@ -187853,11 +187988,11 @@ import json from "@rollup/plugin-json";
|
|
|
187853
187988
|
import dts from "rollup-plugin-dts";
|
|
187854
187989
|
|
|
187855
187990
|
// cli/build/transpile/static-asset-plugin.ts
|
|
187856
|
-
import
|
|
187857
|
-
import
|
|
187991
|
+
import fs40 from "node:fs";
|
|
187992
|
+
import path41 from "node:path";
|
|
187858
187993
|
import { createHash } from "node:crypto";
|
|
187859
187994
|
function normalizePathSeparators(filePath) {
|
|
187860
|
-
return filePath.split(
|
|
187995
|
+
return filePath.split(path41.sep).join("/");
|
|
187861
187996
|
}
|
|
187862
187997
|
var STATIC_ASSET_EXTENSIONS = new Set([
|
|
187863
187998
|
".glb",
|
|
@@ -187888,24 +188023,24 @@ var createStaticAssetPlugin = ({
|
|
|
187888
188023
|
return {
|
|
187889
188024
|
name: "tsci-static-assets",
|
|
187890
188025
|
resolveId(source, importer) {
|
|
187891
|
-
const ext =
|
|
188026
|
+
const ext = path41.extname(source).toLowerCase();
|
|
187892
188027
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
187893
188028
|
return null;
|
|
187894
|
-
if (
|
|
187895
|
-
return
|
|
188029
|
+
if (path41.isAbsolute(source)) {
|
|
188030
|
+
return fs40.existsSync(source) ? { id: normalizePathSeparators(source), external: true } : null;
|
|
187896
188031
|
}
|
|
187897
188032
|
if (importer) {
|
|
187898
|
-
const importerNative = importer.split("/").join(
|
|
187899
|
-
const resolvedFromImporter =
|
|
187900
|
-
if (
|
|
188033
|
+
const importerNative = importer.split("/").join(path41.sep);
|
|
188034
|
+
const resolvedFromImporter = path41.resolve(path41.dirname(importerNative), source);
|
|
188035
|
+
if (fs40.existsSync(resolvedFromImporter)) {
|
|
187901
188036
|
return {
|
|
187902
188037
|
id: normalizePathSeparators(resolvedFromImporter),
|
|
187903
188038
|
external: true
|
|
187904
188039
|
};
|
|
187905
188040
|
}
|
|
187906
188041
|
}
|
|
187907
|
-
const resolvedFromProject =
|
|
187908
|
-
if (
|
|
188042
|
+
const resolvedFromProject = path41.resolve(resolvedBaseUrl, source);
|
|
188043
|
+
if (fs40.existsSync(resolvedFromProject)) {
|
|
187909
188044
|
return {
|
|
187910
188045
|
id: normalizePathSeparators(resolvedFromProject),
|
|
187911
188046
|
external: true
|
|
@@ -187918,8 +188053,8 @@ var createStaticAssetPlugin = ({
|
|
|
187918
188053
|
const wildcard = isWildcard ? source.slice(patternPrefix.length) : "";
|
|
187919
188054
|
for (const target of targets) {
|
|
187920
188055
|
const targetPath = isWildcard ? target.replace("*", wildcard) : target;
|
|
187921
|
-
const resolvedTarget =
|
|
187922
|
-
if (
|
|
188056
|
+
const resolvedTarget = path41.resolve(resolvedBaseUrl, targetPath);
|
|
188057
|
+
if (fs40.existsSync(resolvedTarget)) {
|
|
187923
188058
|
return {
|
|
187924
188059
|
id: normalizePathSeparators(resolvedTarget),
|
|
187925
188060
|
external: true
|
|
@@ -187945,18 +188080,18 @@ var createStaticAssetPlugin = ({
|
|
|
187945
188080
|
if (chunk.type !== "chunk")
|
|
187946
188081
|
continue;
|
|
187947
188082
|
for (const importedId of chunk.imports) {
|
|
187948
|
-
const ext =
|
|
188083
|
+
const ext = path41.extname(importedId).toLowerCase();
|
|
187949
188084
|
if (!STATIC_ASSET_EXTENSIONS.has(ext))
|
|
187950
188085
|
continue;
|
|
187951
188086
|
if (!copiedAssets.has(importedId)) {
|
|
187952
|
-
const assetDir =
|
|
187953
|
-
|
|
187954
|
-
const nativePath = importedId.split("/").join(
|
|
187955
|
-
const fileBuffer =
|
|
188087
|
+
const assetDir = path41.join(outputDir, "assets");
|
|
188088
|
+
fs40.mkdirSync(assetDir, { recursive: true });
|
|
188089
|
+
const nativePath = importedId.split("/").join(path41.sep);
|
|
188090
|
+
const fileBuffer = fs40.readFileSync(nativePath);
|
|
187956
188091
|
const hash = createHash("sha1").update(fileBuffer).digest("hex").slice(0, 8);
|
|
187957
|
-
const fileName = `${
|
|
187958
|
-
const outputFilePath =
|
|
187959
|
-
|
|
188092
|
+
const fileName = `${path41.basename(importedId, ext)}-${hash}${ext}`;
|
|
188093
|
+
const outputFilePath = path41.join(assetDir, fileName);
|
|
188094
|
+
fs40.writeFileSync(outputFilePath, fileBuffer);
|
|
187960
188095
|
copiedAssets.set(importedId, `./assets/${fileName}`);
|
|
187961
188096
|
assetIdToOutputPath.set(importedId, `./assets/${fileName}`);
|
|
187962
188097
|
}
|
|
@@ -187978,17 +188113,17 @@ function escapeRegExp(string) {
|
|
|
187978
188113
|
|
|
187979
188114
|
// cli/build/transpile/index.ts
|
|
187980
188115
|
var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
|
|
187981
|
-
if (id2.startsWith(".") || id2.startsWith("/") ||
|
|
188116
|
+
if (id2.startsWith(".") || id2.startsWith("/") || path42.isAbsolute(id2)) {
|
|
187982
188117
|
return false;
|
|
187983
188118
|
}
|
|
187984
188119
|
let baseUrl = projectDir;
|
|
187985
188120
|
let pathMappings = {};
|
|
187986
|
-
if (tsconfigPath &&
|
|
188121
|
+
if (tsconfigPath && fs41.existsSync(tsconfigPath)) {
|
|
187987
188122
|
try {
|
|
187988
|
-
const tsconfigContent =
|
|
188123
|
+
const tsconfigContent = fs41.readFileSync(tsconfigPath, "utf-8");
|
|
187989
188124
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
187990
188125
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
187991
|
-
baseUrl =
|
|
188126
|
+
baseUrl = path42.resolve(path42.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
187992
188127
|
}
|
|
187993
188128
|
if (tsconfig.compilerOptions?.paths) {
|
|
187994
188129
|
pathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -188002,17 +188137,17 @@ var createExternalFunction = (projectDir, tsconfigPath) => (id2) => {
|
|
|
188002
188137
|
}
|
|
188003
188138
|
}
|
|
188004
188139
|
const potentialPaths = [
|
|
188005
|
-
|
|
188006
|
-
|
|
188007
|
-
|
|
188008
|
-
|
|
188009
|
-
|
|
188010
|
-
|
|
188011
|
-
|
|
188012
|
-
|
|
188013
|
-
|
|
188140
|
+
path42.join(baseUrl, id2),
|
|
188141
|
+
path42.join(baseUrl, `${id2}.ts`),
|
|
188142
|
+
path42.join(baseUrl, `${id2}.tsx`),
|
|
188143
|
+
path42.join(baseUrl, `${id2}.js`),
|
|
188144
|
+
path42.join(baseUrl, `${id2}.jsx`),
|
|
188145
|
+
path42.join(baseUrl, id2, "index.ts"),
|
|
188146
|
+
path42.join(baseUrl, id2, "index.tsx"),
|
|
188147
|
+
path42.join(baseUrl, id2, "index.js"),
|
|
188148
|
+
path42.join(baseUrl, id2, "index.jsx")
|
|
188014
188149
|
];
|
|
188015
|
-
if (potentialPaths.some((p) =>
|
|
188150
|
+
if (potentialPaths.some((p) => fs41.existsSync(p))) {
|
|
188016
188151
|
return false;
|
|
188017
188152
|
}
|
|
188018
188153
|
return true;
|
|
@@ -188023,17 +188158,17 @@ var transpileFile = async ({
|
|
|
188023
188158
|
projectDir
|
|
188024
188159
|
}) => {
|
|
188025
188160
|
try {
|
|
188026
|
-
|
|
188027
|
-
const tsconfigPath =
|
|
188028
|
-
const hasTsConfig =
|
|
188161
|
+
fs41.mkdirSync(outputDir, { recursive: true });
|
|
188162
|
+
const tsconfigPath = path42.join(projectDir, "tsconfig.json");
|
|
188163
|
+
const hasTsConfig = fs41.existsSync(tsconfigPath);
|
|
188029
188164
|
let tsconfigBaseUrl = projectDir;
|
|
188030
188165
|
let tsconfigPathMappings;
|
|
188031
188166
|
if (hasTsConfig) {
|
|
188032
188167
|
try {
|
|
188033
|
-
const tsconfigContent =
|
|
188168
|
+
const tsconfigContent = fs41.readFileSync(tsconfigPath, "utf-8");
|
|
188034
188169
|
const tsconfig = JSON.parse(tsconfigContent);
|
|
188035
188170
|
if (tsconfig.compilerOptions?.baseUrl) {
|
|
188036
|
-
tsconfigBaseUrl =
|
|
188171
|
+
tsconfigBaseUrl = path42.resolve(path42.dirname(tsconfigPath), tsconfig.compilerOptions.baseUrl);
|
|
188037
188172
|
}
|
|
188038
188173
|
if (tsconfig.compilerOptions?.paths) {
|
|
188039
188174
|
tsconfigPathMappings = tsconfig.compilerOptions.paths;
|
|
@@ -188088,27 +188223,27 @@ var transpileFile = async ({
|
|
|
188088
188223
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
188089
188224
|
plugins: getPlugins()
|
|
188090
188225
|
});
|
|
188091
|
-
const esmOutputPath =
|
|
188226
|
+
const esmOutputPath = path42.join(outputDir, "index.js");
|
|
188092
188227
|
await esmBundle.write({
|
|
188093
188228
|
file: esmOutputPath,
|
|
188094
188229
|
format: "es",
|
|
188095
188230
|
sourcemap: false
|
|
188096
188231
|
});
|
|
188097
|
-
console.log(`ESM bundle written to ${
|
|
188232
|
+
console.log(`ESM bundle written to ${path42.relative(projectDir, esmOutputPath)}`);
|
|
188098
188233
|
console.log("Building CommonJS bundle...");
|
|
188099
188234
|
const cjsBundle = await rollup({
|
|
188100
188235
|
input,
|
|
188101
188236
|
external: createExternalFunction(projectDir, hasTsConfig ? tsconfigPath : undefined),
|
|
188102
188237
|
plugins: getPlugins()
|
|
188103
188238
|
});
|
|
188104
|
-
const cjsOutputPath =
|
|
188239
|
+
const cjsOutputPath = path42.join(outputDir, "index.cjs");
|
|
188105
188240
|
console.log("Writing CJS bundle to:", cjsOutputPath);
|
|
188106
188241
|
await cjsBundle.write({
|
|
188107
188242
|
file: cjsOutputPath,
|
|
188108
188243
|
format: "cjs",
|
|
188109
188244
|
sourcemap: false
|
|
188110
188245
|
});
|
|
188111
|
-
console.log(`CommonJS bundle written to ${
|
|
188246
|
+
console.log(`CommonJS bundle written to ${path42.relative(projectDir, cjsOutputPath)}`);
|
|
188112
188247
|
console.log("Generating type declarations...");
|
|
188113
188248
|
const dtsBundle = await rollup({
|
|
188114
188249
|
input,
|
|
@@ -188133,9 +188268,9 @@ var transpileFile = async ({
|
|
|
188133
188268
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
188134
188269
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
188135
188270
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
188136
|
-
const dtsOutputPath =
|
|
188137
|
-
|
|
188138
|
-
console.log(`Type declarations written to ${
|
|
188271
|
+
const dtsOutputPath = path42.join(outputDir, "index.d.ts");
|
|
188272
|
+
fs41.writeFileSync(dtsOutputPath, dtsContent);
|
|
188273
|
+
console.log(`Type declarations written to ${path42.relative(projectDir, dtsOutputPath)}`);
|
|
188139
188274
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
188140
188275
|
return true;
|
|
188141
188276
|
} catch (err) {
|
|
@@ -188148,17 +188283,17 @@ var transpileFile = async ({
|
|
|
188148
188283
|
};
|
|
188149
188284
|
|
|
188150
188285
|
// cli/utils/validate-main-in-dist.ts
|
|
188151
|
-
import
|
|
188152
|
-
import
|
|
188286
|
+
import fs42 from "node:fs";
|
|
188287
|
+
import path43 from "node:path";
|
|
188153
188288
|
var validateMainInDist = (projectDir, distDir) => {
|
|
188154
|
-
const packageJsonPath =
|
|
188155
|
-
if (!
|
|
188289
|
+
const packageJsonPath = path43.join(projectDir, "package.json");
|
|
188290
|
+
if (!fs42.existsSync(packageJsonPath))
|
|
188156
188291
|
return;
|
|
188157
|
-
const packageJson = JSON.parse(
|
|
188292
|
+
const packageJson = JSON.parse(fs42.readFileSync(packageJsonPath, "utf-8"));
|
|
188158
188293
|
if (typeof packageJson.main !== "string")
|
|
188159
188294
|
return;
|
|
188160
|
-
const resolvedMainPath =
|
|
188161
|
-
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${
|
|
188295
|
+
const resolvedMainPath = path43.resolve(projectDir, packageJson.main);
|
|
188296
|
+
const isMainInDist = resolvedMainPath === distDir || resolvedMainPath.startsWith(`${distDir}${path43.sep}`);
|
|
188162
188297
|
if (!isMainInDist) {
|
|
188163
188298
|
console.warn('When using transpilation, your package\'s "main" field should point inside the `dist/*` directory, usually to "dist/index.js"');
|
|
188164
188299
|
}
|
|
@@ -188181,7 +188316,7 @@ async function getLatestTscircuitCdnUrl() {
|
|
|
188181
188316
|
|
|
188182
188317
|
// cli/build/register.ts
|
|
188183
188318
|
var registerBuild = (program3) => {
|
|
188184
|
-
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad", "Generate KiCad project directories for each successful build output").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").action(async (file, options) => {
|
|
188319
|
+
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("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").action(async (file, options) => {
|
|
188185
188320
|
try {
|
|
188186
188321
|
const {
|
|
188187
188322
|
projectDir,
|
|
@@ -188191,34 +188326,42 @@ var registerBuild = (program3) => {
|
|
|
188191
188326
|
} = await getBuildEntrypoints({
|
|
188192
188327
|
fileOrDir: file
|
|
188193
188328
|
});
|
|
188329
|
+
const { resolvedOptions, handled } = await applyCiBuildOptions({
|
|
188330
|
+
projectDir,
|
|
188331
|
+
options
|
|
188332
|
+
});
|
|
188333
|
+
if (handled) {
|
|
188334
|
+
return;
|
|
188335
|
+
}
|
|
188194
188336
|
const platformConfig2 = (() => {
|
|
188195
|
-
if (!
|
|
188337
|
+
if (!resolvedOptions?.disablePcb && !resolvedOptions?.disablePartsEngine) {
|
|
188196
188338
|
return;
|
|
188339
|
+
}
|
|
188197
188340
|
const config = {};
|
|
188198
|
-
if (
|
|
188341
|
+
if (resolvedOptions?.disablePcb) {
|
|
188199
188342
|
config.pcbDisabled = true;
|
|
188200
188343
|
}
|
|
188201
|
-
if (
|
|
188344
|
+
if (resolvedOptions?.disablePartsEngine) {
|
|
188202
188345
|
config.partsEngineDisabled = true;
|
|
188203
188346
|
}
|
|
188204
188347
|
return config;
|
|
188205
188348
|
})();
|
|
188206
|
-
const distDir =
|
|
188207
|
-
|
|
188349
|
+
const distDir = path44.join(projectDir, "dist");
|
|
188350
|
+
fs43.mkdirSync(distDir, { recursive: true });
|
|
188208
188351
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
188209
188352
|
let hasErrors = false;
|
|
188210
188353
|
const staticFileReferences = [];
|
|
188211
188354
|
const builtFiles = [];
|
|
188212
188355
|
const kicadProjects = [];
|
|
188213
|
-
const shouldGenerateKicad =
|
|
188356
|
+
const shouldGenerateKicad = resolvedOptions?.kicad || resolvedOptions?.kicadFootprintLibrary;
|
|
188214
188357
|
for (const filePath of circuitFiles) {
|
|
188215
|
-
const relative10 =
|
|
188358
|
+
const relative10 = path44.relative(projectDir, filePath);
|
|
188216
188359
|
console.log(`Building ${relative10}...`);
|
|
188217
188360
|
const outputDirName = relative10.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
188218
|
-
const outputPath =
|
|
188361
|
+
const outputPath = path44.join(distDir, outputDirName, "circuit.json");
|
|
188219
188362
|
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
188220
|
-
ignoreErrors:
|
|
188221
|
-
ignoreWarnings:
|
|
188363
|
+
ignoreErrors: resolvedOptions?.ignoreErrors,
|
|
188364
|
+
ignoreWarnings: resolvedOptions?.ignoreWarnings,
|
|
188222
188365
|
platformConfig: platformConfig2
|
|
188223
188366
|
});
|
|
188224
188367
|
builtFiles.push({
|
|
@@ -188228,23 +188371,23 @@ var registerBuild = (program3) => {
|
|
|
188228
188371
|
});
|
|
188229
188372
|
if (!buildOutcome.ok) {
|
|
188230
188373
|
hasErrors = true;
|
|
188231
|
-
} else if (
|
|
188232
|
-
const normalizedSourcePath = relative10.split(
|
|
188233
|
-
const relativeOutputPath =
|
|
188234
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
188374
|
+
} else if (resolvedOptions?.site) {
|
|
188375
|
+
const normalizedSourcePath = relative10.split(path44.sep).join("/");
|
|
188376
|
+
const relativeOutputPath = path44.join(outputDirName, "circuit.json");
|
|
188377
|
+
const normalizedOutputPath = relativeOutputPath.split(path44.sep).join("/");
|
|
188235
188378
|
staticFileReferences.push({
|
|
188236
188379
|
filePath: normalizedSourcePath,
|
|
188237
188380
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
188238
188381
|
});
|
|
188239
188382
|
}
|
|
188240
188383
|
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
188241
|
-
const projectOutputDir =
|
|
188242
|
-
const projectName =
|
|
188384
|
+
const projectOutputDir = path44.join(distDir, outputDirName, "kicad");
|
|
188385
|
+
const projectName = path44.basename(outputDirName);
|
|
188243
188386
|
const project = await generateKicadProject({
|
|
188244
188387
|
circuitJson: buildOutcome.circuitJson,
|
|
188245
188388
|
outputDir: projectOutputDir,
|
|
188246
188389
|
projectName,
|
|
188247
|
-
writeFiles: Boolean(
|
|
188390
|
+
writeFiles: Boolean(resolvedOptions?.kicad)
|
|
188248
188391
|
});
|
|
188249
188392
|
kicadProjects.push({
|
|
188250
188393
|
...project,
|
|
@@ -188252,21 +188395,21 @@ var registerBuild = (program3) => {
|
|
|
188252
188395
|
});
|
|
188253
188396
|
}
|
|
188254
188397
|
}
|
|
188255
|
-
if (hasErrors && !
|
|
188398
|
+
if (hasErrors && !resolvedOptions?.ignoreErrors) {
|
|
188256
188399
|
process.exit(1);
|
|
188257
188400
|
}
|
|
188258
|
-
const shouldGeneratePreviewImages =
|
|
188401
|
+
const shouldGeneratePreviewImages = resolvedOptions?.previewImages || resolvedOptions?.allImages;
|
|
188259
188402
|
if (shouldGeneratePreviewImages) {
|
|
188260
|
-
console.log(
|
|
188403
|
+
console.log(resolvedOptions?.allImages ? "Generating preview images for all builds..." : "Generating preview images...");
|
|
188261
188404
|
await buildPreviewImages({
|
|
188262
188405
|
builtFiles,
|
|
188263
188406
|
distDir,
|
|
188264
188407
|
mainEntrypoint,
|
|
188265
188408
|
previewComponentPath,
|
|
188266
|
-
allImages:
|
|
188409
|
+
allImages: resolvedOptions?.allImages
|
|
188267
188410
|
});
|
|
188268
188411
|
}
|
|
188269
|
-
if (
|
|
188412
|
+
if (resolvedOptions?.previewGltf) {
|
|
188270
188413
|
console.log("Generating preview GLTF...");
|
|
188271
188414
|
await buildPreviewGltf({
|
|
188272
188415
|
builtFiles,
|
|
@@ -188275,7 +188418,7 @@ var registerBuild = (program3) => {
|
|
|
188275
188418
|
previewComponentPath
|
|
188276
188419
|
});
|
|
188277
188420
|
}
|
|
188278
|
-
if (
|
|
188421
|
+
if (resolvedOptions?.transpile) {
|
|
188279
188422
|
validateMainInDist(projectDir, distDir);
|
|
188280
188423
|
console.log("Transpiling entry file...");
|
|
188281
188424
|
const { mainEntrypoint: transpileEntrypoint } = await getBuildEntrypoints({
|
|
@@ -188297,28 +188440,28 @@ var registerBuild = (program3) => {
|
|
|
188297
188440
|
process.exit(1);
|
|
188298
188441
|
}
|
|
188299
188442
|
}
|
|
188300
|
-
if (
|
|
188443
|
+
if (resolvedOptions?.site) {
|
|
188301
188444
|
let standaloneScriptSrc = "./standalone.min.js";
|
|
188302
|
-
if (
|
|
188445
|
+
if (resolvedOptions?.useCdnJavascript) {
|
|
188303
188446
|
standaloneScriptSrc = await getLatestTscircuitCdnUrl();
|
|
188304
188447
|
} else {
|
|
188305
|
-
|
|
188448
|
+
fs43.writeFileSync(path44.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
188306
188449
|
}
|
|
188307
188450
|
const indexHtml = getStaticIndexHtmlFile({
|
|
188308
188451
|
files: staticFileReferences,
|
|
188309
188452
|
standaloneScriptSrc
|
|
188310
188453
|
});
|
|
188311
|
-
|
|
188454
|
+
fs43.writeFileSync(path44.join(distDir, "index.html"), indexHtml);
|
|
188312
188455
|
}
|
|
188313
188456
|
const successCount = builtFiles.filter((f) => f.ok).length;
|
|
188314
188457
|
const failCount = builtFiles.length - successCount;
|
|
188315
188458
|
const enabledOpts = [
|
|
188316
|
-
|
|
188317
|
-
|
|
188318
|
-
|
|
188319
|
-
|
|
188320
|
-
|
|
188321
|
-
|
|
188459
|
+
resolvedOptions?.site && "site",
|
|
188460
|
+
resolvedOptions?.transpile && "transpile",
|
|
188461
|
+
resolvedOptions?.previewImages && "preview-images",
|
|
188462
|
+
resolvedOptions?.allImages && "all-images",
|
|
188463
|
+
resolvedOptions?.kicad && "kicad",
|
|
188464
|
+
resolvedOptions?.previewGltf && "preview-gltf"
|
|
188322
188465
|
].filter(Boolean);
|
|
188323
188466
|
console.log("");
|
|
188324
188467
|
console.log(kleur_default.bold("Build complete"));
|
|
@@ -188326,7 +188469,7 @@ var registerBuild = (program3) => {
|
|
|
188326
188469
|
if (enabledOpts.length > 0) {
|
|
188327
188470
|
console.log(` Options ${kleur_default.cyan(enabledOpts.join(", "))}`);
|
|
188328
188471
|
}
|
|
188329
|
-
console.log(` Output ${kleur_default.dim(
|
|
188472
|
+
console.log(` Output ${kleur_default.dim(path44.relative(process.cwd(), distDir) || "dist")}`);
|
|
188330
188473
|
console.log(hasErrors ? kleur_default.yellow(`
|
|
188331
188474
|
⚠ Build completed with errors`) : kleur_default.green(`
|
|
188332
188475
|
✓ Done`));
|
|
@@ -188340,8 +188483,8 @@ var registerBuild = (program3) => {
|
|
|
188340
188483
|
};
|
|
188341
188484
|
|
|
188342
188485
|
// lib/shared/snapshot-project.ts
|
|
188343
|
-
import
|
|
188344
|
-
import
|
|
188486
|
+
import fs45 from "node:fs";
|
|
188487
|
+
import path45 from "node:path";
|
|
188345
188488
|
import looksSame2 from "looks-same";
|
|
188346
188489
|
import {
|
|
188347
188490
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -188352,7 +188495,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
188352
188495
|
|
|
188353
188496
|
// lib/shared/compare-images.ts
|
|
188354
188497
|
import looksSame from "looks-same";
|
|
188355
|
-
import
|
|
188498
|
+
import fs44 from "node:fs/promises";
|
|
188356
188499
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
188357
188500
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
188358
188501
|
strict: false,
|
|
@@ -188368,7 +188511,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
188368
188511
|
tolerance: 2
|
|
188369
188512
|
});
|
|
188370
188513
|
} else {
|
|
188371
|
-
await
|
|
188514
|
+
await fs44.writeFile(diffPath, buffer2);
|
|
188372
188515
|
}
|
|
188373
188516
|
}
|
|
188374
188517
|
return { equal: equal2 };
|
|
@@ -188393,7 +188536,7 @@ var snapshotProject = async ({
|
|
|
188393
188536
|
...DEFAULT_IGNORED_PATTERNS,
|
|
188394
188537
|
...ignored.map(normalizeIgnorePattern)
|
|
188395
188538
|
];
|
|
188396
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
188539
|
+
const resolvedPaths = filePaths.map((f) => path45.resolve(projectDir, f));
|
|
188397
188540
|
const boardFiles = findBoardFiles({
|
|
188398
188541
|
projectDir,
|
|
188399
188542
|
ignore,
|
|
@@ -188407,7 +188550,7 @@ var snapshotProject = async ({
|
|
|
188407
188550
|
const mismatches = [];
|
|
188408
188551
|
let didUpdate = false;
|
|
188409
188552
|
for (const file of boardFiles) {
|
|
188410
|
-
const relativeFilePath =
|
|
188553
|
+
const relativeFilePath = path45.relative(projectDir, file);
|
|
188411
188554
|
let circuitJson;
|
|
188412
188555
|
let pcbSvg;
|
|
188413
188556
|
let schSvg;
|
|
@@ -188462,17 +188605,17 @@ var snapshotProject = async ({
|
|
|
188462
188605
|
} catch (error) {
|
|
188463
188606
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
188464
188607
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
188465
|
-
const fileDir =
|
|
188466
|
-
const relativeDir =
|
|
188467
|
-
const snapDir2 = snapshotsDirName ?
|
|
188468
|
-
const base2 =
|
|
188469
|
-
const snap3dPath =
|
|
188470
|
-
const existing3dSnapshot =
|
|
188608
|
+
const fileDir = path45.dirname(file);
|
|
188609
|
+
const relativeDir = path45.relative(projectDir, fileDir);
|
|
188610
|
+
const snapDir2 = snapshotsDirName ? path45.join(projectDir, snapshotsDirName, relativeDir) : path45.join(fileDir, "__snapshots__");
|
|
188611
|
+
const base2 = path45.basename(file).replace(/\.tsx$/, "");
|
|
188612
|
+
const snap3dPath = path45.join(snapDir2, `${base2}-3d.snap.png`);
|
|
188613
|
+
const existing3dSnapshot = fs45.existsSync(snap3dPath);
|
|
188471
188614
|
if (existing3dSnapshot) {
|
|
188472
188615
|
onError(kleur_default.red(`
|
|
188473
188616
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
188474
188617
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
188475
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
188618
|
+
`) + kleur_default.red(` Existing snapshot: ${path45.relative(projectDir, snap3dPath)}
|
|
188476
188619
|
`));
|
|
188477
188620
|
return onExit2(1);
|
|
188478
188621
|
} else {
|
|
@@ -188488,9 +188631,9 @@ var snapshotProject = async ({
|
|
|
188488
188631
|
}
|
|
188489
188632
|
}
|
|
188490
188633
|
}
|
|
188491
|
-
const snapDir = snapshotsDirName ?
|
|
188492
|
-
|
|
188493
|
-
const base =
|
|
188634
|
+
const snapDir = snapshotsDirName ? path45.join(projectDir, snapshotsDirName, path45.relative(projectDir, path45.dirname(file))) : path45.join(path45.dirname(file), "__snapshots__");
|
|
188635
|
+
fs45.mkdirSync(snapDir, { recursive: true });
|
|
188636
|
+
const base = path45.basename(file).replace(/\.tsx$/, "");
|
|
188494
188637
|
const snapshots = [];
|
|
188495
188638
|
if (pcbOnly || !schematicOnly) {
|
|
188496
188639
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -188508,31 +188651,31 @@ var snapshotProject = async ({
|
|
|
188508
188651
|
for (const snapshot of snapshots) {
|
|
188509
188652
|
const { type } = snapshot;
|
|
188510
188653
|
const is3d = type === "3d";
|
|
188511
|
-
const snapPath =
|
|
188512
|
-
const existing =
|
|
188654
|
+
const snapPath = path45.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
188655
|
+
const existing = fs45.existsSync(snapPath);
|
|
188513
188656
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
188514
188657
|
const newContentForFile = snapshot.content;
|
|
188515
188658
|
if (!existing) {
|
|
188516
|
-
|
|
188517
|
-
console.log("✅", kleur_default.gray(
|
|
188659
|
+
fs45.writeFileSync(snapPath, newContentForFile);
|
|
188660
|
+
console.log("✅", kleur_default.gray(path45.relative(projectDir, snapPath)));
|
|
188518
188661
|
didUpdate = true;
|
|
188519
188662
|
continue;
|
|
188520
188663
|
}
|
|
188521
|
-
const oldContentBuffer =
|
|
188664
|
+
const oldContentBuffer = fs45.readFileSync(snapPath);
|
|
188522
188665
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
188523
188666
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
188524
188667
|
if (update) {
|
|
188525
188668
|
if (!forceUpdate && equal2) {
|
|
188526
|
-
console.log("✅", kleur_default.gray(
|
|
188669
|
+
console.log("✅", kleur_default.gray(path45.relative(projectDir, snapPath)));
|
|
188527
188670
|
} else {
|
|
188528
|
-
|
|
188529
|
-
console.log("✅", kleur_default.gray(
|
|
188671
|
+
fs45.writeFileSync(snapPath, newContentForFile);
|
|
188672
|
+
console.log("✅", kleur_default.gray(path45.relative(projectDir, snapPath)));
|
|
188530
188673
|
didUpdate = true;
|
|
188531
188674
|
}
|
|
188532
188675
|
} else if (!equal2) {
|
|
188533
188676
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
188534
188677
|
} else {
|
|
188535
|
-
console.log("✅", kleur_default.gray(
|
|
188678
|
+
console.log("✅", kleur_default.gray(path45.relative(projectDir, snapPath)));
|
|
188536
188679
|
}
|
|
188537
188680
|
}
|
|
188538
188681
|
}
|
|
@@ -188571,22 +188714,22 @@ var registerSnapshot = (program3) => {
|
|
|
188571
188714
|
};
|
|
188572
188715
|
|
|
188573
188716
|
// lib/shared/setup-github-actions.ts
|
|
188574
|
-
import
|
|
188575
|
-
import
|
|
188717
|
+
import fs46 from "node:fs";
|
|
188718
|
+
import path46 from "node:path";
|
|
188576
188719
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
188577
188720
|
const findGitRoot = (startDir) => {
|
|
188578
|
-
let dir =
|
|
188579
|
-
while (dir !==
|
|
188580
|
-
if (
|
|
188721
|
+
let dir = path46.resolve(startDir);
|
|
188722
|
+
while (dir !== path46.parse(dir).root) {
|
|
188723
|
+
if (fs46.existsSync(path46.join(dir, ".git"))) {
|
|
188581
188724
|
return dir;
|
|
188582
188725
|
}
|
|
188583
|
-
dir =
|
|
188726
|
+
dir = path46.dirname(dir);
|
|
188584
188727
|
}
|
|
188585
188728
|
return null;
|
|
188586
188729
|
};
|
|
188587
188730
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
188588
|
-
const workflowsDir =
|
|
188589
|
-
|
|
188731
|
+
const workflowsDir = path46.join(gitRoot, ".github", "workflows");
|
|
188732
|
+
fs46.mkdirSync(workflowsDir, { recursive: true });
|
|
188590
188733
|
const buildWorkflow = `name: tscircuit Build
|
|
188591
188734
|
|
|
188592
188735
|
on:
|
|
@@ -188625,8 +188768,8 @@ jobs:
|
|
|
188625
188768
|
- run: bun install
|
|
188626
188769
|
- run: bunx tsci snapshot
|
|
188627
188770
|
`;
|
|
188628
|
-
writeFileIfNotExists(
|
|
188629
|
-
writeFileIfNotExists(
|
|
188771
|
+
writeFileIfNotExists(path46.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
188772
|
+
writeFileIfNotExists(path46.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
188630
188773
|
};
|
|
188631
188774
|
|
|
188632
188775
|
// cli/setup/register.ts
|
|
@@ -188664,8 +188807,8 @@ function registerAuthSetupNpmrc(program3) {
|
|
|
188664
188807
|
}
|
|
188665
188808
|
|
|
188666
188809
|
// cli/convert/register.ts
|
|
188667
|
-
import
|
|
188668
|
-
import
|
|
188810
|
+
import fs47 from "node:fs/promises";
|
|
188811
|
+
import path47 from "node:path";
|
|
188669
188812
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
188670
188813
|
|
|
188671
188814
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -188785,15 +188928,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
188785
188928
|
var registerConvert = (program3) => {
|
|
188786
188929
|
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) => {
|
|
188787
188930
|
try {
|
|
188788
|
-
const inputPath =
|
|
188789
|
-
const modContent = await
|
|
188931
|
+
const inputPath = path47.resolve(file);
|
|
188932
|
+
const modContent = await fs47.readFile(inputPath, "utf-8");
|
|
188790
188933
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
188791
|
-
const componentName = options.name ??
|
|
188934
|
+
const componentName = options.name ?? path47.basename(inputPath, ".kicad_mod");
|
|
188792
188935
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
188793
188936
|
componentName
|
|
188794
188937
|
});
|
|
188795
|
-
const outputPath = options.output ?
|
|
188796
|
-
await
|
|
188938
|
+
const outputPath = options.output ? path47.resolve(options.output) : path47.join(path47.dirname(inputPath), `${componentName}.tsx`);
|
|
188939
|
+
await fs47.writeFile(outputPath, tsx);
|
|
188797
188940
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
188798
188941
|
} catch (error) {
|
|
188799
188942
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -188888,102 +189031,6 @@ var registerSimulate = (program3) => {
|
|
|
188888
189031
|
});
|
|
188889
189032
|
};
|
|
188890
189033
|
|
|
188891
|
-
// lib/shared/install-project-dependencies.ts
|
|
188892
|
-
import fs47 from "node:fs";
|
|
188893
|
-
import path47 from "node:path";
|
|
188894
|
-
|
|
188895
|
-
// lib/shared/collect-tsci-dependencies.ts
|
|
188896
|
-
import fs46 from "node:fs";
|
|
188897
|
-
import path46 from "node:path";
|
|
188898
|
-
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
188899
|
-
var DEFAULT_IGNORES = [
|
|
188900
|
-
"**/node_modules/**",
|
|
188901
|
-
"**/.git/**",
|
|
188902
|
-
"**/dist/**",
|
|
188903
|
-
"**/build/**",
|
|
188904
|
-
"**/.tsci/**"
|
|
188905
|
-
];
|
|
188906
|
-
var IMPORT_PATTERN = /["'`](@tsci\/[A-Za-z0-9._/-]+)["'`]/g;
|
|
188907
|
-
function collectTsciDependencies({
|
|
188908
|
-
cwd = process.cwd(),
|
|
188909
|
-
patterns = DEFAULT_PATTERNS,
|
|
188910
|
-
ignore = DEFAULT_IGNORES
|
|
188911
|
-
} = {}) {
|
|
188912
|
-
const searchRoot = path46.resolve(cwd);
|
|
188913
|
-
const files = globbySync(patterns, {
|
|
188914
|
-
cwd: searchRoot,
|
|
188915
|
-
absolute: true,
|
|
188916
|
-
ignore,
|
|
188917
|
-
gitignore: true
|
|
188918
|
-
});
|
|
188919
|
-
const dependencies2 = new Set;
|
|
188920
|
-
for (const filePath of files) {
|
|
188921
|
-
try {
|
|
188922
|
-
const fileContents = fs46.readFileSync(filePath, "utf-8");
|
|
188923
|
-
let match;
|
|
188924
|
-
while (true) {
|
|
188925
|
-
match = IMPORT_PATTERN.exec(fileContents);
|
|
188926
|
-
if (match === null)
|
|
188927
|
-
break;
|
|
188928
|
-
dependencies2.add(match[1]);
|
|
188929
|
-
}
|
|
188930
|
-
} catch (error) {}
|
|
188931
|
-
}
|
|
188932
|
-
return Array.from(dependencies2);
|
|
188933
|
-
}
|
|
188934
|
-
|
|
188935
|
-
// lib/shared/install-project-dependencies.ts
|
|
188936
|
-
async function installProjectDependencies({
|
|
188937
|
-
cwd = process.cwd()
|
|
188938
|
-
} = {}) {
|
|
188939
|
-
const projectRoot = path47.resolve(cwd);
|
|
188940
|
-
const packageJsonPath = path47.join(projectRoot, "package.json");
|
|
188941
|
-
const npmrcPath = path47.join(projectRoot, ".npmrc");
|
|
188942
|
-
const packageManager = getPackageManager();
|
|
188943
|
-
if (!fs47.existsSync(projectRoot)) {
|
|
188944
|
-
throw new Error(`Directory not found: ${projectRoot}`);
|
|
188945
|
-
}
|
|
188946
|
-
let packageJsonCreated = false;
|
|
188947
|
-
if (!fs47.existsSync(packageJsonPath)) {
|
|
188948
|
-
console.log("No package.json found. Generating a new one.");
|
|
188949
|
-
generatePackageJson(projectRoot);
|
|
188950
|
-
packageJsonCreated = true;
|
|
188951
|
-
} else {
|
|
188952
|
-
console.log("Found existing package.json.");
|
|
188953
|
-
}
|
|
188954
|
-
if (!fs47.existsSync(npmrcPath)) {
|
|
188955
|
-
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
188956
|
-
fs47.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
188957
|
-
}
|
|
188958
|
-
const packageJson = JSON.parse(fs47.readFileSync(packageJsonPath, "utf-8"));
|
|
188959
|
-
if (packageJsonCreated) {
|
|
188960
|
-
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
188961
|
-
if (tsciDependencies.length > 0) {
|
|
188962
|
-
packageJson.dependencies = packageJson.dependencies || {};
|
|
188963
|
-
for (const dependency of tsciDependencies) {
|
|
188964
|
-
if (!packageJson.dependencies[dependency]) {
|
|
188965
|
-
packageJson.dependencies[dependency] = "latest";
|
|
188966
|
-
}
|
|
188967
|
-
}
|
|
188968
|
-
console.log(`Added ${tsciDependencies.length} @tsci dependencies to package.json.`);
|
|
188969
|
-
} else {
|
|
188970
|
-
console.log("No @tsci dependencies detected in circuit files.");
|
|
188971
|
-
}
|
|
188972
|
-
}
|
|
188973
|
-
fs47.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
188974
|
-
`);
|
|
188975
|
-
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
188976
|
-
try {
|
|
188977
|
-
packageManager.installAll({ cwd: projectRoot });
|
|
188978
|
-
console.log("Dependencies installed successfully.");
|
|
188979
|
-
} catch (error) {
|
|
188980
|
-
console.warn("Failed to automatically install dependencies.");
|
|
188981
|
-
console.warn(`Please run \`${packageManager.getInstallAllCommand()}\` manually.`);
|
|
188982
|
-
handleRegistryAuthError({ error, projectDir: projectRoot });
|
|
188983
|
-
throw error;
|
|
188984
|
-
}
|
|
188985
|
-
}
|
|
188986
|
-
|
|
188987
189034
|
// cli/install/register.ts
|
|
188988
189035
|
var registerInstall = (program3) => {
|
|
188989
189036
|
program3.command("install [packageSpec]").description("Install project dependencies, or install a specific package (e.g., tsci install https://github.com/espressif/kicad-libraries)").action(async (packageSpec) => {
|