@d5render/cli 0.1.15 → 0.1.18

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/d5cli CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  import { execSync, spawn } from "node:child_process";
3
- import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
3
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { dirname, join } from "node:path";
5
5
  import { argv, env, exit, platform } from "node:process";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
8
  //#region package.json
9
- var name = "@d5render/cli";
10
- var version = "0.1.15";
9
+ var name$1 = "@d5render/cli";
10
+ var version = "0.1.18";
11
11
 
12
12
  //#endregion
13
13
  //#region copilot/server/config.ts
14
- const name$1 = "d5_mcp_review_builtin";
14
+ const name = "d5_mcp_review_builtin";
15
15
  const report = "report";
16
16
  const getHash = "hash";
17
17
  const file = "./copilot.js";
@@ -37,7 +37,7 @@ const envUsed = {
37
37
  };
38
38
  const tools = [
39
39
  "--additional-mcp-config",
40
- JSON.stringify({ mcpServers: { [name$1]: {
40
+ JSON.stringify({ mcpServers: { [name]: {
41
41
  type: "local",
42
42
  command: "node",
43
43
  args: [serveFile, `--customizenv=${JSON.stringify(envUsed)}`],
@@ -142,10 +142,13 @@ const commits = () => {
142
142
 
143
143
  //#endregion
144
144
  //#region copilot/bin/utils.ts
145
- const root = env.HOME ?? env.HOMEPATH ?? env.LOCALAPPDATA;
145
+ const HOME = env.HOME ?? env.HOMEPATH;
146
+ const root = HOME ?? env.LOCALAPPDATA;
146
147
  if (!root) throw new Error("cannot find home directory");
147
148
  const cwd = join(dirname(fileURLToPath(import.meta.url)), "../");
148
149
  function deploy() {
150
+ const config = join(HOME, ".copilot/config.json");
151
+ if (existsSync(config)) rmSync(config);
149
152
  const dir = join(root, ".copilot/skills/codereview");
150
153
  if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
151
154
  const skillRoot = join(cwd, ".skills/review");
@@ -194,8 +197,8 @@ function need() {
194
197
 
195
198
  //#endregion
196
199
  //#region copilot/bin/index.ts
197
- const prompt = `Load skills, then call the mcp tool '${name$1}-${getHash}' to load code-review commits, if the task encounters an error, throw that.
198
- Otherwise, use chinese as default language to call the mcp tool '${name$1}-${report}'`;
200
+ const prompt = `Load skills, then call the mcp tool '${name}-${getHash}' to load code-review commits, if the task encounters an error, throw that.
201
+ Otherwise, use chinese as default language to call the mcp tool '${name}-${report}'`;
199
202
  deploy();
200
203
  if (need()) {
201
204
  install();
@@ -221,20 +224,21 @@ if (need()) {
221
224
  } else console.log("重复提交,进程跳过");
222
225
  function findCopilopt() {
223
226
  let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
224
- if (!copilot) try {
225
- const pathEnv = env.PATH || env.Path || "";
226
- const pathSeparator = platform === "win32" ? ";" : ":";
227
- const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
228
- if (npm) copilot = join(npm, "node_modules", "@github", "copilot");
229
- } catch {}
227
+ if (!copilot) {
228
+ const first = platform === "win32" ? win : linux;
229
+ const second = platform === "win32" ? linux : win;
230
+ copilot = first();
231
+ if (!copilot) copilot = second();
232
+ if (!copilot) throw new Error("没找到安装的包");
233
+ }
230
234
  const pkg = join(copilot, "package.json");
231
- if (!existsSync(pkg)) throw new Error("non copilot package found");
235
+ if (!existsSync(pkg)) throw new Error("安装的包找不到正确版本 " + pkg);
232
236
  const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
233
237
  const binPath = typeof copilotPackage.bin === "string" ? copilotPackage.bin : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
234
238
  if (!binPath) throw new Error("non copilot executable found");
235
239
  const copilotVersion = copilotPackage.version || "unknown";
236
240
  const copilotPath = join(copilot, binPath);
237
- console.log(`${name} server:
241
+ console.log(`${name$1} server:
238
242
  version: ${version}
239
243
  path: ${serveFile}
240
244
  copilot:
@@ -242,5 +246,23 @@ copilot:
242
246
  path: ${copilotPath}`);
243
247
  return copilotPath;
244
248
  }
249
+ function win() {
250
+ const pathEnv = env.PATH || env.Path || "";
251
+ const pathSeparator = platform === "win32" ? ";" : ":";
252
+ const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
253
+ if (npm) return join(npm, "node_modules", "@github", "copilot");
254
+ return "";
255
+ }
256
+ function linux() {
257
+ let cached = env.NVM_BIN;
258
+ if (!cached) {
259
+ const pathEnv = env.PATH || env.Path || "";
260
+ const pathSeparator = platform === "win32" ? ";" : ":";
261
+ const npm = pathEnv.split(pathSeparator).find((p) => p.includes(".nvm"));
262
+ if (npm) cached = npm;
263
+ }
264
+ if (cached) return join(cached, "..", "lib", "node_modules", "@github", "copilot");
265
+ return "";
266
+ }
245
267
 
246
268
  //#endregion
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "license": "MIT",
5
5
  "author": "jasirou",
6
6
  "main": "./bin/d5cli",
7
- "version": "0.1.15",
7
+ "version": "0.1.18",
8
8
  "devDependencies": {
9
9
  "@modelcontextprotocol/sdk": "^1.25.1",
10
10
  "@types/node": "^25.0.3",