MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / generateLaunchdPlist

Function generateLaunchdPlist

apps/cli/src/service.ts:278–324  ·  view source on GitHub ↗
(options: LaunchdPlistOptions)

Source from the content-addressed store, hash-verified

276 * keeps it off the foreground scheduler.
277 */
278export const generateLaunchdPlist = (options: LaunchdPlistOptions): string => {
279 const programArgs = options.programArguments
280 .map((arg) => ` <string>${xmlEscape(arg)}</string>`)
281 .join("\n");
282 const bundleIdentifier = associatedBundleIdentifier(options.programArguments);
283 const associatedBundleIdentifiers = bundleIdentifier
284 ? ` <key>AssociatedBundleIdentifiers</key>\n <array>\n <string>${xmlEscape(bundleIdentifier)}</string>\n </array>\n`
285 : "";
286 const envEntries = Object.entries(options.environment)
287 .map(
288 ([key, value]) =>
289 ` <key>${xmlEscape(key)}</key>\n <string>${xmlEscape(value)}</string>`,
290 )
291 .join("\n");
292 return `<?xml version="1.0" encoding="UTF-8"?>
293<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
294<plist version="1.0">
295<dict>
296 <key>Label</key>
297 <string>${xmlEscape(options.label)}</string>
298${associatedBundleIdentifiers} <key>ProgramArguments</key>
299 <array>
300${programArgs}
301 </array>
302 <key>EnvironmentVariables</key>
303 <dict>
304${envEntries}
305 </dict>
306 <key>RunAtLoad</key>
307 <true/>
308 <key>KeepAlive</key>
309 <dict>
310 <key>SuccessfulExit</key>
311 <false/>
312 </dict>
313 <key>ProcessType</key>
314 <string>Background</string>
315 <key>WorkingDirectory</key>
316 <string>${xmlEscape(options.workingDirectory)}</string>
317 <key>StandardOutPath</key>
318 <string>${xmlEscape(options.stdoutPath)}</string>
319 <key>StandardErrorPath</key>
320 <string>${xmlEscape(options.stderrPath)}</string>
321</dict>
322</plist>
323`;
324};
325
326const parseLaunchctlPid = (printOutput: string): number | null => {
327 const match = printOutput.match(/\bpid\s*=\s*(\d+)/);

Callers 2

service.test.tsFile · 0.90
makeLaunchdBackendFunction · 0.85

Calls 2

xmlEscapeFunction · 0.70

Tested by

no test coverage detected