Generate visual representations of the networks underlying video-gamebooks on YouTube
https://youtube-maze.delab.re/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
834 B
35 lines
834 B
import { spawn } from 'child_process';
|
|
import xml2js from 'xml2js';
|
|
|
|
const parser = new xml2js.Parser();
|
|
const builder = new xml2js.Builder({ headless: true });
|
|
|
|
const invokeDot = (input, format) => new Promise((resolve, reject) =>
|
|
{
|
|
const dot = spawn('dot', [`-T${format}`]);
|
|
let stdout = '';
|
|
|
|
dot.stdout.on('data', data => stdout += data);
|
|
|
|
dot.on('close', code => {
|
|
if (code !== 0)
|
|
{
|
|
reject(new Error(`dot returned error code ${code}`));
|
|
}
|
|
else
|
|
{
|
|
resolve(stdout);
|
|
}
|
|
});
|
|
|
|
dot.on('error', reject);
|
|
dot.stdin.write(input);
|
|
dot.stdin.end();
|
|
});
|
|
|
|
export const toSVG = async input =>
|
|
{
|
|
const svg = await invokeDot(input, 'svg');
|
|
const parsed = await parser.parseStringPromise(svg);
|
|
return builder.buildObject(parsed);
|
|
};
|
|
|