@guandata/guanmetric 0.1.1 → 0.1.2
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/CHANGELOG.md +5 -0
- package/README.md +7 -0
- package/bin/postinstall.js +58 -0
- package/bin/run.js +32 -1
- package/binaries/guanmetric-darwin-arm64 +0 -0
- package/binaries/guanmetric-darwin-x64 +0 -0
- package/binaries/guanmetric-linux-arm64 +0 -0
- package/binaries/guanmetric-linux-x64 +0 -0
- package/binaries/guanmetric-win32-x64.exe +0 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -9,6 +9,8 @@ npm install -g @guandata/guanmetric
|
|
|
9
9
|
guanmetric install-skill
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
+
> `npm install -g` / `npm link` 全局安装时会通过 postinstall 自动执行一次 skill 安装/刷新;上述命令用于手动重装或排查。CI 等无需 skill 的环境可设 `GUAN_SKIP_INSTALL_SKILL=1` 跳过。
|
|
13
|
+
|
|
12
14
|
## 常用命令
|
|
13
15
|
|
|
14
16
|
```bash
|
|
@@ -23,6 +25,11 @@ guanmetric public-dim create --file public_dim.json --dry-run
|
|
|
23
25
|
|
|
24
26
|
## 版本更新
|
|
25
27
|
|
|
28
|
+
### @guandata/guanmetric 0.1.2
|
|
29
|
+
|
|
30
|
+
- 全局安装或升级后自动刷新 AI Skill,减少 CLI 与 Agent 使用说明版本不一致的情况。
|
|
31
|
+
- 随包提供完整的指标管理说明和参考资料。
|
|
32
|
+
|
|
26
33
|
### @guandata/guanmetric 0.1.1
|
|
27
34
|
|
|
28
35
|
- 增强指标 Excel 标准化能力,支持按原子、复合和多类衍生指标拆分标准模板。
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Best-effort post-install hook: refresh the installed AI skill right after
|
|
5
|
+
* a global npm install/upgrade, so users cannot forget to run
|
|
6
|
+
* `guanmetric install-skill` and end up with a stale SKILL.md.
|
|
7
|
+
*
|
|
8
|
+
* Constraints:
|
|
9
|
+
* - MUST never fail the npm install: every failure path still exits 0.
|
|
10
|
+
* - Only runs for global installs (`npm install -g` / `npm link`); a local
|
|
11
|
+
* `npm install` inside a project never touches the user's home dirs.
|
|
12
|
+
* - Escape hatch: GUAN_SKIP_INSTALL_SKILL=1 skips entirely (e.g. CI images
|
|
13
|
+
* that install the CLI but never run an AI agent are skipped by default).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
"use strict";
|
|
17
|
+
|
|
18
|
+
const { spawnSync } = require("child_process");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
|
|
21
|
+
const CLI_NAME = "guanmetric";
|
|
22
|
+
|
|
23
|
+
function skipReason() {
|
|
24
|
+
if (process.env.GUAN_SKIP_INSTALL_SKILL === "1") return "GUAN_SKIP_INSTALL_SKILL=1";
|
|
25
|
+
if (process.env.npm_config_global !== "true") return "not a global install";
|
|
26
|
+
if (process.env.CI) return "CI environment";
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function main() {
|
|
31
|
+
const reason = skipReason();
|
|
32
|
+
if (reason) {
|
|
33
|
+
console.log(`[${CLI_NAME}] postinstall: skipping automatic install-skill (${reason}).`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log(`[${CLI_NAME}] postinstall: refreshing AI skill (${CLI_NAME} install-skill)...`);
|
|
37
|
+
const result = spawnSync(
|
|
38
|
+
process.execPath,
|
|
39
|
+
[path.join(__dirname, "run.js"), "install-skill"],
|
|
40
|
+
{ stdio: "inherit", env: process.env, timeout: 180000 }
|
|
41
|
+
);
|
|
42
|
+
if (result.error || result.status !== 0) {
|
|
43
|
+
console.warn(
|
|
44
|
+
`[${CLI_NAME}] postinstall: automatic skill install did not complete` +
|
|
45
|
+
(result.error ? ` (${result.error.message})` : ` (exit ${result.status})`) +
|
|
46
|
+
`; run \`${CLI_NAME} install-skill\` manually to refresh SKILL.md.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
main();
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn(
|
|
55
|
+
`[${CLI_NAME}] postinstall: ${err.message}; run \`${CLI_NAME} install-skill\` manually.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
process.exit(0);
|
package/bin/run.js
CHANGED
|
@@ -86,10 +86,36 @@ if (process.argv[2] === "version" && process.argv.length === 3) {
|
|
|
86
86
|
process.exit(0);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
|
|
90
|
+
// 定位 npm 自带的 npx-cli.js 并用 node 直接执行(与 guanskill 保持一致),
|
|
91
|
+
// 避免 Windows 上 spawn npx.cmd 的两类问题:shell:true 不做参数 quoting
|
|
92
|
+
// (全局安装路径含空格时会被拆参),以及新版 Node 禁止无 shell 的 .cmd
|
|
93
|
+
// spawn(CVE-2024-27980)。postinstall 场景下 npm_execpath 必然可用。
|
|
94
|
+
function resolveNpxInvocation() {
|
|
95
|
+
const executableDir = path.dirname(process.execPath);
|
|
96
|
+
const candidates = [];
|
|
97
|
+
if (process.env.npm_execpath) {
|
|
98
|
+
candidates.push(path.join(path.dirname(process.env.npm_execpath), "npx-cli.js"));
|
|
99
|
+
}
|
|
100
|
+
candidates.push(path.join(executableDir, "node_modules", "npm", "bin", "npx-cli.js"));
|
|
101
|
+
candidates.push(path.resolve(executableDir, "..", "node_modules", "npm", "bin", "npx-cli.js"));
|
|
102
|
+
candidates.push(path.resolve(executableDir, "..", "lib", "node_modules", "npm", "bin", "npx-cli.js"));
|
|
103
|
+
const npxCliPath = candidates.find((candidate) => fs.existsSync(candidate));
|
|
104
|
+
if (npxCliPath) {
|
|
105
|
+
return { command: process.execPath, argsPrefix: [npxCliPath] };
|
|
106
|
+
}
|
|
107
|
+
if (process.platform === "win32") {
|
|
108
|
+
throw new Error("Cannot locate npm/bin/npx-cli.js for safe Windows execution");
|
|
109
|
+
}
|
|
110
|
+
return { command: "npx", argsPrefix: [] };
|
|
111
|
+
}
|
|
112
|
+
|
|
89
113
|
if (process.argv[2] === "install-skill") {
|
|
90
114
|
const pkgRoot = path.join(__dirname, "..");
|
|
91
115
|
const extraArgs = process.argv.slice(3);
|
|
92
116
|
const args = [
|
|
117
|
+
// --yes: postinstall 等非交互环境下 npx 需要免确认下载 skills CLI
|
|
118
|
+
"--yes",
|
|
93
119
|
"skills",
|
|
94
120
|
"add",
|
|
95
121
|
pkgRoot,
|
|
@@ -100,7 +126,12 @@ if (process.argv[2] === "install-skill") {
|
|
|
100
126
|
...extraArgs,
|
|
101
127
|
];
|
|
102
128
|
console.log("Installing guanmetric to AI coding assistants...");
|
|
103
|
-
const
|
|
129
|
+
const npxInvocation = resolveNpxInvocation();
|
|
130
|
+
const result = spawnSync(npxInvocation.command, [...npxInvocation.argsPrefix, ...args], {
|
|
131
|
+
stdio: "inherit",
|
|
132
|
+
env: process.env,
|
|
133
|
+
shell: false,
|
|
134
|
+
});
|
|
104
135
|
if (result.error) throw result.error;
|
|
105
136
|
const status = result.status || 0;
|
|
106
137
|
if (status === 0) installBuddySkills(pkgRoot, "guanmetric");
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guandata/guanmetric",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "观远 BI 指标写操作工具 - 指标创建编辑删除、指标目录、公共维度、Excel 标准化",
|
|
5
5
|
"bin": {
|
|
6
6
|
"guanmetric": "bin/run.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
+
"postinstall": "node bin/postinstall.js",
|
|
9
10
|
"build": "node scripts/build.js && node scripts/sync-skill.js",
|
|
10
11
|
"changelog": "node ../../scripts/generate-release-changelog.js .",
|
|
11
12
|
"check-changelog": "node ../../scripts/check-release-changelog.js .",
|