@scrylog/cli 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/service/manager.ts +32 -1
package/package.json
CHANGED
package/src/service/manager.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
3
4
|
import { getResolvedConfigPath } from "../shared/config";
|
|
4
5
|
import {
|
|
5
6
|
ensureParentDir,
|
|
@@ -63,6 +64,7 @@ export function resolveDaemonExec(configPath?: string, daemonPath = whichCommand
|
|
|
63
64
|
export function renderLaunchAgentPlist(configPath?: string): string {
|
|
64
65
|
const args = resolveDaemonExec(configPath);
|
|
65
66
|
const programArguments = args.map((arg) => ` <string>${xmlEscape(arg)}</string>`).join("\n");
|
|
67
|
+
const path = launchdPath(args);
|
|
66
68
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
67
69
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
68
70
|
<plist version="1.0">
|
|
@@ -73,6 +75,11 @@ export function renderLaunchAgentPlist(configPath?: string): string {
|
|
|
73
75
|
<array>
|
|
74
76
|
${programArguments}
|
|
75
77
|
</array>
|
|
78
|
+
<key>EnvironmentVariables</key>
|
|
79
|
+
<dict>
|
|
80
|
+
<key>PATH</key>
|
|
81
|
+
<string>${xmlEscape(path)}</string>
|
|
82
|
+
</dict>
|
|
76
83
|
<key>RunAtLoad</key>
|
|
77
84
|
<true/>
|
|
78
85
|
<key>KeepAlive</key>
|
|
@@ -241,6 +248,30 @@ function shellQuote(value: string): string {
|
|
|
241
248
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
242
249
|
}
|
|
243
250
|
|
|
251
|
+
function launchdPath(args: string[]): string {
|
|
252
|
+
const commandPath = args[0];
|
|
253
|
+
const candidates = [
|
|
254
|
+
commandPath && isAbsolute(commandPath) ? dirname(commandPath) : undefined,
|
|
255
|
+
isAbsolute(process.execPath) ? dirname(process.execPath) : undefined,
|
|
256
|
+
process.env.PATH,
|
|
257
|
+
join(homedir(), ".bun", "bin"),
|
|
258
|
+
"/opt/homebrew/bin",
|
|
259
|
+
"/usr/local/bin",
|
|
260
|
+
"/usr/bin",
|
|
261
|
+
"/bin",
|
|
262
|
+
"/usr/sbin",
|
|
263
|
+
"/sbin",
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
const paths = new Set<string>();
|
|
267
|
+
for (const candidate of candidates) {
|
|
268
|
+
for (const part of candidate?.split(":") ?? []) {
|
|
269
|
+
if (part) paths.add(part);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return Array.from(paths).join(":");
|
|
273
|
+
}
|
|
274
|
+
|
|
244
275
|
function xmlEscape(value: string): string {
|
|
245
276
|
return value
|
|
246
277
|
.replace(/&/g, "&")
|