openclaw-channels-csdn-setup 0.2.2 → 0.2.4

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 (2) hide show
  1. package/dist/cli.cjs +37 -9
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -53,6 +53,14 @@ function mergeCsdnIntoOpenClawConfig(existing, csdn) {
53
53
  // src/cli.ts
54
54
  var PLUGIN_PACKAGE = "csdn-im";
55
55
  var DEFAULT_API_URL = "https://msg.csdn.net/claw";
56
+ function isPlainObject2(v) {
57
+ return typeof v === "object" && v !== null && !Array.isArray(v);
58
+ }
59
+ function stripChannelFromConfig(cfg, channelId) {
60
+ const channels = isPlainObject2(cfg.channels) ? { ...cfg.channels } : {};
61
+ delete channels[channelId];
62
+ return { ...cfg, channels };
63
+ }
56
64
  function defaultConfigPath() {
57
65
  return (0, import_node_path.join)((0, import_node_os.homedir)(), ".openclaw", "openclaw.json");
58
66
  }
@@ -98,7 +106,28 @@ function run(argv) {
98
106
  }
99
107
  const apiUrl = parsed.values["api-url"]?.trim() || process.env.CSDN_API_URL?.trim() || DEFAULT_API_URL;
100
108
  const configPath = parsed.values.config?.trim() || defaultConfigPath();
109
+ let existing;
110
+ if ((0, import_node_fs.existsSync)(configPath)) {
111
+ try {
112
+ const raw = (0, import_node_fs.readFileSync)(configPath, "utf8");
113
+ existing = JSON.parse(raw);
114
+ } catch (e) {
115
+ console.error(`Error: could not read ${configPath}: ${e}`);
116
+ return 1;
117
+ }
118
+ }
101
119
  if (!parsed.values["skip-install"]) {
120
+ if (existing && isPlainObject2(existing.channels) && PLUGIN_PACKAGE in existing.channels) {
121
+ try {
122
+ const stripped = stripChannelFromConfig(existing, PLUGIN_PACKAGE);
123
+ (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(configPath), { recursive: true });
124
+ (0, import_node_fs.writeFileSync)(configPath, `${JSON.stringify(stripped, null, 2)}
125
+ `, "utf8");
126
+ } catch (e) {
127
+ console.error(`Error: could not pre-strip channel config: ${e}`);
128
+ return 1;
129
+ }
130
+ }
102
131
  const openclaw = (0, import_node_child_process.spawnSync)(
103
132
  "openclaw",
104
133
  ["plugins", "install", PLUGIN_PACKAGE],
@@ -118,15 +147,14 @@ function run(argv) {
118
147
  console.error(`Error: openclaw plugins install exited with code ${openclaw.status}`);
119
148
  return openclaw.status ?? 1;
120
149
  }
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;
150
+ if ((0, import_node_fs.existsSync)(configPath)) {
151
+ try {
152
+ const raw = (0, import_node_fs.readFileSync)(configPath, "utf8");
153
+ existing = JSON.parse(raw);
154
+ } catch (e) {
155
+ console.error(`Error: could not read ${configPath} after install: ${e}`);
156
+ return 1;
157
+ }
130
158
  }
131
159
  }
132
160
  const merged = mergeCsdnIntoOpenClawConfig(existing, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-channels-csdn-setup",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "One-shot installer: openclaw plugins install csdn-im@latest + merge channels.csdn-im into openclaw.json. Requires OpenClaw peer range as published in csdn-im (see csdn-im package.json openclaw.compatibility).",
5
5
  "type": "module",
6
6
  "license": "MIT",