trilium/scripts/utils.mts

30 lines
No EOL
931 B
TypeScript

import { execSync } from "child_process";
import { readFileSync } from "fs";
import { platform } from "os";
export function isNixOS() {
if (platform() !== "linux") return false;
const osReleaseFile = readFileSync("/etc/os-release", "utf-8");
return osReleaseFile.includes("ID=nixos");
}
function resetPath() {
// On Unix-like systems, PATH is usually inherited from login shell
// but npm prepends node_modules/.bin. Let's remove it:
const origPath = process.env.PATH || "";
// npm usually adds something like ".../node_modules/.bin"
process.env.PATH = origPath
.split(":")
.filter(p => !p.includes("node_modules/.bin"))
.join(":");
}
export function getElectronPath() {
if (isNixOS()) {
resetPath();
return execSync("nix eval --raw nixpkgs#electron_37").toString("utf-8") + "/bin/electron";
} else {
return "electron";
}
}