@sterliakov/toggl-tracker
Version:
A simple cross-platform GUI for Toggl tracker API.
42 lines (36 loc) • 1.25 kB
JavaScript
const { spawnSync } = require("node:child_process");
/**
* Returns the executable path which is located inside `node_modules`
* The naming convention is toggl-tracker-${os}-${arch}
* If the platform is `win32` or `cygwin`, executable will include a `.exe` extension.
* @see https://nodejs.org/api/os.html#osarch
* @see https://nodejs.org/api/os.html#osplatform
* @example "x/xx/node_modules/toggl-tracker-darwin-arm64"
*/
function getExePath() {
const arch = process.arch;
let os = process.platform;
let extension = "";
if (["win32", "cygwin"].includes(process.platform)) {
os = "windows";
extension = ".exe";
}
try {
// Since the binary will be located inside `node_modules`, we can simply call `require.resolve`
return require.resolve(`@sterliakov/toggl-tracker-${os}-${arch}/bin/toggl-tracker${extension}`);
} catch (e) {
throw new Error(
`Couldn't find application binary inside node_modules for ${os}-${arch}`
);
}
}
/**
* Runs the application with args using nodejs spawn
*/
function run() {
const args = process.argv.slice(2);
const processResult = spawnSync(getExePath(), args, { stdio: "inherit" });
process.exit(processResult.status ?? 0);
}
run();