ziwei-cli 1.1.1 → 1.1.3
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/bin/install.cjs +17 -11
- package/lib/commands/palace.js +18 -37
- package/package.json +1 -1
package/bin/install.cjs
CHANGED
|
@@ -161,18 +161,23 @@ async function installCli() {
|
|
|
161
161
|
logStep("3/4", "安装 ziwei CLI...");
|
|
162
162
|
|
|
163
163
|
try {
|
|
164
|
-
// Check if already installed
|
|
164
|
+
// Check if already installed with correct version
|
|
165
165
|
try {
|
|
166
|
-
execSync("
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
const version = execSync("ziwei --version", { encoding: "utf8" }).trim();
|
|
167
|
+
const pkg = require(path.join(PACKAGE_ROOT, "package.json"));
|
|
168
|
+
if (version === pkg.version) {
|
|
169
|
+
logSuccess(`ziwei CLI 已安装 (v${version})`);
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
logInfo(`当前版本 ${version},升级到 ${pkg.version}...`);
|
|
169
173
|
} catch {
|
|
170
174
|
// Not installed, proceed
|
|
171
175
|
}
|
|
172
176
|
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
// Global install ensures dependencies are properly resolved
|
|
178
|
+
// and persists after npx temp dir is cleaned up
|
|
179
|
+
logInfo("正在全局安装 ziwei CLI 及依赖...");
|
|
180
|
+
execSync("npm install -g ziwei-cli", { stdio: "inherit" });
|
|
176
181
|
logSuccess("ziwei CLI 安装成功");
|
|
177
182
|
|
|
178
183
|
// Verify
|
|
@@ -182,7 +187,7 @@ async function installCli() {
|
|
|
182
187
|
return true;
|
|
183
188
|
} catch (error) {
|
|
184
189
|
logError(`CLI 安装失败: ${error.message}`);
|
|
185
|
-
logInfo("你可以手动运行:
|
|
190
|
+
logInfo("你可以手动运行: npm install -g ziwei-cli");
|
|
186
191
|
return false;
|
|
187
192
|
}
|
|
188
193
|
}
|
|
@@ -197,15 +202,16 @@ ${color("green", "━━━━━━━━━━━━━━━━━━━━
|
|
|
197
202
|
|
|
198
203
|
${color("cyan", "CLI 命令:")}
|
|
199
204
|
ziwei palace --palace 命宫 --date 1990-05-15 --time 10:30 --gender 男 --city 北京
|
|
200
|
-
ziwei
|
|
205
|
+
ziwei bazi --date 1990-05-15 --time 10:30 --gender 男
|
|
206
|
+
ziwei calendar
|
|
201
207
|
|
|
202
208
|
${color("cyan", "Skill 触发词:")}
|
|
203
|
-
|
|
209
|
+
算命、看命、命盘、运势、合盘、紫微、八字、流年、大限
|
|
204
210
|
|
|
205
211
|
${color("yellow", "在 Claude Code / OpenClaw 中试试:")}
|
|
206
212
|
"帮我算命"
|
|
207
213
|
"看看我今年的运势"
|
|
208
|
-
"
|
|
214
|
+
"帮我排个八字"
|
|
209
215
|
|
|
210
216
|
${color("dim", "重启 Claude Code 会话后 skill 将自动加载")}
|
|
211
217
|
`);
|
package/lib/commands/palace.js
CHANGED
|
@@ -16,28 +16,13 @@ function buildQueryDate(year, month = 1, day = 1) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* 获取指定层级的宫位及三方四正(统一走 horoscope 接口)
|
|
20
20
|
*/
|
|
21
|
-
function getScopedPalaceAndSurrounded(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { targetPalace, surroundedPalaces, scopeData: {} };
|
|
27
|
-
} else {
|
|
28
|
-
// 运限层从 horoscope 获取
|
|
29
|
-
const horoscope = astrolabe.horoscope(queryDate);
|
|
30
|
-
const scopeData = horoscope[scope];
|
|
31
|
-
|
|
32
|
-
if (!scopeData) {
|
|
33
|
-
throw new Error(`无效的运限范围: ${scope}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const targetPalace = horoscope.palace(palaceName, scope);
|
|
37
|
-
const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
|
|
38
|
-
|
|
39
|
-
return { targetPalace, surroundedPalaces, scopeData };
|
|
40
|
-
}
|
|
21
|
+
function getScopedPalaceAndSurrounded(horoscope, palaceName, scope) {
|
|
22
|
+
const scopeData = horoscope[scope] || {};
|
|
23
|
+
const targetPalace = horoscope.palace(palaceName, scope);
|
|
24
|
+
const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
|
|
25
|
+
return { targetPalace, surroundedPalaces, scopeData };
|
|
41
26
|
}
|
|
42
27
|
|
|
43
28
|
/**
|
|
@@ -87,18 +72,20 @@ export async function executePalace(options) {
|
|
|
87
72
|
is_leap: leap || false
|
|
88
73
|
});
|
|
89
74
|
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
75
|
+
// 归一化宫位名称:iztro 内部除"命宫"外均不带"宫"字
|
|
76
|
+
const base = palace.replace(/宫$/, '');
|
|
77
|
+
const targetPalaceName = base === '命' ? '命宫' : base;
|
|
78
|
+
|
|
79
|
+
// 构建查询日期(origin 用今天的日期,不影响本命数据)
|
|
80
|
+
const queryDate = scope !== 'origin'
|
|
81
|
+
? buildQueryDate(year, month || 1, day || 1)
|
|
82
|
+
: new Date().toISOString().slice(0, 10);
|
|
95
83
|
|
|
96
|
-
//
|
|
97
|
-
const
|
|
84
|
+
// 统一通过 horoscope 接口查询所有层级
|
|
85
|
+
const horoscope = astrolabe.horoscope(queryDate);
|
|
98
86
|
|
|
99
|
-
// 获取目标宫位和三方四正
|
|
100
87
|
const { targetPalace, surroundedPalaces, scopeData } = getScopedPalaceAndSurrounded(
|
|
101
|
-
|
|
88
|
+
horoscope, targetPalaceName, scope
|
|
102
89
|
);
|
|
103
90
|
|
|
104
91
|
if (!targetPalace) {
|
|
@@ -109,13 +96,7 @@ export async function executePalace(options) {
|
|
|
109
96
|
}
|
|
110
97
|
|
|
111
98
|
// 检测格局
|
|
112
|
-
|
|
113
|
-
if (scope === 'origin') {
|
|
114
|
-
patterns = detectPatterns(astrolabe);
|
|
115
|
-
} else {
|
|
116
|
-
const horoscope = astrolabe.horoscope(queryDate);
|
|
117
|
-
patterns = detectPatterns(horoscope, scope);
|
|
118
|
-
}
|
|
99
|
+
const patterns = detectPatterns(horoscope, scope);
|
|
119
100
|
|
|
120
101
|
// 构建结果
|
|
121
102
|
const result = {
|