33 lines
891 B
JavaScript
33 lines
891 B
JavaScript
const { spawn } = require("child_process");
|
|
const path = require("path");
|
|
|
|
async function renderWithPython({ type, data, outputPath }) {
|
|
return new Promise((resolve, reject) => {
|
|
const scriptPath = path.resolve(__dirname, "../../render_stats_charts.py");
|
|
const child = spawn("python3", [scriptPath, "--type", type, "--output", outputPath], {
|
|
stdio: ["pipe", "inherit", "inherit"],
|
|
});
|
|
|
|
const payload = JSON.stringify(data);
|
|
child.stdin.write(payload);
|
|
child.stdin.end();
|
|
|
|
child.on("error", (error) => {
|
|
reject(error);
|
|
});
|
|
|
|
child.on("exit", (code) => {
|
|
if (code === 0) {
|
|
resolve();
|
|
} else {
|
|
reject(new Error(`Python renderer exited with code ${code}`));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
renderWithPython,
|
|
};
|
|
|