@syengup/friday-channel-next 0.0.17 → 0.0.19

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.
Files changed (3) hide show
  1. package/install.js +99 -11
  2. package/install.sh +9 -7
  3. package/package.json +2 -1
package/install.js CHANGED
@@ -8,8 +8,27 @@ import { fileURLToPath } from "node:url";
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = dirname(__filename);
10
10
 
11
- const PLUGIN_DIR = process.argv[2] || join(homedir(), ".openclaw", "extensions", "friday-channel-next");
12
- const OPENCLAW_CONFIG = join(homedir(), ".openclaw", "openclaw.json");
11
+ const sudoUser = process.env.SUDO_USER;
12
+
13
+ function realHome() {
14
+ if (!sudoUser) return homedir();
15
+ // Under sudo, homedir() may return /root. Check if HOME was preserved.
16
+ const current = homedir();
17
+ if (current !== "/root" && current !== "/var/root" && existsSync(current)) return current;
18
+ // Resolve the real user's home
19
+ try {
20
+ const h = execSync(`sh -c 'echo ~${sudoUser}'`, { encoding: "utf8" }).trim();
21
+ if (h && !h.startsWith("~") && existsSync(h)) return h;
22
+ } catch {}
23
+ for (const g of [`/home/${sudoUser}`, `/Users/${sudoUser}`]) {
24
+ if (existsSync(g)) return g;
25
+ }
26
+ return current;
27
+ }
28
+
29
+ const USER_HOME = realHome();
30
+ const PLUGIN_DIR = process.argv[2] || join(USER_HOME, ".openclaw", "extensions", "friday-channel-next");
31
+ const OPENCLAW_CONFIG = join(USER_HOME, ".openclaw", "openclaw.json");
13
32
  const REPO_URL = process.env.FRIDAY_NEXT_REPO || "https://github.com/SyengUp/openclaw-fridaynext-channel.git";
14
33
 
15
34
  const G = (s) => `\x1b[32m${s}\x1b[0m`;
@@ -34,6 +53,20 @@ function has(cmd) {
34
53
  }
35
54
  }
36
55
 
56
+ let openclawCmd = "openclaw";
57
+
58
+ function hasOpenclaw() {
59
+ if (has("openclaw")) return true;
60
+ if (!sudoUser) return false;
61
+ // Under sudo, openclaw isn't in root's PATH — run via the real user.
62
+ try {
63
+ execSync(`sudo -u "${sudoUser}" openclaw --version`, { stdio: "ignore" });
64
+ openclawCmd = `sudo -u "${sudoUser}" openclaw`;
65
+ return true;
66
+ } catch {}
67
+ return false;
68
+ }
69
+
37
70
  // Running from an npm/npx package when we have the full source (index.ts + package.json)
38
71
  // and are NOT already inside the target plugin dir.
