install.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env node
  2. /**
  3. * plugin-tips-cn 安装器(npm 分发用)。
  4. *
  5. * npx plugin-tips-cn # 装到 $HERMES_HOME/plugins/plugin-tips-cn(默认 ~/.hermes)
  6. * npx plugin-tips-cn --check # 只看目标位置,不写文件
  7. * HERMES_HOME=/opt/data npx plugin-tips-cn
  8. *
  9. * 装完还需要在 Hermes 里启用并重启一次网关(插件目录不会被长驻进程自动重扫):
  10. * hermes plugins enable plugin-tips-cn
  11. */
  12. const fs = require("fs");
  13. const os = require("os");
  14. const path = require("path");
  15. const PKG_ROOT = path.resolve(__dirname, "..");
  16. const FILES = ["plugin.yaml", "__init__.py", "phrases.json", "validate_phrases.py", "README.md", "LICENSE"];
  17. const DIR_NAME = "plugin-tips-cn";
  18. function hermesHome() {
  19. return process.env.HERMES_HOME || path.join(os.homedir(), ".hermes");
  20. }
  21. function main() {
  22. const args = process.argv.slice(2);
  23. const checkOnly = args.includes("--check") || args.includes("-c");
  24. const home = hermesHome();
  25. const target = path.join(home, "plugins", DIR_NAME);
  26. console.log(`Hermes 家目录: ${home}`);
  27. console.log(`插件目标位置: ${target}`);
  28. if (checkOnly) return;
  29. const missing = FILES.filter((f) => !fs.existsSync(path.join(PKG_ROOT, f)));
  30. if (missing.length) {
  31. console.error(`✗ 包里缺文件: ${missing.join(", ")}`);
  32. process.exit(1);
  33. }
  34. fs.mkdirSync(target, { recursive: true });
  35. let n = 0;
  36. for (const f of FILES) {
  37. fs.copyFileSync(path.join(PKG_ROOT, f), path.join(target, f));
  38. n += 1;
  39. }
  40. console.log(`✓ 已复制 ${n} 个文件到 ${target}`);
  41. console.log("");
  42. console.log("还差两步(Hermes 不会自动重扫插件目录):");
  43. console.log(" 1) hermes plugins enable plugin-tips-cn");
  44. console.log(" 2) 重启网关一次(容器里 s6 托管的网关,杀掉会自动拉起)");
  45. console.log("");
  46. console.log("改词库不用重启:phrases.json 按 mtime 热加载。");
  47. console.log("自检词库:python3 " + path.join(target, "validate_phrases.py"));
  48. }
  49. main();