UNPKG

@beoe/rehype-penrose

Version:
23 lines (22 loc) 825 B
// import { type compile } from "@penrose/core"; import { spawn } from "node:child_process"; import { fileURLToPath } from "url"; import { resolve } from "node:path"; const executablePath = resolve(fileURLToPath(import.meta.url), `../../bin/penrose.js`); export const penrose = (opts) => { return new Promise((resolve, reject) => { let res = ""; const bin = spawn(executablePath, [], { windowsHide: true, }); bin.stdout.on("data", (data) => { res += data.toString(); }); bin.stderr.on("data", (data) => reject(data.toString())); bin.on("close", (code) => code === 0 ? resolve(res) : reject(`child process exited with code ${code}`)); bin.stdin.write(JSON.stringify(opts)); bin.stdin.end(); }); };