-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathinstall.js
47 lines (42 loc) · 1.5 KB
/
install.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
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, refreshSketchybar = true) {
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`
);
}
if (refreshSketchybar) {
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]);
}