import "../_dnt.polyfills.js"; import * as dntShim from "../_dnt.shims.js"; import { CapiBinary } from "../deps/capi_binary_builds.js" import { Command } from "../deps/cliffy.js" export const bin = new Command() .description("Execute @ with [args...]") .arguments(" [...args:string]") .stopEarly() .example("run a polkadot node in dev mode", "capi bin polkadot v0.9.41 --dev") .example( "build a chain spec for Rococo local", "capi bin polkadot v0.9.41 build-spec --chain rococo-local", ) .action(runBin) async function runBin( _options: void, binary: string, version: string, ...args: string[] ) { const bin = new CapiBinary(binary, version) if (!(await bin.exists())) { console.error("Downloading", bin.key) await bin.download() } const child = new dntShim.Deno.Command(bin.path, { args, stdin: "inherit", stdout: "inherit", stderr: "inherit", }).spawn() for (const signal of ["SIGTERM", "SIGINT"] satisfies dntShim.Deno.Signal[]) { dntShim.Deno.addSignalListener(signal, () => { child.kill(signal) }) } dntShim.Deno.exit((await child.status).code) }