| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/usr/bin/env node
- /**
- * plugin-tips-cn 安装器(npm 分发用)。
- *
- * npx plugin-tips-cn # 装到 $HERMES_HOME/plugins/plugin-tips-cn(默认 ~/.hermes)
- * npx plugin-tips-cn --check # 只看目标位置,不写文件
- * HERMES_HOME=/opt/data npx plugin-tips-cn
- *
- * 装完还需要在 Hermes 里启用并重启一次网关(插件目录不会被长驻进程自动重扫):
- * hermes plugins enable plugin-tips-cn
- */
- const fs = require("fs");
- const os = require("os");
- const path = require("path");
- const PKG_ROOT = path.resolve(__dirname, "..");
- const FILES = ["plugin.yaml", "__init__.py", "phrases.json", "validate_phrases.py", "README.md", "LICENSE"];
- const DIR_NAME = "plugin-tips-cn";
- function hermesHome() {
- return process.env.HERMES_HOME || path.join(os.homedir(), ".hermes");
- }
- function main() {
- const args = process.argv.slice(2);
- const checkOnly = args.includes("--check") || args.includes("-c");
- const home = hermesHome();
- const target = path.join(home, "plugins", DIR_NAME);
- console.log(`Hermes 家目录: ${home}`);
- console.log(`插件目标位置: ${target}`);
- if (checkOnly) return;
- const missing = FILES.filter((f) => !fs.existsSync(path.join(PKG_ROOT, f)));
- if (missing.length) {
- console.error(`✗ 包里缺文件: ${missing.join(", ")}`);
- process.exit(1);
- }
- fs.mkdirSync(target, { recursive: true });
- let n = 0;
- for (const f of FILES) {
- fs.copyFileSync(path.join(PKG_ROOT, f), path.join(target, f));
- n += 1;
- }
- console.log(`✓ 已复制 ${n} 个文件到 ${target}`);
- console.log("");
- console.log("还差两步(Hermes 不会自动重扫插件目录):");
- console.log(" 1) hermes plugins enable plugin-tips-cn");
- console.log(" 2) 重启网关一次(容器里 s6 托管的网关,杀掉会自动拉起)");
- console.log("");
- console.log("改词库不用重启:phrases.json 按 mtime 热加载。");
- console.log("自检词库:python3 " + path.join(target, "validate_phrases.py"));
- }
- main();
|