openclaw-channels-csdn-setup 0.2.6 → 0.2.7

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 +52 -9
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -53,6 +53,29 @@ 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 hasStalePluginState(cfg, channelId) {
60
+ const plugins = isPlainObject2(cfg.plugins) ? cfg.plugins : {};
61
+ return isPlainObject2(cfg.channels) && channelId in cfg.channels || isPlainObject2(plugins.entries) && channelId in plugins.entries || isPlainObject2(plugins.installs) && channelId in plugins.installs;
62
+ }
63
+ function stripChannelFromConfig(cfg, channelId) {
64
+ const channels = isPlainObject2(cfg.channels) ? { ...cfg.channels } : {};
65
+ delete channels[channelId];
66
+ const plugins = isPlainObject2(cfg.plugins) ? { ...cfg.plugins } : {};
67
+ if (isPlainObject2(plugins.entries)) {
68
+ const entries = { ...plugins.entries };
69
+ delete entries[channelId];
70
+ plugins.entries = entries;
71
+ }
72
+ if (isPlainObject2(plugins.installs)) {
73
+ const installs = { ...plugins.installs };
74
+ delete installs[channelId];
75
+ plugins.installs = installs;
76
+ }
77
+ return { ...cfg, channels, plugins };
78
+ }
56
79
  function defaultConfigPath() {
57
80
  return (0, import_node_path.join)((0, import_node_os.homedir)(), ".openclaw", "openclaw.json");
58
81
  }
@@ -98,7 +121,28 @@ function run(argv) {
98
121
  }
99
122
  const apiUrl = parsed.values["api-url"]?.trim() || process.env.CSDN_API_URL?.trim() || DEFAULT_API_URL;
100
123
  const configPath = parsed.values.config?.trim() || defaultConfigPath();
124
+ let existing;
125
+ if ((0, import_node_fs.existsSync)(configPath)) {
126
+ try {
127
+ const raw = (0, import_node_fs.readFileSync)(configPath, "utf8");
128
+ existing = JSON.parse(raw);
129
+ } catch (e) {
130
+ console.error(`Error: could not read ${configPath}: ${e}`);
131
+ return 1;
132
+ }
133
+ }
101
134
  if (!parsed.values["skip-install"]) {
135
+ if (existing && hasStalePluginState(existing, PLUGIN_PACKAGE)) {
136
+ try {
137
+ const stripped = stripChannelFromConfig(existing, PLUGIN_PACKAGE);
138
+ (0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(configPath), { recursive: true });
139
+ (0, import_node_fs.writeFileSync)(configPath, `${JSON.stringify(stripped, null, 2)}
140
+ `, "utf8");
141
+ } catch (e) {
142
+ console.error(`Error: could not pre-strip channel config: ${e}`);
143
+ return 1;
144
+ }
145
+ }
102
146
  const openclaw = (0, import_node_child_process.spawnSync)(
103
147
  "openclaw",
104
148
  ["plugins", "install", PLUGIN_PACKAGE],
@@ -118,15 +162,14 @@ function run(argv) {
118
162
  console.error(`Error: openclaw plugins install exited with code ${openclaw.status}`);
119
163
  return openclaw.status ?? 1;
120
164
  }
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;
165
+ if ((0, import_node_fs.existsSync)(configPath)) {
166
+ try {
167
+ const raw = (0, import_node_fs.readFileSync)(configPath, "utf8");
168
+ existing = JSON.parse(raw);
169
+ } catch (e) {
170
+ console.error(`Error: could not read ${configPath} after install: ${e}`);
171
+ return 1;
172
+ }
130
173
  }
131
174
  }
132
175
  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.6",
3
+ "version": "0.2.7",
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",