|
18 | 18 | */ |
19 | 19 |
|
20 | 20 | import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; |
21 | | -import { dirname, resolve } from "node:path"; |
22 | | -import { fileURLToPath } from "node:url"; |
| 21 | +import { resolve } from "node:path"; |
| 22 | +import { parseArgs } from "node:util"; |
23 | 23 | import pngToIco from "png-to-ico"; |
24 | 24 | import sharp from "sharp"; |
25 | 25 |
|
26 | | -const here = dirname(fileURLToPath(import.meta.url)); |
| 26 | +const { values: flags } = parseArgs({ |
| 27 | + options: { |
| 28 | + "screenshots-from-assets": { type: "boolean", default: false }, |
| 29 | + "placeholder-screenshots": { type: "boolean", default: false }, |
| 30 | + }, |
| 31 | +}); |
| 32 | + |
| 33 | +const here = import.meta.dirname; |
27 | 34 | const publicDir = resolve(here, "..", "public"); |
28 | 35 | const svg = readFileSync(resolve(publicDir, "icons", "icon.svg")); |
29 | 36 |
|
@@ -85,8 +92,8 @@ async function writeScreenshotFrom(source: string, width: number, height: number |
85 | 92 | } |
86 | 93 |
|
87 | 94 | const capture = resolve(here, "..", "assets", "screenshot.png"); |
88 | | -const fromAssets = process.argv.includes("--screenshots-from-assets"); |
89 | | -const overwriteScreenshots = process.argv.includes("--placeholder-screenshots"); |
| 95 | +const fromAssets = flags["screenshots-from-assets"]; |
| 96 | +const overwriteScreenshots = flags["placeholder-screenshots"]; |
90 | 97 | if (fromAssets && !existsSync(capture)) { |
91 | 98 | throw new Error("--screenshots-from-assets needs assets/screenshot.png (Baton/scripts/generate-screenshots.sh)"); |
92 | 99 | } |
|
0 commit comments