Prettier had never been run in --check mode here before, so this had drifted across most files (markdown tables, long option() chains, line wrapping). Purely formatting, no logic changes - needed so a CI format:check gate can actually pass. Adds .prettierignore for pnpm-lock.yaml specifically: prettier's YAML formatter rewrites every quoted key (single -> double quotes) producing an ~8700-line diff of pure noise on a file pnpm itself owns the formatting of. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
export const SERVICE_NAME = "triggershell";
|
|
|
|
export interface UnitOptions {
|
|
execPath: string;
|
|
binPath: string;
|
|
configPath: string;
|
|
configDir: string;
|
|
port?: number;
|
|
host?: string;
|
|
scope: "user" | "system";
|
|
}
|
|
|
|
export function renderUnit(opts: UnitOptions): string {
|
|
const args = ["start", "--config", opts.configPath, "--no-browser"];
|
|
if (opts.port !== undefined) args.push("--port", String(opts.port));
|
|
if (opts.host !== undefined) args.push("--host", opts.host);
|
|
|
|
const execStart = [opts.execPath, opts.binPath, ...args]
|
|
.map((part) => (part.includes(" ") ? `"${part}"` : part))
|
|
.join(" ");
|
|
|
|
const wantedBy =
|
|
opts.scope === "user" ? "default.target" : "multi-user.target";
|
|
|
|
return `[Unit]
|
|
Description=TriggerShell - self-hosted script runner
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=${execStart}
|
|
WorkingDirectory=${opts.configDir}
|
|
Restart=on-failure
|
|
RestartSec=2
|
|
Environment=NODE_ENV=production
|
|
|
|
[Install]
|
|
WantedBy=${wantedBy}
|
|
`;
|
|
}
|
|
|
|
export function userUnitPath(): string {
|
|
return path.join(
|
|
os.homedir(),
|
|
".config",
|
|
"systemd",
|
|
"user",
|
|
`${SERVICE_NAME}.service`,
|
|
);
|
|
}
|
|
|
|
export function systemUnitPath(): string {
|
|
return path.join("/etc", "systemd", "system", `${SERVICE_NAME}.service`);
|
|
}
|
|
|
|
export function isRoot(): boolean {
|
|
return process.getuid?.() === 0;
|
|
}
|