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

Function generateLaunchdPlist

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

Source from the content-addressed store, hash-verified

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