39
72
  function isRunningFromNpmPackage() {
@@ -46,10 +79,20 @@ function isRunningFromNpmPackage() {
46
79
 
47
80
  // --------------- prerequisites ---------------
48
81
 
49
- const required = ["node", "openclaw"];
50
- const missing = required.filter((c) => !has(c));
82
+ if (sudoUser) {
83
+ warn("Running under sudo is unnecessary and may cause issues.");
84
+ warn("If possible, run without sudo: npx -y @syengup/friday-channel-next");
85
+ }
86
+
87
+ const missing = [];
88
+ if (!has("node")) missing.push("node");
89
+ if (!hasOpenclaw()) missing.push("openclaw");
51
90
  if (missing.length) {
52
91
  missing.forEach((c) => err(`${c} is required but not found. Install it first.`));
92
+ if (sudoUser && missing.includes("openclaw")) {
93
+ err("Could not find openclaw even via the real user's PATH.");
94
+ err(`Check that openclaw is installed under ${USER_HOME}.`);
95
+ }
53
96
  process.exit(1);
54
97
  }
55
98
 
@@ -59,10 +102,15 @@ if (!PKG) {
59
102
  process.exit(1);
60
103
  }
61
104
 
62
- // Auto-detect best registry (if npmjs.org is unreachable, use npmmirror)
105
+ // Auto-detect best registry (measure latency; fall back to npmmirror if slow/unreachable)
63
106
  let registryFlag = "";
64
107
  try {
65
- execSync('curl -s --connect-timeout 3 --max-time 5 https://registry.npmjs.org/ >/dev/null 2>&1');
108
+ const start = Date.now();
109
+ execSync('curl -s -o /dev/null --connect-timeout 2 --max-time 4 https://registry.npmjs.org/', { stdio: "pipe", timeout: 6000 });
110
+ if (Date.now() - start > 1500) {
111
+ warn("Default registry slow, using https://registry.npmmirror.com");
112
+ registryFlag = "--registry=https://registry.npmmirror.com";
113
+ }
66
114
  } catch {
67
115
  warn("Default registry unreachable, using https://registry.npmmirror.com");
68
116
  registryFlag = "--registry=https://registry.npmmirror.com";
@@ -103,16 +151,36 @@ process.chdir(PLUGIN_DIR);
103
151
  // --------------- install + build ---------------
104
152
 
105
153
  log("Installing dependencies...");
106
- execSync(`${PKG} install ${registryFlag}`, { stdio: "inherit" });
154
+ try {
155
+ execSync(`${PKG} install ${registryFlag}`, { stdio: "inherit" });
156
+ } catch {
157
+ err("Dependency installation failed.");
158
+ err("Check your network connection and try again.");
159
+ if (sudoUser) err("If running under sudo, ensure the real user can access the package manager.");
160
+ process.exit(1);
161
+ }
107
162
 
108
163
  log("Building TypeScript...");
109
- execSync(`${PKG} run build`, { stdio: "inherit" });
164
+ try {
165
+ execSync(`${PKG} run build`, { stdio: "inherit" });
166
+ } catch {
167
+ err("TypeScript build failed.");
168
+ err("Check the compilation errors above and make sure the package is not corrupted.");
169
+ process.exit(1);
170
+ }
110
171
 
111
172
  // --------------- configure OpenClaw ---------------
112
173
 
113
174
  log("Configuring OpenClaw...");
114
175
 
115
- const config = JSON.parse(readFileSync(OPENCLAW_CONFIG, "utf8"));
176
+ let config;
177
+ try {
178
+ config = JSON.parse(readFileSync(OPENCLAW_CONFIG, "utf8"));
179
+ } catch {
180
+ err(`Failed to read ${OPENCLAW_CONFIG}.`);
181
+ err("The file may be missing or corrupted. Verify OpenClaw is installed correctly.");
182
+ process.exit(1);
183
+ }
116
184
 
117
185
  if (!config.plugins) config.plugins = {};
118
186
  if (!Array.isArray(config.plugins.allow)) config.plugins.allow = [];
@@ -151,13 +219,33 @@ if (config.gateway.bind !== "lan") {
151
219
  console.log(" + Set gateway.bind to lan");
152
220
  }
153
221
 
154
- writeFileSync(OPENCLAW_CONFIG, JSON.stringify(config, null, 2) + "\n", "utf8");
222
+ try {
223
+ writeFileSync(OPENCLAW_CONFIG, JSON.stringify(config, null, 2) + "\n", "utf8");
224
+ } catch {
225
+ err(`Failed to write ${OPENCLAW_CONFIG}.`);
226
+ err("Check disk space and file permissions.");
227
+ process.exit(1);
228
+ }
155
229
  console.log(" Config updated.");
156
230
 
231
+ if (sudoUser) {
232
+ try {
233
+ execSync(`chown -R "${sudoUser}" "${PLUGIN_DIR}" "${OPENCLAW_CONFIG}"`, { stdio: "ignore" });
234
+ log("Fixed file ownership back to " + sudoUser);
235
+ } catch {
236
+ warn("Could not fix file ownership — files in " + PLUGIN_DIR + " may be owned by root.");
237
+ }
238
+ }
239
+
157
240
  // --------------- restart gateway ---------------
158
241
 
159
242
  log("Restarting OpenClaw gateway...");
160
- execSync("openclaw gateway restart", { stdio: "inherit" });
243
+ try {
244
+ execSync(`${openclawCmd} gateway restart`, { stdio: "inherit" });
245
+ } catch {
246
+ warn("Gateway restart failed. The plugin files are installed but the gateway was not restarted.");
247
+ warn("Check 'openclaw gateway status' and restart manually: openclaw gateway restart");
248
+ }
161
249
 
162
250
  // --------------- verify ---------------
163
251
 
package/install.sh CHANGED
@@ -39,13 +39,15 @@ else
39
39
  exit 1
40
40
  fi
41
41
 
42
- # Auto-detect best registry (if npmjs.org is unreachable, use npmmirror)
43
- if curl -s --connect-timeout 3 https://registry.npmjs.org/ >/dev/null 2>&1; then
44
- REGISTRY=""
45
- else
46
- warn "Default registry unreachable, using https://registry.npmmirror.com"
47
- REGISTRY="--registry=https://registry.npmmirror.com"
48
- fi
42
+ # Auto-detect best registry (measure latency; fall back to npmmirror if slow/unreachable)
43
+ TIME=$(curl -s -o /dev/null -w '%{time_total}' --connect-timeout 2 --max-time 4 https://registry.npmjs.org/ 2>/dev/null || echo "999")
44
+ case "$TIME" in
45
+ 0.*) ;; # under 1s — fast enough
46
+ *)
47
+ warn "Default registry slow/unreachable, using https://registry.npmmirror.com"
48
+ REGISTRY="--registry=https://registry.npmmirror.com"
49
+ ;;
50
+ esac
49
51
 
50
52
  if [ ! -f "$OPENCLAW_CONFIG" ]; then
51
53
  err "OpenClaw config not found at $OPENCLAW_CONFIG"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syengup/friday-channel-next",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "description": "OpenClaw Friday Next Apple channel plugin",
5
5
  "type": "module",
6
6
  "files": [
@@ -53,6 +53,7 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
+ "apn": "^2.2.0",
56
57
  "qrcode-terminal": "^0.12.0"
57
58
  },
58
59
  "devDependencies": {