@ours.network/tg-connector 0.3.3-nightly.2 → 0.3.3-nightly.4
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/dist/cli.js +41 -23
- package/dist/connector.js +1992 -1959
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -140,6 +140,40 @@ function serviceEnvironment(config, stateDir) {
|
|
|
140
140
|
if (config.daemonStateDir) env.OURS_TG_DAEMON_STATE_DIR = config.daemonStateDir;
|
|
141
141
|
return env;
|
|
142
142
|
}
|
|
143
|
+
function xmlText(value) {
|
|
144
|
+
return String(value).replace(/[&<>"']/g, (character) => ({
|
|
145
|
+
"&": "&",
|
|
146
|
+
"<": "<",
|
|
147
|
+
">": ">",
|
|
148
|
+
'"': """,
|
|
149
|
+
"'": "'"
|
|
150
|
+
})[character]);
|
|
151
|
+
}
|
|
152
|
+
function launchdPlist(input) {
|
|
153
|
+
const envEntries = Object.entries(input.env).map(([key, value]) => ` <key>${xmlText(key)}</key><string>${xmlText(value)}</string>`).join("\n");
|
|
154
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
155
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
156
|
+
<plist version="1.0">
|
|
157
|
+
<dict>
|
|
158
|
+
<key>Label</key><string>${xmlText(input.label)}</string>
|
|
159
|
+
<key>ProgramArguments</key>
|
|
160
|
+
<array>
|
|
161
|
+
<string>${xmlText(input.execPath)}</string>
|
|
162
|
+
<string>${xmlText(input.self)}</string>
|
|
163
|
+
<string>serve</string>
|
|
164
|
+
</array>
|
|
165
|
+
<key>EnvironmentVariables</key>
|
|
166
|
+
<dict>
|
|
167
|
+
${envEntries}
|
|
168
|
+
</dict>
|
|
169
|
+
<key>RunAtLoad</key><true/>
|
|
170
|
+
<key>KeepAlive</key><true/>
|
|
171
|
+
<key>StandardOutPath</key><string>${xmlText(input.logPath)}</string>
|
|
172
|
+
<key>StandardErrorPath</key><string>${xmlText(input.logPath)}</string>
|
|
173
|
+
</dict>
|
|
174
|
+
</plist>
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
143
177
|
|
|
144
178
|
// src/routing.ts
|
|
145
179
|
function looksLikeBotToken(s) {
|
|
@@ -559,29 +593,13 @@ function installLaunchd() {
|
|
|
559
593
|
const plistPath = launchdPlistPath();
|
|
560
594
|
fs2.mkdirSync(dirname2(plistPath), { recursive: true });
|
|
561
595
|
const env = serviceEnv();
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
<array>
|
|
570
|
-
<string>${process.execPath}</string>
|
|
571
|
-
<string>${SELF}</string>
|
|
572
|
-
<string>serve</string>
|
|
573
|
-
</array>
|
|
574
|
-
<key>EnvironmentVariables</key>
|
|
575
|
-
<dict>
|
|
576
|
-
${envEntries}
|
|
577
|
-
</dict>
|
|
578
|
-
<key>RunAtLoad</key><true/>
|
|
579
|
-
<key>KeepAlive</key><true/>
|
|
580
|
-
<key>StandardOutPath</key><string>${LOG_PATH}</string>
|
|
581
|
-
<key>StandardErrorPath</key><string>${LOG_PATH}</string>
|
|
582
|
-
</dict>
|
|
583
|
-
</plist>
|
|
584
|
-
`;
|
|
596
|
+
const plist = launchdPlist({
|
|
597
|
+
label: LAUNCHD_LABEL,
|
|
598
|
+
execPath: process.execPath,
|
|
599
|
+
self: SELF,
|
|
600
|
+
logPath: LOG_PATH,
|
|
601
|
+
env
|
|
602
|
+
});
|
|
585
603
|
fs2.writeFileSync(plistPath, plist);
|
|
586
604
|
out(`wrote ${plistPath}`);
|
|
587
605
|
run("launchctl", ["unload", plistPath]);
|