napcat-plugin-debug-cli 1.2.6 → 1.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.
- package/cli.mjs +22 -16
- package/package.json +1 -1
- package/vite.mjs +32 -24
package/cli.mjs
CHANGED
|
@@ -5141,7 +5141,7 @@ class RpcClient {
|
|
|
5141
5141
|
this.pending.delete(id);
|
|
5142
5142
|
reject(new Error("RPC timeout"));
|
|
5143
5143
|
}
|
|
5144
|
-
},
|
|
5144
|
+
}, 3e4);
|
|
5145
5145
|
});
|
|
5146
5146
|
}
|
|
5147
5147
|
}
|
|
@@ -5242,14 +5242,22 @@ function createWatcher(watchPath, onPluginChange) {
|
|
|
5242
5242
|
}
|
|
5243
5243
|
};
|
|
5244
5244
|
}
|
|
5245
|
-
function
|
|
5246
|
-
|
|
5247
|
-
for (const entry of fs.readdirSync(
|
|
5248
|
-
const
|
|
5249
|
-
const
|
|
5250
|
-
if (entry.isDirectory())
|
|
5251
|
-
|
|
5245
|
+
function collectFiles(dir, prefix = "") {
|
|
5246
|
+
const files = [];
|
|
5247
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
5248
|
+
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
5249
|
+
const fullPath = path.join(dir, entry.name);
|
|
5250
|
+
if (entry.isDirectory()) {
|
|
5251
|
+
files.push(...collectFiles(fullPath, relPath));
|
|
5252
|
+
} else {
|
|
5253
|
+
files.push({
|
|
5254
|
+
path: relPath,
|
|
5255
|
+
content: fs.readFileSync(fullPath).toString("base64"),
|
|
5256
|
+
encoding: "base64"
|
|
5257
|
+
});
|
|
5258
|
+
}
|
|
5252
5259
|
}
|
|
5260
|
+
return files;
|
|
5253
5261
|
}
|
|
5254
5262
|
function countFiles(dir) {
|
|
5255
5263
|
let count = 0;
|
|
@@ -5283,16 +5291,14 @@ async function deployPlugin(projectDir, remotePluginPath, rpc) {
|
|
|
5283
5291
|
logErr(`解析 dist/package.json 失败: ${e.message}`);
|
|
5284
5292
|
return false;
|
|
5285
5293
|
}
|
|
5286
|
-
|
|
5287
|
-
logInfo(`部署 ${co(pluginName, C.bold, C.cyan)} → ${co(destDir, C.dim)}`);
|
|
5294
|
+
logInfo(`部署 ${co(pluginName, C.bold, C.cyan)} → 远程插件目录`);
|
|
5288
5295
|
try {
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
logOk(`文件复制完成 (${countFiles(distDir)} 个文件)`);
|
|
5296
|
+
await rpc.call("removeDir", pluginName);
|
|
5297
|
+
const files = collectFiles(distDir, pluginName);
|
|
5298
|
+
await rpc.call("writeFiles", files);
|
|
5299
|
+
logOk(`文件传输完成 (${countFiles(distDir)} 个文件)`);
|
|
5294
5300
|
} catch (e) {
|
|
5295
|
-
logErr(
|
|
5301
|
+
logErr(`部署失败: ${e.message}`);
|
|
5296
5302
|
return false;
|
|
5297
5303
|
}
|
|
5298
5304
|
try {
|
package/package.json
CHANGED
package/vite.mjs
CHANGED
|
@@ -52,7 +52,7 @@ class SimpleRpcClient {
|
|
|
52
52
|
this.pending.delete(id);
|
|
53
53
|
reject(new Error("RPC timeout"));
|
|
54
54
|
}
|
|
55
|
-
},
|
|
55
|
+
}, 3e4);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
get connected() {
|
|
@@ -65,15 +65,6 @@ class SimpleRpcClient {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
function copyDirRecursive(src, dest) {
|
|
69
|
-
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
|
|
70
|
-
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
71
|
-
const srcPath = path.join(src, entry.name);
|
|
72
|
-
const destPath = path.join(dest, entry.name);
|
|
73
|
-
if (entry.isDirectory()) copyDirRecursive(srcPath, destPath);
|
|
74
|
-
else fs.copyFileSync(srcPath, destPath);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
68
|
function countFiles(dir) {
|
|
78
69
|
let count = 0;
|
|
79
70
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
@@ -82,6 +73,23 @@ function countFiles(dir) {
|
|
|
82
73
|
}
|
|
83
74
|
return count;
|
|
84
75
|
}
|
|
76
|
+
function collectFiles(dir, prefix = "") {
|
|
77
|
+
const files = [];
|
|
78
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
79
|
+
const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
80
|
+
const fullPath = path.join(dir, entry.name);
|
|
81
|
+
if (entry.isDirectory()) {
|
|
82
|
+
files.push(...collectFiles(fullPath, relPath));
|
|
83
|
+
} else {
|
|
84
|
+
files.push({
|
|
85
|
+
path: relPath,
|
|
86
|
+
content: fs.readFileSync(fullPath).toString("base64"),
|
|
87
|
+
encoding: "base64"
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return files;
|
|
92
|
+
}
|
|
85
93
|
function napcatHmrPlugin(options = {}) {
|
|
86
94
|
const {
|
|
87
95
|
wsUrl = "ws://127.0.0.1:8998",
|
|
@@ -178,14 +186,17 @@ function napcatHmrPlugin(options = {}) {
|
|
|
178
186
|
logErr("解析 dist/package.json 失败");
|
|
179
187
|
return;
|
|
180
188
|
}
|
|
181
|
-
const destDir = path.join(remotePluginPath, pluginName);
|
|
182
189
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
190
|
+
await rpc.call("removeDir", pluginName);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
logErr(`清理远程目录失败: ${e.message}`);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
const files = collectFiles(distDir, pluginName);
|
|
197
|
+
await rpc.call("writeFiles", files);
|
|
187
198
|
} catch (e) {
|
|
188
|
-
logErr(
|
|
199
|
+
logErr(`传输文件失败: ${e.message}`);
|
|
189
200
|
return;
|
|
190
201
|
}
|
|
191
202
|
const projectRoot = config.root || process.cwd();
|
|
@@ -214,8 +225,8 @@ function napcatHmrPlugin(options = {}) {
|
|
|
214
225
|
continue;
|
|
215
226
|
}
|
|
216
227
|
try {
|
|
217
|
-
const
|
|
218
|
-
|
|
228
|
+
const webuiFiles = collectFiles(webuiDistDir, `${pluginName}/${webuiTargetDir}`);
|
|
229
|
+
await rpc.call("writeFiles", webuiFiles);
|
|
219
230
|
logOk(`WebUI (${webuiTargetDir}) 已部署 (${countFiles(webuiDistDir)} 个文件)`);
|
|
220
231
|
} catch (e) {
|
|
221
232
|
logErr(`WebUI (${webuiTargetDir}) 部署失败: ${e.message}`);
|
|
@@ -260,7 +271,6 @@ function napcatHmrPlugin(options = {}) {
|
|
|
260
271
|
} catch {
|
|
261
272
|
return;
|
|
262
273
|
}
|
|
263
|
-
const destDir = path.join(remotePluginPath, pluginName);
|
|
264
274
|
const projectRoot = config.root || process.cwd();
|
|
265
275
|
let hasChanges = false;
|
|
266
276
|
for (const wc of webuiConfigs) {
|
|
@@ -288,11 +298,9 @@ function napcatHmrPlugin(options = {}) {
|
|
|
288
298
|
continue;
|
|
289
299
|
}
|
|
290
300
|
try {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
copyDirRecursive(webuiDistDir, webuiDestDir);
|
|
301
|
+
await rpc.call("removeDir", `${pluginName}/${webuiTargetDir}`);
|
|
302
|
+
const webuiFiles = collectFiles(webuiDistDir, `${pluginName}/${webuiTargetDir}`);
|
|
303
|
+
await rpc.call("writeFiles", webuiFiles);
|
|
296
304
|
logOk(`WebUI (${webuiTargetDir}) 已部署 (${countFiles(webuiDistDir)} 个文件)`);
|
|
297
305
|
hasChanges = true;
|
|
298
306
|
} catch (e) {
|