@tscircuit/cli 0.1.174 → 0.1.175

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.
Files changed (2) hide show
  1. package/dist/main.js +47 -47
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -467116,7 +467116,7 @@ var getGlobalDepsInstallCommand = (packageManager, deps) => {
467116
467116
  import { execSync as execSync2 } from "node:child_process";
467117
467117
  var import_semver2 = __toESM2(require_semver2(), 1);
467118
467118
  // package.json
467119
- var version = "0.1.173";
467119
+ var version = "0.1.174";
467120
467120
  var package_default = {
467121
467121
  name: "@tscircuit/cli",
467122
467122
  version,
@@ -535101,22 +535101,17 @@ var snapshotProject = async ({
535101
535101
  ...DEFAULT_IGNORED_PATTERNS,
535102
535102
  ...ignored.map(normalizeIgnorePattern)
535103
535103
  ];
535104
- let files = [];
535105
- if (filePaths.length > 0) {
535106
- files = filePaths.map((f) => path26.resolve(projectDir, f));
535107
- } else {
535108
- const boardFiles = globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
535109
- cwd: projectDir,
535110
- ignore
535111
- });
535112
- files = boardFiles.map((f) => path26.join(projectDir, f));
535113
- }
535114
- if (files.length === 0) {
535115
- console.log("No entrypoint found. Run 'tsci init' to bootstrap a basic project or specify a file with 'tsci snapshot <file>'");
535104
+ const boardFiles = filePaths.length > 0 ? filePaths.map((f) => path26.resolve(projectDir, f)) : globbySync(["**/*.board.tsx", "**/*.circuit.tsx"], {
535105
+ cwd: projectDir,
535106
+ ignore
535107
+ }).map((f) => path26.join(projectDir, f));
535108
+ if (boardFiles.length === 0) {
535109
+ console.log("No entrypoint found. Run 'tsci init' to bootstrap a project or specify a file with 'tsci snapshot <file>'");
535116
535110
  return onExit(0);
535117
535111
  }
535118
535112
  const mismatches = [];
535119
- for (const file of files) {
535113
+ let didUpdate = false;
535114
+ for (const file of boardFiles) {
535120
535115
  const { circuitJson } = await generateCircuitJson({ filePath: file });
535121
535116
  const pcbSvg = convertCircuitJsonToPcbSvg(circuitJson);
535122
535117
  const schSvg = convertCircuitJsonToSchematicSvg(circuitJson);
@@ -535124,58 +535119,63 @@ var snapshotProject = async ({
535124
535119
  const snapDir = path26.join(path26.dirname(file), "__snapshots__");
535125
535120
  fs26.mkdirSync(snapDir, { recursive: true });
535126
535121
  const base = path26.basename(file).replace(/\.tsx$/, "");
535127
- const snapshotPairs = [];
535128
- const includePcb = pcbOnly || !schematicOnly;
535129
- const includeSchematic = schematicOnly || !pcbOnly;
535130
- if (includePcb)
535131
- snapshotPairs.push(["pcb", pcbSvg]);
535132
- if (includeSchematic)
535133
- snapshotPairs.push(["schematic", schSvg]);
535134
- if (threeD && svg3d) {
535135
- snapshotPairs.push(["3d", svg3d]);
535136
- }
535137
- for (const [type, svg] of snapshotPairs) {
535122
+ const pairs3 = [];
535123
+ if (pcbOnly || !schematicOnly)
535124
+ pairs3.push(["pcb", pcbSvg]);
535125
+ if (schematicOnly || !pcbOnly)
535126
+ pairs3.push(["schematic", schSvg]);
535127
+ if (threeD && svg3d)
535128
+ pairs3.push(["3d", svg3d]);
535129
+ const looksSame = await loadLooksSame();
535130
+ if (!looksSame) {
535131
+ console.error("looks-same is required. Install it with 'bun add -d looks-same'");
535132
+ return onExit(1);
535133
+ }
535134
+ for (const [type, newSvg] of pairs3) {
535138
535135
  const snapPath = path26.join(snapDir, `${base}-${type}.snap.svg`);
535139
- const fileExists = fs26.existsSync(snapPath);
535140
- if (!fileExists) {
535141
- fs26.writeFileSync(snapPath, svg);
535136
+ const existing = fs26.existsSync(snapPath);
535137
+ if (!existing) {
535138
+ fs26.writeFileSync(snapPath, newSvg, "utf8");
535142
535139
  console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
535140
+ didUpdate = true;
535143
535141
  continue;
535144
535142
  }
535145
- const existing = fs26.readFileSync(snapPath, "utf-8");
535146
- const looksSame = await loadLooksSame();
535147
- const equal = looksSame ? (await looksSame.default(Buffer.from(svg), Buffer.from(existing), {
535143
+ const oldSvg = fs26.readFileSync(snapPath, "utf8");
535144
+ const bufNew = Buffer.from(newSvg, "utf8");
535145
+ const bufOld = Buffer.from(oldSvg, "utf8");
535146
+ const { equal } = await looksSame.default(bufNew, bufOld, {
535148
535147
  strict: false,
535149
535148
  tolerance: 2
535150
- })).equal : existing === svg;
535149
+ });
535151
535150
  if (update) {
535152
535151
  if (!forceUpdate && equal) {
535153
535152
  console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
535154
535153
  } else {
535155
- fs26.writeFileSync(snapPath, svg);
535154
+ fs26.writeFileSync(snapPath, newSvg, "utf8");
535156
535155
  console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
535156
+ didUpdate = true;
535157
535157
  }
535158
535158
  } else if (!equal) {
535159
- if (looksSame) {
535160
- const diffPath = snapPath.replace(".snap.svg", ".diff.png");
535161
- await looksSame.createDiff({
535162
- reference: Buffer.from(existing),
535163
- current: Buffer.from(svg),
535164
- diff: diffPath,
535165
- highlightColor: "#ff00ff"
535166
- });
535167
- mismatches.push(`${snapPath} (diff: ${diffPath})`);
535168
- } else {
535169
- mismatches.push(snapPath);
535170
- }
535159
+ const diffPath = snapPath.replace(".snap.svg", ".diff.png");
535160
+ const diffBuffer = await looksSame.createDiff({
535161
+ reference: bufOld,
535162
+ current: bufNew,
535163
+ highlightColor: "#ff00ff",
535164
+ tolerance: 2,
535165
+ extension: "png"
535166
+ });
535167
+ fs26.writeFileSync(diffPath, diffBuffer);
535168
+ mismatches.push(`${snapPath} (diff: ${diffPath})`);
535169
+ } else {
535170
+ console.log("✅", kleur_default.gray(path26.relative(projectDir, snapPath)));
535171
535171
  }
535172
535172
  }
535173
535173
  }
535174
535174
  if (update) {
535175
- onSuccess("Created snapshots");
535175
+ didUpdate ? onSuccess("Created snapshots") : onSuccess("All snapshots already up to date");
535176
535176
  return onExit(0);
535177
535177
  }
535178
- if (mismatches.length > 0) {
535178
+ if (mismatches.length) {
535179
535179
  onError(`Snapshot mismatch:
535180
535180
  ${mismatches.join(`
535181
535181
  `)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.174",
3
+ "version": "0.1.175",
4
4
  "main": "dist/main.js",
5
5
  "devDependencies": {
6
6
  "@babel/standalone": "^7.26.9",