kcode-pi 0.1.5 → 0.1.6
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/README.md +17 -0
- package/dist/cli/kcode.d.ts +1 -0
- package/dist/cli/kcode.js +27 -4
- package/package.json +1 -1
- package/src/cli/kcode.ts +29 -4
package/README.md
CHANGED
|
@@ -61,6 +61,12 @@ kcode context --refresh
|
|
|
61
61
|
kcode doctor
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
查看当前 KCode 版本:
|
|
65
|
+
|
|
66
|
+
```powershell
|
|
67
|
+
kcode version
|
|
68
|
+
```
|
|
69
|
+
|
|
64
70
|
启动工作环境:
|
|
65
71
|
|
|
66
72
|
```powershell
|
|
@@ -236,6 +242,16 @@ kcode context --refresh
|
|
|
236
242
|
kcode doctor
|
|
237
243
|
```
|
|
238
244
|
|
|
245
|
+
### `kcode version`
|
|
246
|
+
|
|
247
|
+
显示当前 KCode package 版本、安装路径、随包 Pi CLI 版本和 Node 版本。
|
|
248
|
+
|
|
249
|
+
```powershell
|
|
250
|
+
kcode version
|
|
251
|
+
kcode --version
|
|
252
|
+
kcode -v
|
|
253
|
+
```
|
|
254
|
+
|
|
239
255
|
### `kcode start`
|
|
240
256
|
|
|
241
257
|
启动 KCode 工作环境。
|
|
@@ -407,6 +423,7 @@ kd_debug 分析金蝶日志和堆栈
|
|
|
407
423
|
查看当前安装版本:
|
|
408
424
|
|
|
409
425
|
```powershell
|
|
426
|
+
kcode version
|
|
410
427
|
npm ls -g kcode-pi --depth=0
|
|
411
428
|
```
|
|
412
429
|
|
package/dist/cli/kcode.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export declare function runKcodeCli(args: string[], cwd?: string): KcodeCliResul
|
|
|
12
12
|
export declare function initProject(cwd: string): KcodeCliResult;
|
|
13
13
|
export declare function context(cwd: string, args: string[]): KcodeCliResult;
|
|
14
14
|
export declare function doctor(cwd: string): KcodeCliResult;
|
|
15
|
+
export declare function version(): KcodeCliResult;
|
|
15
16
|
export declare function start(cwd: string, piArgs: string[]): KcodeCliResult;
|
|
16
17
|
export declare function resolvePiCliCommand(piArgs?: string[]): PiCliCommand | undefined;
|
package/dist/cli/kcode.js
CHANGED
|
@@ -6,7 +6,9 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
import { ensureProjectContext, writeProjectContext } from "../context/project-context.js";
|
|
7
7
|
const packageRoot = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
8
8
|
const require = createRequire(import.meta.url);
|
|
9
|
-
const
|
|
9
|
+
const packageMetadata = readPackageMetadata(packageRoot);
|
|
10
|
+
const packageName = packageMetadata.name ?? "kcode-pi";
|
|
11
|
+
const packageVersion = packageMetadata.version ?? "unknown";
|
|
10
12
|
export function runKcodeCli(args, cwd = process.cwd()) {
|
|
11
13
|
const command = args[0] ?? "help";
|
|
12
14
|
switch (command) {
|
|
@@ -16,6 +18,10 @@ export function runKcodeCli(args, cwd = process.cwd()) {
|
|
|
16
18
|
return context(cwd, args.slice(1));
|
|
17
19
|
case "doctor":
|
|
18
20
|
return doctor(cwd);
|
|
21
|
+
case "version":
|
|
22
|
+
case "--version":
|
|
23
|
+
case "-v":
|
|
24
|
+
return version();
|
|
19
25
|
case "start":
|
|
20
26
|
return start(cwd, args.slice(1));
|
|
21
27
|
case "help":
|
|
@@ -57,6 +63,7 @@ export function doctor(cwd) {
|
|
|
57
63
|
const settingsPath = projectSettingsPath(cwd);
|
|
58
64
|
lines.push(`Node:${node.status === 0 ? node.stdout.trim() : "未找到"}`);
|
|
59
65
|
lines.push(`Pi CLI:${formatPiCliStatus(piCli, pi)}`);
|
|
66
|
+
lines.push(`KCode version:${packageName}@${packageVersion}`);
|
|
60
67
|
lines.push(`KCode package:${packageRoot}`);
|
|
61
68
|
lines.push(`项目配置:${existsSync(settingsPath) ? settingsPath : "未创建,请先运行 kcode init"}`);
|
|
62
69
|
lines.push(`项目上下文:${existsSync(join(cwd, ".pi", "kd", "PROJECT_CONTEXT.md")) ? join(cwd, ".pi", "kd", "PROJECT_CONTEXT.md") : "未创建,请运行 kcode context"}`);
|
|
@@ -70,6 +77,19 @@ export function doctor(cwd) {
|
|
|
70
77
|
output: lines.join("\n"),
|
|
71
78
|
};
|
|
72
79
|
}
|
|
80
|
+
export function version() {
|
|
81
|
+
const piCli = resolvePiCliCommand(["--version"]);
|
|
82
|
+
const pi = piCli ? spawnSync(piCli.command, piCli.args, { encoding: "utf8" }) : undefined;
|
|
83
|
+
return {
|
|
84
|
+
exitCode: 0,
|
|
85
|
+
output: [
|
|
86
|
+
`${packageName}@${packageVersion}`,
|
|
87
|
+
`KCode package:${packageRoot}`,
|
|
88
|
+
`Pi CLI:${formatPiCliStatus(piCli, pi)}`,
|
|
89
|
+
`Node:${process.version}`,
|
|
90
|
+
].join("\n"),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
73
93
|
export function start(cwd, piArgs) {
|
|
74
94
|
const init = initProject(cwd);
|
|
75
95
|
const piCli = resolvePiCliCommand(piArgs);
|
|
@@ -127,12 +147,14 @@ function isSameKcodePackage(candidate, currentPackage) {
|
|
|
127
147
|
return candidateName === packageName;
|
|
128
148
|
}
|
|
129
149
|
function readPackageName(packagePath) {
|
|
150
|
+
return readPackageMetadata(packagePath).name;
|
|
151
|
+
}
|
|
152
|
+
function readPackageMetadata(packagePath) {
|
|
130
153
|
try {
|
|
131
|
-
|
|
132
|
-
return packageJson.name;
|
|
154
|
+
return JSON.parse(readFileSync(join(packagePath, "package.json"), "utf8"));
|
|
133
155
|
}
|
|
134
156
|
catch {
|
|
135
|
-
return
|
|
157
|
+
return {};
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
function packageNameFromPath(path) {
|
|
@@ -182,6 +204,7 @@ function helpText() {
|
|
|
182
204
|
" kcode init 初始化当前项目的 .pi/settings.json",
|
|
183
205
|
" kcode context 生成或刷新 .pi/kd/PROJECT_CONTEXT.md",
|
|
184
206
|
" kcode doctor 检查 Node、随包 Pi CLI、KCode package 和项目级配置",
|
|
207
|
+
" kcode version 显示 KCode、随包 Pi CLI 和 Node 版本",
|
|
185
208
|
" kcode start 初始化项目配置后启动 KCode 工作环境",
|
|
186
209
|
].join("\n");
|
|
187
210
|
}
|
package/package.json
CHANGED
package/src/cli/kcode.ts
CHANGED
|
@@ -17,7 +17,9 @@ interface PiSettings {
|
|
|
17
17
|
|
|
18
18
|
const packageRoot = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
19
19
|
const require = createRequire(import.meta.url);
|
|
20
|
-
const
|
|
20
|
+
const packageMetadata = readPackageMetadata(packageRoot);
|
|
21
|
+
const packageName = packageMetadata.name ?? "kcode-pi";
|
|
22
|
+
const packageVersion = packageMetadata.version ?? "unknown";
|
|
21
23
|
|
|
22
24
|
export interface PiCliCommand {
|
|
23
25
|
command: string;
|
|
@@ -36,6 +38,10 @@ export function runKcodeCli(args: string[], cwd = process.cwd()): KcodeCliResult
|
|
|
36
38
|
return context(cwd, args.slice(1));
|
|
37
39
|
case "doctor":
|
|
38
40
|
return doctor(cwd);
|
|
41
|
+
case "version":
|
|
42
|
+
case "--version":
|
|
43
|
+
case "-v":
|
|
44
|
+
return version();
|
|
39
45
|
case "start":
|
|
40
46
|
return start(cwd, args.slice(1));
|
|
41
47
|
case "help":
|
|
@@ -84,6 +90,7 @@ export function doctor(cwd: string): KcodeCliResult {
|
|
|
84
90
|
|
|
85
91
|
lines.push(`Node:${node.status === 0 ? node.stdout.trim() : "未找到"}`);
|
|
86
92
|
lines.push(`Pi CLI:${formatPiCliStatus(piCli, pi)}`);
|
|
93
|
+
lines.push(`KCode version:${packageName}@${packageVersion}`);
|
|
87
94
|
lines.push(`KCode package:${packageRoot}`);
|
|
88
95
|
lines.push(`项目配置:${existsSync(settingsPath) ? settingsPath : "未创建,请先运行 kcode init"}`);
|
|
89
96
|
lines.push(`项目上下文:${existsSync(join(cwd, ".pi", "kd", "PROJECT_CONTEXT.md")) ? join(cwd, ".pi", "kd", "PROJECT_CONTEXT.md") : "未创建,请运行 kcode context"}`);
|
|
@@ -100,6 +107,20 @@ export function doctor(cwd: string): KcodeCliResult {
|
|
|
100
107
|
};
|
|
101
108
|
}
|
|
102
109
|
|
|
110
|
+
export function version(): KcodeCliResult {
|
|
111
|
+
const piCli = resolvePiCliCommand(["--version"]);
|
|
112
|
+
const pi = piCli ? spawnSync(piCli.command, piCli.args, { encoding: "utf8" }) : undefined;
|
|
113
|
+
return {
|
|
114
|
+
exitCode: 0,
|
|
115
|
+
output: [
|
|
116
|
+
`${packageName}@${packageVersion}`,
|
|
117
|
+
`KCode package:${packageRoot}`,
|
|
118
|
+
`Pi CLI:${formatPiCliStatus(piCli, pi)}`,
|
|
119
|
+
`Node:${process.version}`,
|
|
120
|
+
].join("\n"),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
103
124
|
export function start(cwd: string, piArgs: string[]): KcodeCliResult {
|
|
104
125
|
const init = initProject(cwd);
|
|
105
126
|
const piCli = resolvePiCliCommand(piArgs);
|
|
@@ -168,11 +189,14 @@ function isSameKcodePackage(candidate: string, currentPackage: string): boolean
|
|
|
168
189
|
}
|
|
169
190
|
|
|
170
191
|
function readPackageName(packagePath: string): string | undefined {
|
|
192
|
+
return readPackageMetadata(packagePath).name;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function readPackageMetadata(packagePath: string): { name?: string; version?: string } {
|
|
171
196
|
try {
|
|
172
|
-
|
|
173
|
-
return packageJson.name;
|
|
197
|
+
return JSON.parse(readFileSync(join(packagePath, "package.json"), "utf8")) as { name?: string; version?: string };
|
|
174
198
|
} catch {
|
|
175
|
-
return
|
|
199
|
+
return {};
|
|
176
200
|
}
|
|
177
201
|
}
|
|
178
202
|
|
|
@@ -229,6 +253,7 @@ function helpText(): string {
|
|
|
229
253
|
" kcode init 初始化当前项目的 .pi/settings.json",
|
|
230
254
|
" kcode context 生成或刷新 .pi/kd/PROJECT_CONTEXT.md",
|
|
231
255
|
" kcode doctor 检查 Node、随包 Pi CLI、KCode package 和项目级配置",
|
|
256
|
+
" kcode version 显示 KCode、随包 Pi CLI 和 Node 版本",
|
|
232
257
|
" kcode start 初始化项目配置后启动 KCode 工作环境",
|
|
233
258
|
].join("\n");
|
|
234
259
|
}
|