@tencent-weixin/openclaw-weixin-cli 1.0.0

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/LICENSE +21 -0
  2. package/cli.mjs +119 -0
  3. package/package.json +17 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tencent Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/cli.mjs ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync, spawnSync } from "node:child_process";
4
+
5
+ const PLUGIN_SPEC = "@tencent-weixin/openclaw-weixin";
6
+ const CHANNEL_ID = "openclaw-weixin";
7
+
8
+ // ── helpers ──────────────────────────────────────────────────────────────────
9
+
10
+ function log(msg) {
11
+ console.log(`\x1b[36m[weixin]\x1b[0m ${msg}`);
12
+ }
13
+
14
+ function error(msg) {
15
+ console.error(`\x1b[31m[weixin]\x1b[0m ${msg}`);
16
+ }
17
+
18
+ function run(cmd, { silent = true } = {}) {
19
+ const stdio = silent ? ["pipe", "pipe", "pipe"] : "inherit";
20
+ const result = spawnSync(cmd, { shell: true, stdio });
21
+ if (result.status !== 0) {
22
+ const err = new Error(`Command failed with exit code ${result.status}: ${cmd}`);
23
+ err.stderr = silent ? (result.stderr || "").toString() : "";
24
+ throw err;
25
+ }
26
+ return silent ? (result.stdout || "").toString().trim() : "";
27
+ }
28
+
29
+ function which(bin) {
30
+ try {
31
+ return execSync(`which ${bin}`, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ // ── commands ─────────────────────────────────────────────────────────────────
38
+
39
+ function install() {
40
+ // 1. Check openclaw is installed
41
+ if (!which("openclaw")) {
42
+ error("未找到 openclaw,请先安装:");
43
+ console.log(" npm install -g openclaw");
44
+ console.log(" 详见 https://docs.openclaw.ai/install");
45
+ process.exit(1);
46
+ }
47
+ log("已找到本地安装的 openclaw");
48
+
49
+ // 2. Install plugin via openclaw
50
+ log("正在安装插件...");
51
+ try {
52
+ const installOut = run(`openclaw plugins install "${PLUGIN_SPEC}"`);
53
+ if (installOut) log(installOut);
54
+ } catch (installErr) {
55
+ if (installErr.stderr && installErr.stderr.includes("already exists")) {
56
+ log("检测到本地已安装,正在更新...");
57
+ try {
58
+ const updateOut = run(`openclaw plugins update "${CHANNEL_ID}"`);
59
+ if (updateOut) log(updateOut);
60
+ } catch (updateErr) {
61
+ error("插件更新失败,请手动执行:");
62
+ if (updateErr.stderr) console.error(updateErr.stderr);
63
+ console.log(` openclaw plugins update "${CHANNEL_ID}"`);
64
+ process.exit(1);
65
+ }
66
+ } else {
67
+ error("插件安装失败,请手动执行:");
68
+ if (installErr.stderr) console.error(installErr.stderr);
69
+ console.log(` openclaw plugins install "${PLUGIN_SPEC}"`);
70
+ process.exit(1);
71
+ }
72
+ }
73
+
74
+ // 3. Login (interactive QR scan)
75
+ log("插件就绪,开始首次连接...");
76
+ try {
77
+ run(`openclaw channels login --channel ${CHANNEL_ID}`, { silent: false });
78
+ } catch {
79
+ console.log();
80
+ error("首次连接未完成,可稍后手动重试:");
81
+ console.log(` openclaw channels login --channel ${CHANNEL_ID}`);
82
+ }
83
+
84
+ // 4. Done
85
+ console.log();
86
+ log("\x1b[32m安装完成!\x1b[0m");
87
+ console.log();
88
+ }
89
+
90
+ function help() {
91
+ console.log(`
92
+ 用法: npx -y @tencent-weixin/openclaw-weixin-cli <命令>
93
+
94
+ 命令:
95
+ install 安装微信插件并扫码连接
96
+ help 显示帮助信息
97
+ `);
98
+ }
99
+
100
+ // ── main ─────────────────────────────────────────────────────────────────────
101
+
102
+ const command = process.argv[2];
103
+
104
+ switch (command) {
105
+ case "install":
106
+ install();
107
+ break;
108
+ case "help":
109
+ case "--help":
110
+ case "-h":
111
+ help();
112
+ break;
113
+ default:
114
+ if (command) {
115
+ error(`未知命令: ${command}`);
116
+ }
117
+ help();
118
+ process.exit(command ? 1 : 0);
119
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@tencent-weixin/openclaw-weixin-cli",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight installer for the OpenClaw Weixin channel plugin",
5
+ "license": "MIT",
6
+ "author": "Tencent",
7
+ "type": "module",
8
+ "bin": {
9
+ "weixin-installer": "./cli.mjs"
10
+ },
11
+ "files": [
12
+ "cli.mjs"
13
+ ],
14
+ "engines": {
15
+ "node": ">=22"
16
+ }
17
+ }