diff --git a/poptimal.js b/poptimal.js index 2fc1bc0..5232c74 100644 --- a/poptimal.js +++ b/poptimal.js @@ -2,6 +2,8 @@ import { Resvg } from "@resvg/resvg-js"; import { promises } from "fs"; import { JSDOM } from "jsdom"; import * as d3 from "d3"; +import yargs from "yargs/yargs"; +import { hideBin } from "yargs/helpers"; import random from "random"; @@ -86,19 +88,24 @@ function poptimal_svg() { } async function main() { - const svg = poptimal_svg(); + const argv = yargs(hideBin(process.argv)) + .usage("Usage: -w WIDTH -o OUTPUT_PNG") + .default('w', 1200) + .default('o', 'poptimal.png').argv; + + const svg = poptimal_svg(argv.w); const opts = { background: 'rgba(255, 255, 255, 1.0)', fitTo: { mode: 'width', - value: 1200, + value: argv.w, }, }; const resvg = new Resvg(svg, opts) const pngData = resvg.render() const pngBuffer = pngData.asPng() - await promises.writeFile('test.png', pngBuffer); + await promises.writeFile(argv.o, pngBuffer); }