@routerhub/agent-rules 1.5.29 → 1.5.30
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/package.json +1 -1
- package/postinstall.js +36 -8
package/package.json
CHANGED
package/postinstall.js
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
|
|
7
|
+
// 获取下游项目根目录(INIT_CWD 是 npm/pnpm 执行 install 时的原始目录)
|
|
8
|
+
const projectRoot = process.env.INIT_CWD || process.cwd();
|
|
9
|
+
const packageRoot = __dirname;
|
|
10
|
+
const mergeScriptPath = path.join(packageRoot, "merge.js");
|
|
11
|
+
|
|
12
|
+
// 安全检查:如果项目根目录在 node_modules 内,说明 INIT_CWD 未正确设置,跳过初始化
|
|
13
|
+
if (projectRoot.includes("node_modules")) {
|
|
14
|
+
console.log("[agent-rules] 检测到在 node_modules 内运行,跳过自动初始化");
|
|
15
|
+
console.log("[agent-rules] 请手动执行: npx agent-rules init");
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
console.log("");
|
|
20
|
+
console.log("[agent-rules] 安装完成,正在同步规则文件...");
|
|
21
|
+
|
|
22
|
+
// 执行 sync 生成所有规则输出文件
|
|
23
|
+
const syncProcess = spawn("node", [mergeScriptPath, "sync"], {
|
|
24
|
+
cwd: projectRoot,
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
syncProcess.on("close", (code) => {
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
console.log("[agent-rules] 规则文件同步完成");
|
|
31
|
+
console.log("");
|
|
32
|
+
} else {
|
|
33
|
+
console.error("[agent-rules] 同步失败,退出码:", code);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
syncProcess.on("error", (err) => {
|
|
38
|
+
console.error("[agent-rules] 同步过程出错:", err.message);
|
|
39
|
+
});
|