chore: modernize
This commit is contained in:
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]);
|
||||
}
|
Reference in New Issue
Block a user