@tscircuit/cli 0.1.496 → 0.1.497
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 +275 -85
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -72387,7 +72387,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
|
|
|
72387
72387
|
import { execSync as execSync2 } from "node:child_process";
|
|
72388
72388
|
var import_semver2 = __toESM2(require_semver2(), 1);
|
|
72389
72389
|
// package.json
|
|
72390
|
-
var version = "0.1.
|
|
72390
|
+
var version = "0.1.496";
|
|
72391
72391
|
var package_default = {
|
|
72392
72392
|
name: "@tscircuit/cli",
|
|
72393
72393
|
version,
|
|
@@ -92912,6 +92912,9 @@ var KicadPcb = class _KicadPcb extends SxClass {
|
|
|
92912
92912
|
}
|
|
92913
92913
|
};
|
|
92914
92914
|
SxClass.register(KicadPcb);
|
|
92915
|
+
var parseKicadSexpr = (sexpr) => {
|
|
92916
|
+
return SxClass.parse(sexpr);
|
|
92917
|
+
};
|
|
92915
92918
|
|
|
92916
92919
|
// node_modules/circuit-json-to-kicad/dist/index.js
|
|
92917
92920
|
import { cju } from "@tscircuit/circuit-json-util";
|
|
@@ -195882,8 +195885,8 @@ var registerRemove = (program3) => {
|
|
|
195882
195885
|
};
|
|
195883
195886
|
|
|
195884
195887
|
// cli/build/register.ts
|
|
195885
|
-
import
|
|
195886
|
-
import
|
|
195888
|
+
import path35 from "node:path";
|
|
195889
|
+
import fs36 from "node:fs";
|
|
195887
195890
|
|
|
195888
195891
|
// cli/build/build-file.ts
|
|
195889
195892
|
import path29 from "node:path";
|
|
@@ -195938,13 +195941,16 @@ var buildFile = async (input, output, projectDir, options) => {
|
|
|
195938
195941
|
}
|
|
195939
195942
|
if (errors.length > 0 && !options?.ignoreErrors) {
|
|
195940
195943
|
console.error(kleur_default.red(`Build failed with ${errors.length} error(s). Use --ignore-errors to continue.`));
|
|
195941
|
-
return false;
|
|
195944
|
+
return { ok: false };
|
|
195942
195945
|
} else {
|
|
195943
|
-
return
|
|
195946
|
+
return {
|
|
195947
|
+
ok: true,
|
|
195948
|
+
circuitJson: result.circuitJson
|
|
195949
|
+
};
|
|
195944
195950
|
}
|
|
195945
195951
|
} catch (err) {
|
|
195946
195952
|
console.error(`Build failed: ${err}`);
|
|
195947
|
-
return false;
|
|
195953
|
+
return { ok: false };
|
|
195948
195954
|
}
|
|
195949
195955
|
};
|
|
195950
195956
|
|
|
@@ -196157,9 +196163,167 @@ var buildPreviewImages = async ({
|
|
|
196157
196163
|
});
|
|
196158
196164
|
};
|
|
196159
196165
|
|
|
196160
|
-
// cli/build/
|
|
196161
|
-
import path32 from "node:path";
|
|
196166
|
+
// cli/build/generate-kicad-project.ts
|
|
196162
196167
|
import fs33 from "node:fs";
|
|
196168
|
+
import path32 from "node:path";
|
|
196169
|
+
var createKicadProContent = ({
|
|
196170
|
+
projectName,
|
|
196171
|
+
schematicFileName,
|
|
196172
|
+
boardFileName
|
|
196173
|
+
}) => JSON.stringify({
|
|
196174
|
+
head: {
|
|
196175
|
+
version: 1,
|
|
196176
|
+
generator: "tsci"
|
|
196177
|
+
},
|
|
196178
|
+
project: {
|
|
196179
|
+
name: projectName,
|
|
196180
|
+
files: {
|
|
196181
|
+
schematic: schematicFileName,
|
|
196182
|
+
board: boardFileName
|
|
196183
|
+
}
|
|
196184
|
+
}
|
|
196185
|
+
}, null, 2);
|
|
196186
|
+
var generateKicadProject = async ({
|
|
196187
|
+
circuitJson,
|
|
196188
|
+
outputDir,
|
|
196189
|
+
projectName,
|
|
196190
|
+
writeFiles
|
|
196191
|
+
}) => {
|
|
196192
|
+
const schConverter = new CircuitJsonToKicadSchConverter(circuitJson);
|
|
196193
|
+
schConverter.runUntilFinished();
|
|
196194
|
+
const schContent = schConverter.getOutputString();
|
|
196195
|
+
const pcbConverter = new CircuitJsonToKicadPcbConverter(circuitJson);
|
|
196196
|
+
pcbConverter.runUntilFinished();
|
|
196197
|
+
const pcbContent = pcbConverter.getOutputString();
|
|
196198
|
+
const sanitizedProjectName = projectName.trim().length > 0 ? projectName.trim() : "project";
|
|
196199
|
+
const schematicFileName = `${sanitizedProjectName}.kicad_sch`;
|
|
196200
|
+
const boardFileName = `${sanitizedProjectName}.kicad_pcb`;
|
|
196201
|
+
const projectFileName = `${sanitizedProjectName}.kicad_pro`;
|
|
196202
|
+
const proContent = createKicadProContent({
|
|
196203
|
+
projectName: sanitizedProjectName,
|
|
196204
|
+
schematicFileName,
|
|
196205
|
+
boardFileName
|
|
196206
|
+
});
|
|
196207
|
+
if (writeFiles) {
|
|
196208
|
+
fs33.mkdirSync(outputDir, { recursive: true });
|
|
196209
|
+
fs33.writeFileSync(path32.join(outputDir, schematicFileName), schContent);
|
|
196210
|
+
fs33.writeFileSync(path32.join(outputDir, boardFileName), pcbContent);
|
|
196211
|
+
fs33.writeFileSync(path32.join(outputDir, projectFileName), proContent);
|
|
196212
|
+
}
|
|
196213
|
+
return {
|
|
196214
|
+
pcbContent,
|
|
196215
|
+
schContent,
|
|
196216
|
+
proContent,
|
|
196217
|
+
outputDir,
|
|
196218
|
+
projectName: sanitizedProjectName
|
|
196219
|
+
};
|
|
196220
|
+
};
|
|
196221
|
+
|
|
196222
|
+
// cli/build/generate-kicad-footprint-library.ts
|
|
196223
|
+
import fs34 from "node:fs";
|
|
196224
|
+
import path33 from "node:path";
|
|
196225
|
+
var sanitizeLibraryAndFootprintName = (libraryLink) => {
|
|
196226
|
+
if (!libraryLink) {
|
|
196227
|
+
return {
|
|
196228
|
+
libraryName: "generated",
|
|
196229
|
+
footprintName: "footprint"
|
|
196230
|
+
};
|
|
196231
|
+
}
|
|
196232
|
+
if (!libraryLink.includes(":")) {
|
|
196233
|
+
return {
|
|
196234
|
+
libraryName: "generated",
|
|
196235
|
+
footprintName: libraryLink.replace(/[\\\/]/g, "-") || "footprint"
|
|
196236
|
+
};
|
|
196237
|
+
}
|
|
196238
|
+
const [rawLibraryName, rawFootprintName] = libraryLink.split(":", 2);
|
|
196239
|
+
const libraryName = rawLibraryName?.replace(/[\\\/]/g, "-").trim() || "generated";
|
|
196240
|
+
const footprintName = rawFootprintName?.replace(/[\\\/]/g, "-").trim() || "footprint";
|
|
196241
|
+
return {
|
|
196242
|
+
libraryName,
|
|
196243
|
+
footprintName
|
|
196244
|
+
};
|
|
196245
|
+
};
|
|
196246
|
+
var sanitizeFootprint = (footprint) => {
|
|
196247
|
+
const { libraryName, footprintName } = sanitizeLibraryAndFootprintName(footprint.libraryLink);
|
|
196248
|
+
footprint.libraryLink = footprintName;
|
|
196249
|
+
footprint.position = At.from([0, 0, 0]);
|
|
196250
|
+
footprint.locked = false;
|
|
196251
|
+
footprint.placed = false;
|
|
196252
|
+
footprint.uuid = undefined;
|
|
196253
|
+
footprint.path = undefined;
|
|
196254
|
+
footprint.sheetfile = undefined;
|
|
196255
|
+
footprint.sheetname = undefined;
|
|
196256
|
+
footprint.properties = [];
|
|
196257
|
+
const texts = footprint.fpTexts ?? [];
|
|
196258
|
+
for (const text of texts) {
|
|
196259
|
+
text.uuid = undefined;
|
|
196260
|
+
if (text.type === "reference") {
|
|
196261
|
+
text.text = "REF**";
|
|
196262
|
+
} else if (text.type === "value" && text.text.trim().length === 0) {
|
|
196263
|
+
text.text = footprintName;
|
|
196264
|
+
}
|
|
196265
|
+
}
|
|
196266
|
+
footprint.fpTexts = texts;
|
|
196267
|
+
const pads = footprint.fpPads ?? [];
|
|
196268
|
+
for (const pad2 of pads) {
|
|
196269
|
+
pad2.uuid = undefined;
|
|
196270
|
+
pad2.net = undefined;
|
|
196271
|
+
}
|
|
196272
|
+
footprint.fpPads = pads;
|
|
196273
|
+
return {
|
|
196274
|
+
libraryName,
|
|
196275
|
+
footprintName,
|
|
196276
|
+
content: footprint.getString()
|
|
196277
|
+
};
|
|
196278
|
+
};
|
|
196279
|
+
var generateKicadFootprintLibrary = async ({
|
|
196280
|
+
projects,
|
|
196281
|
+
distDir
|
|
196282
|
+
}) => {
|
|
196283
|
+
const libraryRoot = path33.join(distDir, "kicad-footprints");
|
|
196284
|
+
fs34.mkdirSync(libraryRoot, { recursive: true });
|
|
196285
|
+
const uniqueFootprints = new Map;
|
|
196286
|
+
for (const project of projects) {
|
|
196287
|
+
try {
|
|
196288
|
+
const parsed = parseKicadSexpr(project.pcbContent);
|
|
196289
|
+
const pcb = parsed.find((node) => node instanceof KicadPcb);
|
|
196290
|
+
if (!pcb)
|
|
196291
|
+
continue;
|
|
196292
|
+
const footprints = pcb.footprints ?? [];
|
|
196293
|
+
for (const footprint of footprints) {
|
|
196294
|
+
const sanitized = sanitizeFootprint(footprint);
|
|
196295
|
+
const key = `${sanitized.libraryName}::${sanitized.footprintName}`;
|
|
196296
|
+
if (!uniqueFootprints.has(key)) {
|
|
196297
|
+
uniqueFootprints.set(key, sanitized);
|
|
196298
|
+
}
|
|
196299
|
+
}
|
|
196300
|
+
} catch (error) {
|
|
196301
|
+
console.warn(`Failed to parse KiCad PCB content for footprint extraction from ${project.sourcePath}:`, error);
|
|
196302
|
+
}
|
|
196303
|
+
}
|
|
196304
|
+
const libraryNames = new Set;
|
|
196305
|
+
for (const entry of uniqueFootprints.values()) {
|
|
196306
|
+
libraryNames.add(entry.libraryName);
|
|
196307
|
+
const libraryDir = path33.join(libraryRoot, `${entry.libraryName}.pretty`);
|
|
196308
|
+
fs34.mkdirSync(libraryDir, { recursive: true });
|
|
196309
|
+
const footprintPath = path33.join(libraryDir, `${entry.footprintName}.kicad_mod`);
|
|
196310
|
+
fs34.writeFileSync(footprintPath, `${entry.content}
|
|
196311
|
+
`);
|
|
196312
|
+
}
|
|
196313
|
+
if (libraryNames.size > 0) {
|
|
196314
|
+
const libTableEntries = Array.from(libraryNames).sort().map((name) => ` (lib (name ${name}) (type KiCad) (uri \${KIPRJMOD}/kicad-footprints/${name}.pretty) (options "") (descr "Generated by tsci build"))`);
|
|
196315
|
+
const libTableContent = `(fp_lib_table
|
|
196316
|
+
${libTableEntries.join(`
|
|
196317
|
+
`)}
|
|
196318
|
+
)
|
|
196319
|
+
`;
|
|
196320
|
+
fs34.writeFileSync(path33.join(libraryRoot, "fp-lib-table"), libTableContent);
|
|
196321
|
+
}
|
|
196322
|
+
};
|
|
196323
|
+
|
|
196324
|
+
// cli/build/transpile.ts
|
|
196325
|
+
import path34 from "node:path";
|
|
196326
|
+
import fs35 from "node:fs";
|
|
196163
196327
|
import { rollup } from "rollup";
|
|
196164
196328
|
import typescript from "@rollup/plugin-typescript";
|
|
196165
196329
|
import resolve11 from "@rollup/plugin-node-resolve";
|
|
@@ -196172,7 +196336,7 @@ var transpileFile = async ({
|
|
|
196172
196336
|
projectDir
|
|
196173
196337
|
}) => {
|
|
196174
196338
|
try {
|
|
196175
|
-
|
|
196339
|
+
fs35.mkdirSync(outputDir, { recursive: true });
|
|
196176
196340
|
console.log("Building ESM bundle...");
|
|
196177
196341
|
const esmBundle = await rollup({
|
|
196178
196342
|
input,
|
|
@@ -196202,11 +196366,11 @@ var transpileFile = async ({
|
|
|
196202
196366
|
]
|
|
196203
196367
|
});
|
|
196204
196368
|
await esmBundle.write({
|
|
196205
|
-
file:
|
|
196369
|
+
file: path34.join(outputDir, "index.js"),
|
|
196206
196370
|
format: "es",
|
|
196207
196371
|
sourcemap: false
|
|
196208
196372
|
});
|
|
196209
|
-
console.log(`ESM bundle written to ${
|
|
196373
|
+
console.log(`ESM bundle written to ${path34.relative(projectDir, path34.join(outputDir, "index.js"))}`);
|
|
196210
196374
|
console.log("Building CommonJS bundle...");
|
|
196211
196375
|
const cjsBundle = await rollup({
|
|
196212
196376
|
input,
|
|
@@ -196236,11 +196400,11 @@ var transpileFile = async ({
|
|
|
196236
196400
|
]
|
|
196237
196401
|
});
|
|
196238
196402
|
await cjsBundle.write({
|
|
196239
|
-
file:
|
|
196403
|
+
file: path34.join(outputDir, "index.cjs"),
|
|
196240
196404
|
format: "cjs",
|
|
196241
196405
|
sourcemap: false
|
|
196242
196406
|
});
|
|
196243
|
-
console.log(`CommonJS bundle written to ${
|
|
196407
|
+
console.log(`CommonJS bundle written to ${path34.relative(projectDir, path34.join(outputDir, "index.cjs"))}`);
|
|
196244
196408
|
console.log("Generating type declarations...");
|
|
196245
196409
|
const dtsBundle = await rollup({
|
|
196246
196410
|
input,
|
|
@@ -196260,8 +196424,8 @@ var transpileFile = async ({
|
|
|
196260
196424
|
dtsContent = dtsContent.replace(/import \* as [\w_]+ from ['"]react\/jsx-runtime['"];?\s*\n?/g, "");
|
|
196261
196425
|
dtsContent = dtsContent.replace(/[\w_]+\.JSX\.Element/g, "any");
|
|
196262
196426
|
dtsContent = dtsContent.replace(/export\s*{\s*};\s*$/gm, "").trim();
|
|
196263
|
-
|
|
196264
|
-
console.log(`Type declarations written to ${
|
|
196427
|
+
fs35.writeFileSync(path34.join(outputDir, "index.d.ts"), dtsContent);
|
|
196428
|
+
console.log(`Type declarations written to ${path34.relative(projectDir, path34.join(outputDir, "index.d.ts"))}`);
|
|
196265
196429
|
console.log(kleur_default.green("Transpilation complete!"));
|
|
196266
196430
|
return true;
|
|
196267
196431
|
} catch (err) {
|
|
@@ -196275,7 +196439,7 @@ var transpileFile = async ({
|
|
|
196275
196439
|
|
|
196276
196440
|
// cli/build/register.ts
|
|
196277
196441
|
var registerBuild = (program3) => {
|
|
196278
|
-
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").action(async (file, options) => {
|
|
196442
|
+
program3.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad", "Generate KiCad project directories for each successful build output").option("--kicad-footprint-library", "Generate a KiCad footprint library from all successful build outputs").action(async (file, options) => {
|
|
196279
196443
|
try {
|
|
196280
196444
|
const { projectDir, circuitFiles, mainEntrypoint } = await getBuildEntrypoints({
|
|
196281
196445
|
fileOrDir: file
|
|
@@ -196292,18 +196456,20 @@ var registerBuild = (program3) => {
|
|
|
196292
196456
|
}
|
|
196293
196457
|
return config;
|
|
196294
196458
|
})();
|
|
196295
|
-
const distDir =
|
|
196296
|
-
|
|
196459
|
+
const distDir = path35.join(projectDir, "dist");
|
|
196460
|
+
fs36.mkdirSync(distDir, { recursive: true });
|
|
196297
196461
|
console.log(`Building ${circuitFiles.length} file(s)...`);
|
|
196298
196462
|
let hasErrors = false;
|
|
196299
196463
|
const staticFileReferences = [];
|
|
196300
196464
|
const builtFiles = [];
|
|
196465
|
+
const kicadProjects = [];
|
|
196466
|
+
const shouldGenerateKicad = options?.kicad || options?.kicadFootprintLibrary;
|
|
196301
196467
|
for (const filePath of circuitFiles) {
|
|
196302
|
-
const relative9 =
|
|
196468
|
+
const relative9 = path35.relative(projectDir, filePath);
|
|
196303
196469
|
console.log(`Building ${relative9}...`);
|
|
196304
196470
|
const outputDirName = relative9.replace(/(\.board|\.circuit)?\.tsx$/, "");
|
|
196305
|
-
const outputPath =
|
|
196306
|
-
const
|
|
196471
|
+
const outputPath = path35.join(distDir, outputDirName, "circuit.json");
|
|
196472
|
+
const buildOutcome = await buildFile(filePath, outputPath, projectDir, {
|
|
196307
196473
|
ignoreErrors: options?.ignoreErrors,
|
|
196308
196474
|
ignoreWarnings: options?.ignoreWarnings,
|
|
196309
196475
|
platformConfig: platformConfig2
|
|
@@ -196311,19 +196477,33 @@ var registerBuild = (program3) => {
|
|
|
196311
196477
|
builtFiles.push({
|
|
196312
196478
|
sourcePath: filePath,
|
|
196313
196479
|
outputPath,
|
|
196314
|
-
ok
|
|
196480
|
+
ok: buildOutcome.ok
|
|
196315
196481
|
});
|
|
196316
|
-
if (!ok) {
|
|
196482
|
+
if (!buildOutcome.ok) {
|
|
196317
196483
|
hasErrors = true;
|
|
196318
196484
|
} else if (options?.site) {
|
|
196319
|
-
const normalizedSourcePath = relative9.split(
|
|
196320
|
-
const relativeOutputPath =
|
|
196321
|
-
const normalizedOutputPath = relativeOutputPath.split(
|
|
196485
|
+
const normalizedSourcePath = relative9.split(path35.sep).join("/");
|
|
196486
|
+
const relativeOutputPath = path35.join(outputDirName, "circuit.json");
|
|
196487
|
+
const normalizedOutputPath = relativeOutputPath.split(path35.sep).join("/");
|
|
196322
196488
|
staticFileReferences.push({
|
|
196323
196489
|
filePath: normalizedSourcePath,
|
|
196324
196490
|
fileStaticAssetUrl: `./${normalizedOutputPath}`
|
|
196325
196491
|
});
|
|
196326
196492
|
}
|
|
196493
|
+
if (buildOutcome.ok && shouldGenerateKicad && buildOutcome.circuitJson) {
|
|
196494
|
+
const projectOutputDir = path35.join(distDir, outputDirName, "kicad");
|
|
196495
|
+
const projectName = path35.basename(outputDirName);
|
|
196496
|
+
const project = await generateKicadProject({
|
|
196497
|
+
circuitJson: buildOutcome.circuitJson,
|
|
196498
|
+
outputDir: projectOutputDir,
|
|
196499
|
+
projectName,
|
|
196500
|
+
writeFiles: Boolean(options?.kicad)
|
|
196501
|
+
});
|
|
196502
|
+
kicadProjects.push({
|
|
196503
|
+
...project,
|
|
196504
|
+
sourcePath: filePath
|
|
196505
|
+
});
|
|
196506
|
+
}
|
|
196327
196507
|
}
|
|
196328
196508
|
if (hasErrors && !options?.ignoreErrors) {
|
|
196329
196509
|
process.exit(1);
|
|
@@ -196360,8 +196540,18 @@ var registerBuild = (program3) => {
|
|
|
196360
196540
|
files: staticFileReferences,
|
|
196361
196541
|
standaloneScriptSrc: "./standalone.min.js"
|
|
196362
196542
|
});
|
|
196363
|
-
|
|
196364
|
-
|
|
196543
|
+
fs36.writeFileSync(path35.join(distDir, "index.html"), indexHtml);
|
|
196544
|
+
fs36.writeFileSync(path35.join(distDir, "standalone.min.js"), standalone_min_default);
|
|
196545
|
+
}
|
|
196546
|
+
if (options?.kicadFootprintLibrary) {
|
|
196547
|
+
if (kicadProjects.length === 0) {
|
|
196548
|
+
console.warn("No successful build output available for KiCad footprint library generation.");
|
|
196549
|
+
} else {
|
|
196550
|
+
await generateKicadFootprintLibrary({
|
|
196551
|
+
projects: kicadProjects,
|
|
196552
|
+
distDir
|
|
196553
|
+
});
|
|
196554
|
+
}
|
|
196365
196555
|
}
|
|
196366
196556
|
console.log("Build complete!");
|
|
196367
196557
|
process.exit(0);
|
|
@@ -196374,8 +196564,8 @@ var registerBuild = (program3) => {
|
|
|
196374
196564
|
};
|
|
196375
196565
|
|
|
196376
196566
|
// lib/shared/snapshot-project.ts
|
|
196377
|
-
import
|
|
196378
|
-
import
|
|
196567
|
+
import fs38 from "node:fs";
|
|
196568
|
+
import path36 from "node:path";
|
|
196379
196569
|
import looksSame2 from "looks-same";
|
|
196380
196570
|
import {
|
|
196381
196571
|
convertCircuitJsonToPcbSvg as convertCircuitJsonToPcbSvg3,
|
|
@@ -196386,7 +196576,7 @@ import { renderGLTFToPNGBufferFromGLBBuffer as renderGLTFToPNGBufferFromGLBBuffe
|
|
|
196386
196576
|
|
|
196387
196577
|
// lib/shared/compare-images.ts
|
|
196388
196578
|
import looksSame from "looks-same";
|
|
196389
|
-
import
|
|
196579
|
+
import fs37 from "node:fs/promises";
|
|
196390
196580
|
var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
196391
196581
|
const { equal: equal2 } = await looksSame(buffer1, buffer2, {
|
|
196392
196582
|
strict: false,
|
|
@@ -196402,7 +196592,7 @@ var compareAndCreateDiff = async (buffer1, buffer2, diffPath) => {
|
|
|
196402
196592
|
tolerance: 2
|
|
196403
196593
|
});
|
|
196404
196594
|
} else {
|
|
196405
|
-
await
|
|
196595
|
+
await fs37.writeFile(diffPath, buffer2);
|
|
196406
196596
|
}
|
|
196407
196597
|
}
|
|
196408
196598
|
return { equal: equal2 };
|
|
@@ -196427,7 +196617,7 @@ var snapshotProject = async ({
|
|
|
196427
196617
|
...DEFAULT_IGNORED_PATTERNS,
|
|
196428
196618
|
...ignored.map(normalizeIgnorePattern)
|
|
196429
196619
|
];
|
|
196430
|
-
const resolvedPaths = filePaths.map((f) =>
|
|
196620
|
+
const resolvedPaths = filePaths.map((f) => path36.resolve(projectDir, f));
|
|
196431
196621
|
const boardFiles = findBoardFiles({
|
|
196432
196622
|
projectDir,
|
|
196433
196623
|
ignore,
|
|
@@ -196441,7 +196631,7 @@ var snapshotProject = async ({
|
|
|
196441
196631
|
const mismatches = [];
|
|
196442
196632
|
let didUpdate = false;
|
|
196443
196633
|
for (const file of boardFiles) {
|
|
196444
|
-
const relativeFilePath =
|
|
196634
|
+
const relativeFilePath = path36.relative(projectDir, file);
|
|
196445
196635
|
let circuitJson;
|
|
196446
196636
|
let pcbSvg;
|
|
196447
196637
|
let schSvg;
|
|
@@ -196495,17 +196685,17 @@ var snapshotProject = async ({
|
|
|
196495
196685
|
} catch (error) {
|
|
196496
196686
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
196497
196687
|
if (errorMessage.includes("No pcb_board found in circuit JSON")) {
|
|
196498
|
-
const fileDir =
|
|
196499
|
-
const relativeDir =
|
|
196500
|
-
const snapDir2 = snapshotsDirName ?
|
|
196501
|
-
const base2 =
|
|
196502
|
-
const snap3dPath =
|
|
196503
|
-
const existing3dSnapshot =
|
|
196688
|
+
const fileDir = path36.dirname(file);
|
|
196689
|
+
const relativeDir = path36.relative(projectDir, fileDir);
|
|
196690
|
+
const snapDir2 = snapshotsDirName ? path36.join(projectDir, snapshotsDirName, relativeDir) : path36.join(fileDir, "__snapshots__");
|
|
196691
|
+
const base2 = path36.basename(file).replace(/\.tsx$/, "");
|
|
196692
|
+
const snap3dPath = path36.join(snapDir2, `${base2}-3d.snap.png`);
|
|
196693
|
+
const existing3dSnapshot = fs38.existsSync(snap3dPath);
|
|
196504
196694
|
if (existing3dSnapshot) {
|
|
196505
196695
|
onError(kleur_default.red(`
|
|
196506
196696
|
❌ Failed to generate 3D snapshot for ${relativeFilePath}:
|
|
196507
196697
|
`) + kleur_default.red(` No pcb_board found in circuit JSON
|
|
196508
|
-
`) + kleur_default.red(` Existing snapshot: ${
|
|
196698
|
+
`) + kleur_default.red(` Existing snapshot: ${path36.relative(projectDir, snap3dPath)}
|
|
196509
196699
|
`));
|
|
196510
196700
|
return onExit(1);
|
|
196511
196701
|
} else {
|
|
@@ -196521,9 +196711,9 @@ var snapshotProject = async ({
|
|
|
196521
196711
|
}
|
|
196522
196712
|
}
|
|
196523
196713
|
}
|
|
196524
|
-
const snapDir = snapshotsDirName ?
|
|
196525
|
-
|
|
196526
|
-
const base =
|
|
196714
|
+
const snapDir = snapshotsDirName ? path36.join(projectDir, snapshotsDirName, path36.relative(projectDir, path36.dirname(file))) : path36.join(path36.dirname(file), "__snapshots__");
|
|
196715
|
+
fs38.mkdirSync(snapDir, { recursive: true });
|
|
196716
|
+
const base = path36.basename(file).replace(/\.tsx$/, "");
|
|
196527
196717
|
const snapshots = [];
|
|
196528
196718
|
if (pcbOnly || !schematicOnly) {
|
|
196529
196719
|
snapshots.push({ type: "pcb", content: pcbSvg, isBinary: false });
|
|
@@ -196541,31 +196731,31 @@ var snapshotProject = async ({
|
|
|
196541
196731
|
for (const snapshot of snapshots) {
|
|
196542
196732
|
const { type } = snapshot;
|
|
196543
196733
|
const is3d = type === "3d";
|
|
196544
|
-
const snapPath =
|
|
196545
|
-
const existing =
|
|
196734
|
+
const snapPath = path36.join(snapDir, `${base}-${type}.snap.${is3d ? "png" : "svg"}`);
|
|
196735
|
+
const existing = fs38.existsSync(snapPath);
|
|
196546
196736
|
const newContentBuffer = snapshot.isBinary ? snapshot.content : Buffer.from(snapshot.content, "utf8");
|
|
196547
196737
|
const newContentForFile = snapshot.content;
|
|
196548
196738
|
if (!existing) {
|
|
196549
|
-
|
|
196550
|
-
console.log("✅", kleur_default.gray(
|
|
196739
|
+
fs38.writeFileSync(snapPath, newContentForFile);
|
|
196740
|
+
console.log("✅", kleur_default.gray(path36.relative(projectDir, snapPath)));
|
|
196551
196741
|
didUpdate = true;
|
|
196552
196742
|
continue;
|
|
196553
196743
|
}
|
|
196554
|
-
const oldContentBuffer =
|
|
196744
|
+
const oldContentBuffer = fs38.readFileSync(snapPath);
|
|
196555
196745
|
const diffPath = snapPath.replace(is3d ? ".snap.png" : ".snap.svg", is3d ? ".diff.png" : ".diff.svg");
|
|
196556
196746
|
const { equal: equal2 } = await compareAndCreateDiff(oldContentBuffer, newContentBuffer, diffPath);
|
|
196557
196747
|
if (update) {
|
|
196558
196748
|
if (!forceUpdate && equal2) {
|
|
196559
|
-
console.log("✅", kleur_default.gray(
|
|
196749
|
+
console.log("✅", kleur_default.gray(path36.relative(projectDir, snapPath)));
|
|
196560
196750
|
} else {
|
|
196561
|
-
|
|
196562
|
-
console.log("✅", kleur_default.gray(
|
|
196751
|
+
fs38.writeFileSync(snapPath, newContentForFile);
|
|
196752
|
+
console.log("✅", kleur_default.gray(path36.relative(projectDir, snapPath)));
|
|
196563
196753
|
didUpdate = true;
|
|
196564
196754
|
}
|
|
196565
196755
|
} else if (!equal2) {
|
|
196566
196756
|
mismatches.push(`${snapPath} (diff: ${diffPath})`);
|
|
196567
196757
|
} else {
|
|
196568
|
-
console.log("✅", kleur_default.gray(
|
|
196758
|
+
console.log("✅", kleur_default.gray(path36.relative(projectDir, snapPath)));
|
|
196569
196759
|
}
|
|
196570
196760
|
}
|
|
196571
196761
|
}
|
|
@@ -196604,22 +196794,22 @@ var registerSnapshot = (program3) => {
|
|
|
196604
196794
|
};
|
|
196605
196795
|
|
|
196606
196796
|
// lib/shared/setup-github-actions.ts
|
|
196607
|
-
import
|
|
196608
|
-
import
|
|
196797
|
+
import fs39 from "node:fs";
|
|
196798
|
+
import path37 from "node:path";
|
|
196609
196799
|
var setupGithubActions = (projectDir = process.cwd()) => {
|
|
196610
196800
|
const findGitRoot = (startDir) => {
|
|
196611
|
-
let dir =
|
|
196612
|
-
while (dir !==
|
|
196613
|
-
if (
|
|
196801
|
+
let dir = path37.resolve(startDir);
|
|
196802
|
+
while (dir !== path37.parse(dir).root) {
|
|
196803
|
+
if (fs39.existsSync(path37.join(dir, ".git"))) {
|
|
196614
196804
|
return dir;
|
|
196615
196805
|
}
|
|
196616
|
-
dir =
|
|
196806
|
+
dir = path37.dirname(dir);
|
|
196617
196807
|
}
|
|
196618
196808
|
return null;
|
|
196619
196809
|
};
|
|
196620
196810
|
const gitRoot = findGitRoot(projectDir) ?? projectDir;
|
|
196621
|
-
const workflowsDir =
|
|
196622
|
-
|
|
196811
|
+
const workflowsDir = path37.join(gitRoot, ".github", "workflows");
|
|
196812
|
+
fs39.mkdirSync(workflowsDir, { recursive: true });
|
|
196623
196813
|
const buildWorkflow = `name: tscircuit Build
|
|
196624
196814
|
|
|
196625
196815
|
on:
|
|
@@ -196658,8 +196848,8 @@ jobs:
|
|
|
196658
196848
|
- run: bun install
|
|
196659
196849
|
- run: bunx tsci snapshot
|
|
196660
196850
|
`;
|
|
196661
|
-
writeFileIfNotExists(
|
|
196662
|
-
writeFileIfNotExists(
|
|
196851
|
+
writeFileIfNotExists(path37.join(workflowsDir, "tscircuit-build.yml"), buildWorkflow);
|
|
196852
|
+
writeFileIfNotExists(path37.join(workflowsDir, "tscircuit-snapshot.yml"), snapshotWorkflow);
|
|
196663
196853
|
};
|
|
196664
196854
|
|
|
196665
196855
|
// cli/setup/register.ts
|
|
@@ -196685,8 +196875,8 @@ var registerSetup = (program3) => {
|
|
|
196685
196875
|
};
|
|
196686
196876
|
|
|
196687
196877
|
// cli/convert/register.ts
|
|
196688
|
-
import
|
|
196689
|
-
import
|
|
196878
|
+
import fs40 from "node:fs/promises";
|
|
196879
|
+
import path38 from "node:path";
|
|
196690
196880
|
import { parseKicadModToCircuitJson } from "kicad-component-converter";
|
|
196691
196881
|
|
|
196692
196882
|
// node_modules/@tscircuit/mm/dist/index.js
|
|
@@ -196806,15 +196996,15 @@ var convertCircuitJsonToTscircuit = (circuitJson, opts) => {
|
|
|
196806
196996
|
var registerConvert = (program3) => {
|
|
196807
196997
|
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) => {
|
|
196808
196998
|
try {
|
|
196809
|
-
const inputPath =
|
|
196810
|
-
const modContent = await
|
|
196999
|
+
const inputPath = path38.resolve(file);
|
|
197000
|
+
const modContent = await fs40.readFile(inputPath, "utf-8");
|
|
196811
197001
|
const circuitJson = await parseKicadModToCircuitJson(modContent);
|
|
196812
|
-
const componentName = options.name ??
|
|
197002
|
+
const componentName = options.name ?? path38.basename(inputPath, ".kicad_mod");
|
|
196813
197003
|
const tsx = convertCircuitJsonToTscircuit(circuitJson, {
|
|
196814
197004
|
componentName
|
|
196815
197005
|
});
|
|
196816
|
-
const outputPath = options.output ?
|
|
196817
|
-
await
|
|
197006
|
+
const outputPath = options.output ? path38.resolve(options.output) : path38.join(path38.dirname(inputPath), `${componentName}.tsx`);
|
|
197007
|
+
await fs40.writeFile(outputPath, tsx);
|
|
196818
197008
|
console.log(kleur_default.green(`Converted ${outputPath}`));
|
|
196819
197009
|
} catch (error) {
|
|
196820
197010
|
console.error(kleur_default.red("Failed to convert footprint:"), error instanceof Error ? error.message : error);
|
|
@@ -196909,12 +197099,12 @@ var registerSimulate = (program3) => {
|
|
|
196909
197099
|
};
|
|
196910
197100
|
|
|
196911
197101
|
// lib/shared/install-project-dependencies.ts
|
|
196912
|
-
import
|
|
196913
|
-
import
|
|
197102
|
+
import fs42 from "node:fs";
|
|
197103
|
+
import path40 from "node:path";
|
|
196914
197104
|
|
|
196915
197105
|
// lib/shared/collect-tsci-dependencies.ts
|
|
196916
|
-
import
|
|
196917
|
-
import
|
|
197106
|
+
import fs41 from "node:fs";
|
|
197107
|
+
import path39 from "node:path";
|
|
196918
197108
|
var DEFAULT_PATTERNS = ["**/*.{ts,tsx,js,jsx}"];
|
|
196919
197109
|
var DEFAULT_IGNORES = [
|
|
196920
197110
|
"**/node_modules/**",
|
|
@@ -196929,7 +197119,7 @@ function collectTsciDependencies({
|
|
|
196929
197119
|
patterns = DEFAULT_PATTERNS,
|
|
196930
197120
|
ignore = DEFAULT_IGNORES
|
|
196931
197121
|
} = {}) {
|
|
196932
|
-
const searchRoot =
|
|
197122
|
+
const searchRoot = path39.resolve(cwd);
|
|
196933
197123
|
const files = globbySync(patterns, {
|
|
196934
197124
|
cwd: searchRoot,
|
|
196935
197125
|
absolute: true,
|
|
@@ -196939,7 +197129,7 @@ function collectTsciDependencies({
|
|
|
196939
197129
|
const dependencies2 = new Set;
|
|
196940
197130
|
for (const filePath of files) {
|
|
196941
197131
|
try {
|
|
196942
|
-
const fileContents =
|
|
197132
|
+
const fileContents = fs41.readFileSync(filePath, "utf-8");
|
|
196943
197133
|
let match;
|
|
196944
197134
|
while (true) {
|
|
196945
197135
|
match = IMPORT_PATTERN.exec(fileContents);
|
|
@@ -196956,26 +197146,26 @@ function collectTsciDependencies({
|
|
|
196956
197146
|
async function installProjectDependencies({
|
|
196957
197147
|
cwd = process.cwd()
|
|
196958
197148
|
} = {}) {
|
|
196959
|
-
const projectRoot =
|
|
196960
|
-
const packageJsonPath =
|
|
196961
|
-
const npmrcPath =
|
|
197149
|
+
const projectRoot = path40.resolve(cwd);
|
|
197150
|
+
const packageJsonPath = path40.join(projectRoot, "package.json");
|
|
197151
|
+
const npmrcPath = path40.join(projectRoot, ".npmrc");
|
|
196962
197152
|
const packageManager = getPackageManager();
|
|
196963
|
-
if (!
|
|
197153
|
+
if (!fs42.existsSync(projectRoot)) {
|
|
196964
197154
|
throw new Error(`Directory not found: ${projectRoot}`);
|
|
196965
197155
|
}
|
|
196966
197156
|
let packageJsonCreated = false;
|
|
196967
|
-
if (!
|
|
197157
|
+
if (!fs42.existsSync(packageJsonPath)) {
|
|
196968
197158
|
console.log("No package.json found. Generating a new one.");
|
|
196969
197159
|
generatePackageJson(projectRoot);
|
|
196970
197160
|
packageJsonCreated = true;
|
|
196971
197161
|
} else {
|
|
196972
197162
|
console.log("Found existing package.json.");
|
|
196973
197163
|
}
|
|
196974
|
-
if (!
|
|
197164
|
+
if (!fs42.existsSync(npmrcPath)) {
|
|
196975
197165
|
console.log("Creating .npmrc with tscircuit registry configuration.");
|
|
196976
|
-
|
|
197166
|
+
fs42.writeFileSync(npmrcPath, "@tsci:registry=https://npm.tscircuit.com");
|
|
196977
197167
|
}
|
|
196978
|
-
const packageJson = JSON.parse(
|
|
197168
|
+
const packageJson = JSON.parse(fs42.readFileSync(packageJsonPath, "utf-8"));
|
|
196979
197169
|
if (packageJsonCreated) {
|
|
196980
197170
|
const tsciDependencies = collectTsciDependencies({ cwd: projectRoot });
|
|
196981
197171
|
if (tsciDependencies.length > 0) {
|
|
@@ -196990,7 +197180,7 @@ async function installProjectDependencies({
|
|
|
196990
197180
|
console.log("No @tsci dependencies detected in circuit files.");
|
|
196991
197181
|
}
|
|
196992
197182
|
}
|
|
196993
|
-
|
|
197183
|
+
fs42.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
196994
197184
|
`);
|
|
196995
197185
|
console.log(`Installing dependencies using ${kleur_default.bold(packageManager.name)}...`);
|
|
196996
197186
|
try {
|