chore: modernize

This commit is contained in:
Kevin Dreßler
2024-01-28 14:04:35 +01:00
parent f6591f8a71
commit 7375212f06
9 changed files with 812 additions and 5016 deletions

45
install.js Normal file
View 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]);
}