forked from kvndrsslr/sketchybar-app-font
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
74 lines (64 loc) · 1.58 KB
/
build.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { execSync } from "node:child_process";
import fs from "node:fs";
import { pathToFileURL } from "node:url";
export const startMarker = "### START-OF-ICON-MAP";
export const endMarker = "### END-OF-ICON-MAP";
export function build() {
execSync("./node_modules/.bin/svgtofont -s svgs/ -o dist/", {
stdio: "inherit",
});
const iconMap = fs.readdirSync("./mappings").map((file) => {
const iconName = file.replace(".svg", "");
const appNames = fs.readFileSync(`./mappings/${file}`, "utf8").trim();
return {
iconName,
appNames,
};
});
const iconMapBashFn = `
${startMarker}
function __icon_map() {
case "$1" in
${iconMap
.map(
({ appNames, iconName }) =>
` ${appNames})
icon_result="${iconName}"
;;`,
)
.join("\n")}
*)
icon_result=":default:"
;;
esac
}
${endMarker}`;
fs.writeFileSync(
"./dist/icon_map.sh",
`#!/usr/bin/env bash
${iconMapBashFn}
`,
"utf8",
);
const iconMapLua = `return {
${iconMap
.map(({ appNames, iconName }) =>
appNames
.split("|")
// remove all * in mappings
.map((app) => app.replace("*", ""))
.map((app) => `\t[${app.trim()}] = "${iconName}",`)
.join("\n"),
)
.join("\n")}
}`;
fs.writeFileSync("./dist/icon_map.lua", iconMapLua, "utf8");
// chmod +x ./dist/icon_map.sh
fs.chmodSync("./dist/icon_map.sh", 0o755);
return { iconMapBashFn };
}
// only execute if run directly (ESM)
// use url instead of __filename to support pnpm
if (import.meta.url === pathToFileURL(process.argv[1]).toString()) {
build();
}