From 14b0f7fc1219d48a40916fa01a82381613cf550f Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Tue, 27 Feb 2024 16:40:52 +0000 Subject: [PATCH] gen-screenshot: make CSS file argument optional This will allow you to avoid having to pass gen-screenshot an empty file when you only want to use stylesheet links in `screenshot-page.html`. --- gen-screenshot.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gen-screenshot.ts b/gen-screenshot.ts index 2311690..95c367f 100755 --- a/gen-screenshot.ts +++ b/gen-screenshot.ts @@ -26,20 +26,20 @@ const saveScreenshot = async (src: string, dest: string) => { await browser.close(); }; -if (Deno.args.length !== 2) { +if (Deno.args.length < 1 || Deno.args.length > 2) { console.error( - "usage: gen-screenshot.ts project-name css-file\n\n" + + "usage: gen-screenshot.ts project-name [css-file]\n\n" + "The image filename will be derived from the project name.", ); Deno.exit(1); } const screenshotFile = `${slugify(Deno.args[0])}.png`; -const cssFile = Deno.args[1]; +const cssFile = Deno.args[1] || ""; try { const htmlTemplate = await Deno.readTextFile(templateFile); - const css = await Deno.readTextFile(cssFile); + const css = cssFile === "" ? "" : await Deno.readTextFile(cssFile); const html = htmlTemplate.replace(/%CSS_HERE%/, css); await Deno.writeTextFile(temporaryFile, html);