build: support both registry publish and git clone install

- Add root package.json with files[] for registry publishing
- Add prepare script to sync dist/ from plugin/
- Add postinstall to auto-run install script
- Modify install script: auto-create dist/ if missing (git clone case)
- Plugin works in both scenarios:
  * npm install @hangman-lab/dirigent -> uses bundled dist/
  * git clone + node scripts/install-dirigent-openclaw.mjs -> auto-creates dist/
This commit is contained in:
zhi
2026-03-03 16:24:05 +00:00
parent 8e26744162
commit 2ea4f59a1e
2 changed files with 52 additions and 1 deletions

View File

@@ -14,7 +14,19 @@ const mode = modeArg === "--install" ? "install" : "uninstall";
const env = process.env;
const OPENCLAW_CONFIG_PATH = env.OPENCLAW_CONFIG_PATH || path.join(os.homedir(), ".openclaw", "openclaw.json");
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const PLUGIN_PATH = env.PLUGIN_PATH || path.resolve(__dirname, "..", "dist", "dirigent");
// Ensure dist/dirigent exists (handles git clone without npm prepare)
const DIST_DIR = path.resolve(__dirname, "..", "dist", "dirigent");
const PLUGIN_SRC_DIR = path.resolve(__dirname, "..", "plugin");
if (mode === "install" && !fs.existsSync(DIST_DIR)) {
console.log("[dirigent] dist/ not found, syncing from plugin/...");
fs.mkdirSync(DIST_DIR, { recursive: true });
for (const f of fs.readdirSync(PLUGIN_SRC_DIR)) {
fs.copyFileSync(path.join(PLUGIN_SRC_DIR, f), path.join(DIST_DIR, f));
}
}
const PLUGIN_PATH = env.PLUGIN_PATH || DIST_DIR;
const NO_REPLY_PROVIDER_ID = env.NO_REPLY_PROVIDER_ID || "dirigentway";
const NO_REPLY_MODEL_ID = env.NO_REPLY_MODEL_ID || "no-reply";
const NO_REPLY_BASE_URL = env.NO_REPLY_BASE_URL || "http://127.0.0.1:8787/v1";