From 729f973cb61fe594c35e859ed9285f678ca3f65c Mon Sep 17 00:00:00 2001 From: Sarah Wang Date: Mon, 10 Jun 2024 18:50:07 -0400 Subject: [PATCH] working version of cli --- memory-viz/bin/cli.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/memory-viz/bin/cli.js b/memory-viz/bin/cli.js index e742781a..cb907b6c 100644 --- a/memory-viz/bin/cli.js +++ b/memory-viz/bin/cli.js @@ -1,8 +1,13 @@ #!/usr/bin/env node -console.log("Hola amigos"); +const fs = require("fs"); +const path = require("path"); +const { draw } = require("memory-viz"); -// args[1] is the path to the JSON file (display error for when the path is not valid) -// how to run the file? -// convert JSON to JS (JSON.parse) -// run memoryviz on the output object (error checking for invalid JSON) -// save the generated svg +const filePath = process.argv[2]; +const absolutePath = path.resolve(filePath); +const fileContent = fs.readFileSync(absolutePath, "utf8"); +const data = JSON.parse(fileContent); + +const m = draw(data, true, { width: 1300 }); + +m.save("my_demo.svg");