openclaw-channels-csdn-setup 0.1.5

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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/dist/cli.cjs +157 -0
  4. package/package.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) CSDN
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/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # openclaw-channels-csdn-setup
2
+
3
+ 在已安装 OpenClaw CLI 的前提下,**一条命令**完成:
4
+
5
+ 1. `openclaw plugins install csdn-im`
6
+ 2. 将 `channels.csdn-im`(含 Token)合并写入用户级 `openclaw.json`(默认 `~/.openclaw/openclaw.json`)
7
+
8
+ 不会删除或覆盖配置中的 `bindings`、`agents`、其它 `channels.*` 等字段。
9
+
10
+ 全局命令名(安装本包后):`openclaw-channels-csdn-setup`。
11
+
12
+ ## 用法
13
+
14
+ ```bash
15
+ npx openclaw-channels-csdn-setup@latest --token "$CSDN_BOT_TOKEN"
16
+ ```
17
+
18
+ 环境变量:`CSDN_BOT_TOKEN`(可替代 `--token`)。
19
+
20
+ 常用可选参数:`--api-url`、`--config`、`--skip-install`、`--dry-run`。详见 `--help`。
21
+
22
+ ## 前置条件
23
+
24
+ - Node.js >= 20
25
+ - `openclaw` 在 `PATH` 中(本工具**不会**自动安装 OpenClaw)
26
+
27
+ ## 开发
28
+
29
+ ```bash
30
+ pnpm build
31
+ pnpm test
32
+ ```
33
+
34
+ ## License
35
+
36
+ MIT
package/dist/cli.cjs ADDED
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/cli.ts
22
+ var cli_exports = {};
23
+ __export(cli_exports, {
24
+ PLUGIN_PACKAGE: () => PLUGIN_PACKAGE,
25
+ run: () => run
26
+ });
27
+ module.exports = __toCommonJS(cli_exports);
28
+ var import_node_child_process = require("child_process");
29
+ var import_node_fs = require("fs");
30
+ var import_node_os = require("os");
31
+ var import_node_path = require("path");
32
+ var import_node_util = require("util");
33
+
34
+ // src/merge-config.ts
35
+ var CSDN_IM_CHANNEL_KEY = "csdn-im";
36
+ function isPlainObject(v) {
37
+ return typeof v === "object" && v !== null && !Array.isArray(v);
38
+ }
39
+ function mergeCsdnIntoOpenClawConfig(existing, csdn) {
40
+ const base = isPlainObject(existing) ? { ...existing } : {};
41
+ const prevChannels = base.channels;
42
+ const channels = isPlainObject(prevChannels) ? { ...prevChannels } : {};
43
+ const prevCsdn = channels[CSDN_IM_CHANNEL_KEY];
44
+ const prevCsdnObj = isPlainObject(prevCsdn) ? prevCsdn : {};
45
+ channels[CSDN_IM_CHANNEL_KEY] = {
46
+ ...prevCsdnObj,
47
+ ...csdn
48
+ };
49
+ base.channels = channels;
50
+ return base;
51
+ }
52
+
53
+ // src/cli.ts
54
+ var PLUGIN_PACKAGE = "csdn-im";
55
+ var DEFAULT_API_URL = "https://test-msg.csdn.net/claw";
56
+ function defaultConfigPath() {
57
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), ".openclaw", "openclaw.json");
58
+ }
59
+ function printHelp() {
60
+ console.log(`Usage: openclaw-channels-csdn-setup [options]
61
+
62
+ Install ${PLUGIN_PACKAGE} via the OpenClaw CLI and merge CSDN channel config into ~/.openclaw/openclaw.json.
63
+
64
+ Prerequisites:
65
+ - Node.js >= 20
66
+ - "openclaw" command available on PATH (install OpenClaw globally first)
67
+
68
+ Options:
69
+ --token <token> CSDN Bot token (or set CSDN_BOT_TOKEN)
70
+ --api-url <url> CSDN OpenClaw API base (or CSDN_API_URL)
71
+ --config <path> override openclaw.json path
72
+ --skip-install only write config (skip openclaw plugins install)
73
+ --dry-run print merged JSON, do not write
74
+ -h, --help show this help
75
+ `);
76
+ }
77
+ function run(argv) {
78
+ const parsed = (0, import_node_util.parseArgs)({
79
+ args: argv,
80
+ options: {
81
+ token: { type: "string" },
82
+ "api-url": { type: "string" },
83
+ config: { type: "string" },
84
+ "skip-install": { type: "boolean", default: false },
85
+ "dry-run": { type: "boolean", default: false },
86
+ help: { type: "boolean", short: "h", default: false }
87
+ },
88
+ allowPositionals: false
89
+ });
90
+ if (parsed.values.help) {
91
+ printHelp();
92
+ return 0;
93
+ }
94
+ const token = parsed.values.token?.trim() || process.env.CSDN_BOT_TOKEN?.trim();
95
+ if (!token) {
96
+ console.error("Error: missing token. Pass --token or set CSDN_BOT_TOKEN.");
97
+ return 1;
98
+ }
99
+ const apiUrl = parsed.values["api-url"]?.trim() || process.env.CSDN_API_URL?.trim() || DEFAULT_API_URL;
100
+ const configPath = parsed.values.config?.trim() || defaultConfigPath();
101
+ if (!parsed.values["skip-install"]) {
102
+ const openclaw = (0, import_node_child_process.spawnSync)(
103
+ "openclaw",
104
+ ["plugins", "install", PLUGIN_PACKAGE],
105
+ { stdio: "inherit", shell: process.platform === "win32" }
106
+ );
107
+ if (openclaw.error) {
108
+ if (openclaw.error.code === "ENOENT") {
109
+ console.error(
110
+ 'Error: "openclaw" not found on PATH. Install OpenClaw CLI first, then re-run this command.'
111
+ );
112
+ } else {
113
+ console.error(`Error: failed to run openclaw: ${openclaw.error}`);
114
+ }
115
+ return 1;
116
+ }
117
+ if (openclaw.status !== 0) {
118
+ console.error(`Error: openclaw plugins install exited with code ${openclaw.status}`);
119
+ return openclaw.status ?? 1;
120
+ }
121
+ }
122
+ let existing;
123
+ if ((0, import_node_fs.existsSync)(configPath)) {
124
+ try {
125
+ const raw = (0, import_node_fs.readFileSync)(configPath, "utf8");
126
+ existing = JSON.parse(raw);
127
+ } catch (e) {
128
+ console.error(`Error: could not read ${configPath}: ${e}`);
129
+ return 1;
130
+ }
131
+ }
132
+ const merged = mergeCsdnIntoOpenClawConfig(existing, {
133
+ enabled: true,
134
+ token,
135
+ apiUrl
136
+ });
137
+ if (parsed.values["dry-run"]) {
138
+ console.log(JSON.stringify(merged, null, 2));
139
+ return 0;
140
+ }
141
+ try {
142
+ (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(configPath), { recursive: true });
143
+ (0, import_node_fs.writeFileSync)(configPath, `${JSON.stringify(merged, null, 2)}
144
+ `, "utf8");
145
+ } catch (e) {
146
+ console.error(`Error: could not write ${configPath}: ${e}`);
147
+ return 1;
148
+ }
149
+ console.log(`Wrote CSDN channel config to ${configPath}`);
150
+ return 0;
151
+ }
152
+ run(process.argv.slice(2));
153
+ // Annotate the CommonJS export names for ESM import in node:
154
+ 0 && (module.exports = {
155
+ PLUGIN_PACKAGE,
156
+ run
157
+ });
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "openclaw-channels-csdn-setup",
3
+ "version": "0.1.5",
4
+ "description": "One-shot installer: openclaw plugins install csdn-im + merge channels.csdn-im into openclaw.json",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "bin": {
11
+ "openclaw-channels-csdn-setup": "./dist/cli.cjs"
12
+ },
13
+ "scripts": {
14
+ "build": "tsup",
15
+ "test": "vitest --run"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^22.0.0",
19
+ "tsup": "^8.5.1",
20
+ "typescript": "^5.9.3",
21
+ "vitest": "^2.1.0"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://gitlab.csdn.net/messagecenter/openclawplugin.git"
26
+ },
27
+ "keywords": [
28
+ "openclaw",
29
+ "csdn",
30
+ "csdn-im",
31
+ "setup"
32
+ ]
33
+ }