@syengup/friday-channel-next 0.0.18 → 0.0.20
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/install.js +95 -9
- 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
|
|
12
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
|
|
@@ -108,16 +151,36 @@ process.chdir(PLUGIN_DIR);
|
|
|
108
151
|
// --------------- install + build ---------------
|
|
109
152
|
|
|
110
153
|
log("Installing dependencies...");
|
|
111
|
-
|
|
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
|
+
}
|
|
112
162
|
|
|
113
163
|
log("Building TypeScript...");
|
|
114
|
-
|
|
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
|
+
}
|
|
115
171
|
|
|
116
172
|
// --------------- configure OpenClaw ---------------
|
|
117
173
|
|
|
118
174
|
log("Configuring OpenClaw...");
|
|
119
175
|
|
|
120
|
-
|
|
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
|
+
}
|
|
121
184
|
|
|
122
185
|
if (!config.plugins) config.plugins = {};
|
|
123
186
|
if (!Array.isArray(config.plugins.allow)) config.plugins.allow = [];
|
|
@@ -156,13 +219,36 @@ if (config.gateway.bind !== "lan") {
|
|
|
156
219
|
console.log(" + Set gateway.bind to lan");
|
|
157
220
|
}
|
|
158
221
|
|
|
159
|
-
|
|
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
|
+
}
|
|
160
229
|
console.log(" Config updated.");
|
|
161
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
|
+
|
|
162
240
|
// --------------- restart gateway ---------------
|
|
163
241
|
|
|
164
242
|
log("Restarting OpenClaw gateway...");
|
|
165
|
-
|
|
243
|
+
try {
|
|
244
|
+
const out = execSync(`${openclawCmd} gateway restart`, { encoding: "utf8", stdio: "pipe" });
|
|
245
|
+
if (out.trim()) console.log(out.trim());
|
|
246
|
+
} catch (e) {
|
|
247
|
+
if (e.stdout?.trim()) console.log(e.stdout.trim());
|
|
248
|
+
if (e.stderr?.trim()) console.error(e.stderr.trim());
|
|
249
|
+
warn("Gateway restart failed. The plugin files are installed but the gateway was not restarted.");
|
|
250
|
+
warn("Check 'openclaw gateway status' and restart manually: openclaw gateway restart");
|
|
251
|
+
}
|
|
166
252
|
|
|
167
253
|
// --------------- verify ---------------
|
|
168
254
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syengup/friday-channel-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
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": {
|