24 lines
881 B
TypeScript
24 lines
881 B
TypeScript
import fs from "node:fs";
|
|||
|
|
import path from "node:path";
|
||
|
|
import { fileURLToPath } from "node:url";
|
||
|
|
|
||
|
|
const DEFAULT_CONFIG_NAME = "triggershell.yml";
|
||
|
|
|
||
|
|
/** Root of the installed `triggershell` package - one level up from `src/cli/lib`. */
|
||
|
|
export function resolveAppRoot(): string {
|
||
|
|
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveConfigPath(configArg?: string): string {
|
||
|
|
return path.resolve(process.cwd(), configArg ?? DEFAULT_CONFIG_NAME);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Absolute path to the script that was actually invoked (`node <this>`), with any symlink
|
||
|
|
* (as created by a global npm/pnpm install or `npm link`) resolved away. Used to build a
|
||
|
|
* `systemd` `ExecStart` line that keeps working regardless of how the CLI was installed.
|
||
|
|
*/
|
||
|
|
export function resolveInvokedBinPath(): string {
|
||
|
|
return fs.realpathSync(process.argv[1]);
|
||
|
|
}
|