napcat-plugin-debug-cli 1.2.1 → 1.2.3

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 (3) hide show
  1. package/cli.mjs +37 -3
  2. package/package.json +1 -1
  3. package/vite.mjs +36 -2
package/cli.mjs CHANGED
@@ -5149,13 +5149,42 @@ function createWatcher(watchPath, onPluginChange) {
5149
5149
  const watchers = /* @__PURE__ */ new Map();
5150
5150
  const timers = /* @__PURE__ */ new Map();
5151
5151
  let active = false;
5152
- const EXTS = /* @__PURE__ */ new Set([".js", ".mjs", ".cjs", ".ts", ".mts", ".json"]);
5152
+ const EXTS = /* @__PURE__ */ new Set([
5153
+ ".js",
5154
+ ".mjs",
5155
+ ".cjs",
5156
+ ".ts",
5157
+ ".mts",
5158
+ ".cts",
5159
+ ".json",
5160
+ // 前端 / WebUI 相关
5161
+ ".jsx",
5162
+ ".tsx",
5163
+ ".vue",
5164
+ ".svelte",
5165
+ ".html",
5166
+ ".htm",
5167
+ ".css",
5168
+ ".scss",
5169
+ ".sass",
5170
+ ".less",
5171
+ ".styl",
5172
+ ".svg",
5173
+ ".png",
5174
+ ".jpg",
5175
+ ".jpeg",
5176
+ ".gif",
5177
+ ".webp",
5178
+ ".ico"
5179
+ ]);
5180
+ const IGNORE_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", ".vite", ".cache"]);
5153
5181
  function watchDir(name, dirPath) {
5154
5182
  try {
5155
5183
  const w = fs.watch(dirPath, { recursive: true, persistent: false }, (_ev, file) => {
5156
5184
  if (!file) return;
5157
5185
  if (!EXTS.has(path.extname(file))) return;
5158
- if (file.includes("node_modules") || file.startsWith(".")) return;
5186
+ const parts = file.split(/[\\/]/);
5187
+ if (parts.some((p) => IGNORE_DIRS.has(p) || p.startsWith("."))) return;
5159
5188
  const t = timers.get(name);
5160
5189
  if (t) clearTimeout(t);
5161
5190
  timers.set(name, setTimeout(() => {
@@ -5272,7 +5301,12 @@ async function deployPlugin(projectDir, remotePluginPath, rpc) {
5272
5301
  } catch {
5273
5302
  try {
5274
5303
  logInfo("插件未注册,尝试从目录加载...");
5275
- await rpc.call("loadDirectoryPlugin", destDir);
5304
+ await rpc.call("loadDirectoryPlugin", pluginName);
5305
+ try {
5306
+ await rpc.call("setPluginStatus", pluginName, true);
5307
+ await rpc.call("loadPluginById", pluginName);
5308
+ } catch {
5309
+ }
5276
5310
  logOk(`${co(pluginName, C.green, C.bold)} 首次加载成功`);
5277
5311
  } catch (e2) {
5278
5312
  logWarn(`自动加载失败: ${e2.message},请手动 load ${pluginName}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "napcat-plugin-debug-cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "NapCat 插件调试 CLI — 连接调试服务实现热重载",
6
6
  "author": "NapNeko",
package/vite.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { execSync } from 'node:child_process';
3
4
 
4
5
  const C = {
5
6
  reset: "\x1B[0m",
@@ -86,8 +87,10 @@ function napcatHmrPlugin(options = {}) {
86
87
  wsUrl = "ws://127.0.0.1:8998",
87
88
  token,
88
89
  enabled = true,
89
- autoConnect = true
90
+ autoConnect = true,
91
+ webui
90
92
  } = options;
93
+ const webuiConfigs = webui ? Array.isArray(webui) ? webui : [webui] : [];
91
94
  let rpc = null;
92
95
  let remotePluginPath = null;
93
96
  let connecting = false;
@@ -183,6 +186,37 @@ function napcatHmrPlugin(options = {}) {
183
186
  logErr(`复制文件失败: ${e.message}`);
184
187
  return;
185
188
  }
189
+ const projectRoot = config.root || process.cwd();
190
+ for (const wc of webuiConfigs) {
191
+ const webuiTargetDir = wc.targetDir || "webui";
192
+ const webuiDistDir = path.resolve(projectRoot, wc.distDir);
193
+ const webuiRoot = wc.root ? path.resolve(projectRoot, wc.root) : path.dirname(webuiDistDir);
194
+ if (wc.buildCommand) {
195
+ try {
196
+ log(`构建 WebUI (${co(webuiTargetDir, C.cyan)})...`);
197
+ execSync(wc.buildCommand, {
198
+ cwd: webuiRoot,
199
+ stdio: "pipe",
200
+ env: { ...process.env, NODE_ENV: "production" }
201
+ });
202
+ logOk(`WebUI (${webuiTargetDir}) 构建完成`);
203
+ } catch (e) {
204
+ logErr(`WebUI (${webuiTargetDir}) 构建失败: ${e.stderr?.toString() || e.message}`);
205
+ continue;
206
+ }
207
+ }
208
+ if (!fs.existsSync(webuiDistDir)) {
209
+ logErr(`WebUI 产物目录不存在: ${webuiDistDir}`);
210
+ continue;
211
+ }
212
+ try {
213
+ const webuiDestDir = path.join(destDir, webuiTargetDir);
214
+ copyDirRecursive(webuiDistDir, webuiDestDir);
215
+ logOk(`WebUI (${webuiTargetDir}) 已部署 (${countFiles(webuiDistDir)} 个文件)`);
216
+ } catch (e) {
217
+ logErr(`WebUI (${webuiTargetDir}) 部署失败: ${e.message}`);
218
+ }
219
+ }
186
220
  try {
187
221
  const reloaded = await rpc.call("reloadPlugin", pluginName);
188
222
  if (reloaded === false) {
@@ -191,7 +225,7 @@ function napcatHmrPlugin(options = {}) {
191
225
  logHmr(`${co(pluginName, C.green, C.bold)} 已重载 (${countFiles(distDir)} 个文件)`);
192
226
  } catch {
193
227
  try {
194
- await rpc.call("loadDirectoryPlugin", destDir);
228
+ await rpc.call("loadDirectoryPlugin", pluginName);
195
229
  try {
196
230
  await rpc.call("setPluginStatus", pluginName, true);
197
231
  await rpc.call("loadPluginById", pluginName);