chore: modernize
This commit is contained in:
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"fontName": "sketchybar-app-font",
|
|
||||||
"css": false,
|
|
||||||
"emptyDist": true,
|
|
||||||
"useNameAsUnicode": true
|
|
||||||
}
|
|
61
build.js
Normal file
61
build.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
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"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
echo '
|
|
||||||
function icon_map() {
|
|
||||||
case "$1" in
|
|
||||||
'"$(find ./mappings/ -type f -exec sh -c 'x={};echo "${x##*/}\t$(cat {})"' \; | awk -F "\t" '{print " " $2 ")\n icon_result=\"" $1 "\"\n ;;"}')"'
|
|
||||||
*)
|
|
||||||
icon_result=":default:"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
' > dist/icon_map_fn.sh
|
|
||||||
|
|
45
install.js
Normal file
45
install.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import { execSync } from "node:child_process";
|
||||||
|
import { build, startMarker, endMarker } from "./build.js";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import { pathToFileURL } from "node:url";
|
||||||
|
|
||||||
|
export function install(replaceInScriptPath) {
|
||||||
|
const { iconMapBashFn } = build();
|
||||||
|
|
||||||
|
fs.copyFileSync(
|
||||||
|
"./dist/sketchybar-app-font.ttf",
|
||||||
|
`${process.env.HOME}/Library/Fonts/sketchybar-app-font.ttf`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (replaceInScriptPath) {
|
||||||
|
const pathToScript = path.resolve(replaceInScriptPath);
|
||||||
|
const scriptContents = fs.readFileSync(pathToScript, "utf8");
|
||||||
|
const startMarkerIndex = scriptContents.indexOf(startMarker);
|
||||||
|
const endMarkerIndex = scriptContents.indexOf(endMarker);
|
||||||
|
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
||||||
|
console.error(
|
||||||
|
`Could not find ${startMarker} or ${endMarker} in ${pathToScript}`
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
const newScriptContents =
|
||||||
|
scriptContents.slice(0, startMarkerIndex) +
|
||||||
|
iconMapBashFn +
|
||||||
|
scriptContents.slice(endMarkerIndex + endMarker.length);
|
||||||
|
fs.writeFileSync(pathToScript, newScriptContents, "utf8");
|
||||||
|
} else {
|
||||||
|
fs.copyFileSync(
|
||||||
|
"./dist/icon-map.sh",
|
||||||
|
`${process.env.HOME}/.config/sketchybar/icon-map.sh`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
execSync("sketchybar --reload");
|
||||||
|
}
|
||||||
|
|
||||||
|
// only execute if run directly (ESM)
|
||||||
|
// use url instead of __filename to support pnpm
|
||||||
|
if (import.meta.url === pathToFileURL(process.argv[1]).toString()) {
|
||||||
|
install(process.argv[2]);
|
||||||
|
}
|
4662
package-lock.json
generated
4662
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -1,14 +1,27 @@
|
|||||||
{
|
{
|
||||||
|
"type": "module",
|
||||||
"name": "sketchybar-app-font",
|
"name": "sketchybar-app-font",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "App font for sketchybar, bootstrapped using SVGs from simple-bar",
|
"description": "App font for sketchybar, bootstrapped using SVGs from simple-bar",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "svgtofont -s svgs/ -o dist/ && ./generate_icon_map_fn.sh"
|
"build": "node ./build.js",
|
||||||
|
"install": "node ./install.js",
|
||||||
|
"dev": "node ./watch.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Kevin Dreßler",
|
"author": "Kevin Dreßler",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"svgtofont": "^3.17.8"
|
"svgtofont": "^4.1.1"
|
||||||
|
},
|
||||||
|
"svgtofont": {
|
||||||
|
"fontName": "sketchybar-app-font",
|
||||||
|
"website": false,
|
||||||
|
"css": false,
|
||||||
|
"emptyDist": true,
|
||||||
|
"useNameAsUnicode": true
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"chokidar": "^3.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1017
pnpm-lock.yaml
generated
1017
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
|
||||||
<defs>
|
<defs>
|
||||||
<linearGradient id="linear0" gradientUnits="userSpaceOnUse" x1="49.021549" y1="-0.0798354" x2="49.021549" y2="97.845657" gradientTransform="matrix(0.046407,0,0,0.217825,3.221968,0.889505)">
|
<linearGradient id="linear0" gradientUnits="userSpaceOnUse" x1="49.021549" y1="-0.0798354" x2="49.021549" y2="97.845657" gradientTransform="matrix(0.046407,0,0,0.217825,3.221968,0.889505)">
|
||||||
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.5 KiB |
Reference in New Issue
Block a user