krishnax12/watchy-eink-smartwatch

Unfinished prototype (not production-ready): 4 native DRC errors, 2 display-flex intersections, and missing antenna radiator copper remain

Version
1.2.7
License
MIT
Stars
1

scripts/route-local-core.tsx

import { cloneElement } from "react";
import type { BoardProps } from "@tscircuit/props";

const coreModulePath = process.env.WATCHY_CORE_MODULE ?? "@tscircuit/core";
const { Circuit } = (await import(
	coreModulePath
)) as typeof import("@tscircuit/core");

const reportDirectory =
	process.env.WATCHY_ROUTING_REPORT_DIR ?? "reports/local-core-routing";
const circuitOutputPath =
	process.env.WATCHY_ROUTING_OUTPUT ?? "dist/index/circuit.json";

const compiled = await Bun.build({
	entrypoints: ["index.circuit.tsx"],
	outdir: "reports/local-core-build",
	target: "bun",
	packages: "external",
	loader: { ".step": "file" },
});
if (!compiled.success) throw new Error(compiled.logs.join("\n"));
const { default: Watchy } = await import(
	`${process.cwd()}/reports/local-core-build/index.circuit.js`
);
const circuit = new Circuit({ platform: { partsEngineDisabled: true } });
const writes: Promise<unknown>[] = [];
let phaseIndex = -1;
let lastProgressAt = 0;
console.log(
	"Using @tscircuit/core module",
	coreModulePath,
	circuit.getCoreVersion(),
);
circuit.on("autorouting:start", (event) => {
	phaseIndex++;
	console.log(
		"Start phase",
		phaseIndex,
		"connections",
		event.simpleRouteJson.connections.length,
	);
	writes.push(
		Bun.write(
			`${reportDirectory}/phase-${phaseIndex}.input.json`,
			JSON.stringify(event.simpleRouteJson, null, 2),
		),
	);
});
circuit.on("autorouting:progress", (event) => {
	if (Date.now() - lastProgressAt < 10000) return;
	lastProgressAt = Date.now();
	console.log("Routing phase", phaseIndex, event.phase);
});
circuit.on("autorouting:end", (event) => {
	console.log(
		"End phase",
		phaseIndex,
		"traces",
		event.simpleRouteJson.traces?.length,
	);
	writes.push(
		Bun.write(
			`${reportDirectory}/phase-${phaseIndex}.output.json`,
			JSON.stringify(event.simpleRouteJson, null, 2),
		),
	);
});
const deadline = setTimeout(() => {
	console.error("Local routing exceeded ten minutes");
	process.exit(1);
}, 600000);
const board = Watchy({
	routingDisabled: process.env.WATCHY_PLACEMENT_ONLY === "1",
});
circuit.add(
	process.env.WATCHY_AUTOROUTER_VERSION
		? cloneElement<BoardProps>(board, {
				autorouterVersion: process.env.WATCHY_AUTOROUTER_VERSION,
			})
		: board,
);
try {
	await circuit.renderUntilSettled();
	await Promise.all(writes);
	const circuitJson = circuit.getCircuitJson();
	await Bun.write(circuitOutputPath, JSON.stringify(circuitJson, null, 2));
	const errors = circuitJson.filter((element) =>
		element.type.endsWith("_error"),
	);
	console.log("DRC errors:", errors.length);
	if (errors.length) process.exitCode = 1;
} finally {
	clearTimeout(deadline);
}