imrishabh18/rp2040-motor-controller
An RP2040-based NEMA17 stepper-motor controller with USB-C programming and PD motor-power negotiation, DRV8825 dual H-bridge drive, current/temperature telemetry, protected power filtering, status RGB LED, buzzer alarm, and optional magnetic encoder.
- Version
- 1.0.42
- License
- unset
- Stars
- 3
scripts/dev.ts
import { mkdir } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const projectDir = resolve(import.meta.dir, "..");
// Built from @tscircuit/eval v0.0.1506 against this project's pinned core
// and its geometry-contact checker patch, rather than the browser's bundled core.
const workerPath = join(projectDir, ".tscircuit/preview-runtime/worker.js");
const manifest = await Bun.file(join(projectDir, ".tscircuit/preview-runtime/manifest.json")).json();
const projectPackage = await Bun.file(join(projectDir, "package.json")).json();
if (manifest.coreVersion !== projectPackage.overrides["@tscircuit/core"]) {
throw new Error("Rebuild the preview worker after changing the pinned core version.");
}
// The tscircuit/browser bundle embeds its own core; package overrides cannot
// change it. Supply the matching evaluator explicitly using runframe's worker
// injection point and the CLI's supported standalone-file override.
const standalone = await Bun.file(fileURLToPath(import.meta.resolve("@tscircuit/runframe/standalone"))).text();
const injectionPoint = '"<--INJECT_TSCIRCUIT_EVAL_WEB_WORKER_BLOB_URL-->"';
if (standalone.split(injectionPoint).length !== 2) {
throw new Error("Runframe worker injection point changed; review the preview adapter.");
}
const workerBase64 = Buffer.from(await Bun.file(workerPath).arrayBuffer()).toString("base64");
const prefix = `const motorPreviewWorkerUrl=URL.createObjectURL(new Blob([new TextDecoder().decode(Uint8Array.from(atob(${JSON.stringify(workerBase64)}), c => c.charCodeAt(0)))],{type:"application/javascript"}));\n`;
const outputDir = join(projectDir, ".tscircuit/preview-runtime");
await mkdir(outputDir, { recursive: true });
const standalonePath = join(outputDir, "standalone.min.js");
await Bun.write(standalonePath, prefix + standalone.replace(injectionPoint, "motorPreviewWorkerUrl"));
console.log(`Preview: core ${manifest.coreVersion}, checks ${manifest.checksVersion} (local patched runtime)`);
const child = Bun.spawn([
process.execPath, join(projectDir, "node_modules/.bin/tsci"), "dev", ...process.argv.slice(2),
], {
cwd: projectDir,
env: { ...process.env, RUNFRAME_STANDALONE_FILE_PATH: standalonePath },
stdin: "inherit", stdout: "inherit", stderr: "inherit",
});
process.on("SIGINT", () => child.kill("SIGINT"));
process.on("SIGTERM", () => child.kill("SIGTERM"));
process.exit(await child.exited);
