-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-images.ts
executable file
·37 lines (32 loc) · 1.06 KB
/
generate-images.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bun
import { defineCommand, runMain } from "citty";
import { readdir } from "node:fs/promises";
import { $ } from "bun";
import sharp from "sharp";
const DOCSET_EXTENSION = ".tgz";
const main = defineCommand({
meta: {
name: "json",
version: "1.0.0",
description: "Docsets",
},
async run({ args, subCommand }) {
const docsetFiles = (await readdir("./docsets"))
?.filter((file) => file.endsWith(DOCSET_EXTENSION))
?.map((file) => file.slice(0, -DOCSET_EXTENSION.length));
for (const docset of docsetFiles) {
console.log("Extracting images from", docset);
const docsetPath = `./docsets/${docset}${DOCSET_EXTENSION}`;
const resp =
await $`tar -xvzf ${docsetPath} -C ./tmp/images ${docset}.docset/icon.tiff`.nothrow();
if (resp.exitCode !== 0) {
continue;
}
const tempImagePath = `./tmp/images/${docset}.docset/icon.tiff`;
const finalImagePath = `./images/${docset}.png`;
await sharp(tempImagePath).toFormat("png").toFile(finalImagePath);
console.log("Extracted image", finalImagePath);
}
},
});
runMain(main);