openclaw-vchat-plugin 0.0.2 → 0.0.3

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.
@@ -24,6 +24,23 @@ function hasCommand(cmd) {
24
24
  return res.status === 0;
25
25
  }
26
26
 
27
+ function pm2ProcessExists(name) {
28
+ const res = spawnSync('pm2', ['jlist'], {
29
+ encoding: 'utf8',
30
+ env: process.env,
31
+ cwd: packageRoot,
32
+ });
33
+ if (res.status !== 0) {
34
+ return false;
35
+ }
36
+ try {
37
+ const list = JSON.parse(res.stdout || '[]');
38
+ return Array.isArray(list) && list.some((item) => item && item.name === name);
39
+ } catch (_) {
40
+ return false;
41
+ }
42
+ }
43
+
27
44
  function getOpenClawHome() {
28
45
  const home = process.env.HOME || process.env.USERPROFILE || '';
29
46
  return process.env.OPENCLAW_HOME || path.join(home, '.openclaw');
@@ -153,11 +170,21 @@ async function install() {
153
170
  process.exit(1);
154
171
  }
155
172
  const name = 'openclaw-vchat';
156
- const start = spawnSync('pm2', ['start', process.execPath, '--name', name, '--', distEntry], {
157
- stdio: 'inherit',
158
- env: process.env,
159
- cwd: packageRoot,
160
- });
173
+ let start;
174
+ if (pm2ProcessExists(name)) {
175
+ console.log(`检测到现有 pm2 进程 ${name},改为重启并刷新配置`);
176
+ start = spawnSync('pm2', ['restart', name, '--update-env'], {
177
+ stdio: 'inherit',
178
+ env: process.env,
179
+ cwd: packageRoot,
180
+ });
181
+ } else {
182
+ start = spawnSync('pm2', ['start', process.execPath, '--name', name, '--', distEntry], {
183
+ stdio: 'inherit',
184
+ env: process.env,
185
+ cwd: packageRoot,
186
+ });
187
+ }
161
188
  if (start.status !== 0) {
162
189
  console.error('pm2 启动失败');
163
190
  process.exit(start.status || 1);
@@ -170,11 +197,12 @@ async function install() {
170
197
  cwd: packageRoot,
171
198
  });
172
199
  if (startup.status !== 0) {
173
- console.error('\npm2 startup 执行失败,请手动执行:pm2 startup && pm2 save');
174
- process.exit(startup.status || 1);
200
+ console.error('\npm2 startup 执行失败,通常是需要按上面提示再手动执行一次 sudo launchd 命令。');
201
+ console.error('安装不会中断,先继续二维码配对;开机自启可稍后补做。');
202
+ } else {
203
+ spawnSync('pm2', ['save'], { stdio: 'inherit', env: process.env, cwd: packageRoot });
204
+ console.log('\nStartup OK: 已尝试启用开机自启');
175
205
  }
176
- spawnSync('pm2', ['save'], { stdio: 'inherit', env: process.env, cwd: packageRoot });
177
- console.log('\nStartup OK: 已尝试启用开机自启');
178
206
  }
179
207
  console.log('\nInstall OK: pm2 进程已创建');
180
208
  if (!enableStartup) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-vchat-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "OpenClaw plugin for VChat mini program - relay server and message channel",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {