napcat-plugin-debug-cli 1.2.5 → 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 +40 -26
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();
|
|
@@ -196,9 +207,12 @@ function napcatHmrPlugin(options = {}) {
|
|
|
196
207
|
if (wc.buildCommand) {
|
|
197
208
|
try {
|
|
198
209
|
log(`构建 WebUI (${co(webuiTargetDir, C.cyan)})...`);
|
|
210
|
+
const webuiEnv = { ...process.env };
|
|
211
|
+
delete webuiEnv.NODE_ENV;
|
|
199
212
|
execSync(wc.buildCommand, {
|
|
200
213
|
cwd: webuiRoot,
|
|
201
|
-
stdio: "pipe"
|
|
214
|
+
stdio: "pipe",
|
|
215
|
+
env: webuiEnv
|
|
202
216
|
});
|
|
203
217
|
logOk(`WebUI (${webuiTargetDir}) 构建完成`);
|
|
204
218
|
} catch (e) {
|
|
@@ -211,8 +225,8 @@ function napcatHmrPlugin(options = {}) {
|
|
|
211
225
|
continue;
|
|
212
226
|
}
|
|
213
227
|
try {
|
|
214
|
-
const
|
|
215
|
-
|
|
228
|
+
const webuiFiles = collectFiles(webuiDistDir, `${pluginName}/${webuiTargetDir}`);
|
|
229
|
+
await rpc.call("writeFiles", webuiFiles);
|
|
216
230
|
logOk(`WebUI (${webuiTargetDir}) 已部署 (${countFiles(webuiDistDir)} 个文件)`);
|
|
217
231
|
} catch (e) {
|
|
218
232
|
logErr(`WebUI (${webuiTargetDir}) 部署失败: ${e.message}`);
|
|
@@ -257,7 +271,6 @@ function napcatHmrPlugin(options = {}) {
|
|
|
257
271
|
} catch {
|
|
258
272
|
return;
|
|
259
273
|
}
|
|
260
|
-
const destDir = path.join(remotePluginPath, pluginName);
|
|
261
274
|
const projectRoot = config.root || process.cwd();
|
|
262
275
|
let hasChanges = false;
|
|
263
276
|
for (const wc of webuiConfigs) {
|
|
@@ -267,9 +280,12 @@ function napcatHmrPlugin(options = {}) {
|
|
|
267
280
|
if (wc.buildCommand) {
|
|
268
281
|
try {
|
|
269
282
|
log(`构建 WebUI (${co(webuiTargetDir, C.cyan)})...`);
|
|
283
|
+
const webuiEnv = { ...process.env };
|
|
284
|
+
delete webuiEnv.NODE_ENV;
|
|
270
285
|
execSync(wc.buildCommand, {
|
|
271
286
|
cwd: webuiRoot,
|
|
272
|
-
stdio: "pipe"
|
|
287
|
+
stdio: "pipe",
|
|
288
|
+
env: webuiEnv
|
|
273
289
|
});
|
|
274
290
|
logOk(`WebUI (${webuiTargetDir}) 构建完成`);
|
|
275
291
|
} catch (e) {
|
|
@@ -282,11 +298,9 @@ function napcatHmrPlugin(options = {}) {
|
|
|
282
298
|
continue;
|
|
283
299
|
}
|
|
284
300
|
try {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
copyDirRecursive(webuiDistDir, webuiDestDir);
|
|
301
|
+
await rpc.call("removeDir", `${pluginName}/${webuiTargetDir}`);
|
|
302
|
+
const webuiFiles = collectFiles(webuiDistDir, `${pluginName}/${webuiTargetDir}`);
|
|
303
|
+
await rpc.call("writeFiles", webuiFiles);
|
|
290
304
|
logOk(`WebUI (${webuiTargetDir}) 已部署 (${countFiles(webuiDistDir)} 个文件)`);
|
|
291
305
|
hasChanges = true;
|
|
292
306
|
} catch (e) {
|