@d5render/cli 0.0.5 → 0.0.22

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 CHANGED
@@ -1,14 +1,29 @@
1
1
  {
2
2
  "name": "@d5render/cli",
3
- "version": "0.0.5",
4
- "description": "",
5
- "license": "ISC",
6
- "main": "index.ts",
7
- "scripts": {
8
- "test": "echo \"Error: run tests from root\" && exit 1"
3
+ "type": "module",
4
+ "license": "MIT",
5
+ "author": "jasirou",
6
+ "main": "./standalone.js",
7
+ "version": "0.0.22",
8
+ "devDependencies": {
9
+ "@modelcontextprotocol/sdk": "^1.24.3",
10
+ "@types/node": "22.18.1",
11
+ "@types/vscode": "^1.88.0",
12
+ "@vscode/vsce": "^3.2.2",
13
+ "rolldown": "^1.0.0-beta.53",
14
+ "zod": "^4.1.13"
9
15
  },
10
- "publishConfig": {
11
- "access": "public"
16
+ "files": [
17
+ "dist",
18
+ "./copilot.config.js",
19
+ "./standalone.js"
20
+ ],
21
+ "bin": {
22
+ "d5cli": "standalone.js"
12
23
  },
13
- "gitHead": "88903f7889cf971e64b713417105bceaca469eae"
24
+ "scripts": {
25
+ "build:copilot": "rolldown -c packages/copilot/rolldown.config.ts",
26
+ "environment": "node ./scripts.js",
27
+ "publish": "node ./scripts.js publish"
28
+ }
14
29
  }
package/standalone.js ADDED
@@ -0,0 +1,74 @@
1
+ import { execSync, spawn } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { env, exit, platform } from "node:process";
5
+ import { errorMessage, getHash, getPrompt, name, report, tools } from "./copilot.config.js";
6
+
7
+ const prompt = `call the mcp tool '${name}-${getHash}' to load review commits, if the task encounters an error, throw that, otherwise, you can decide for yourself which tools to use to enrich context and determine whether a specific commit needs to be reviewed.
8
+ Then, use chinese as default language to organize the report into JSON format and call the mcp tool '${name}-${report}', please ignore error encountered when calling this and report title should not contain words such as MCP or "中文".`;
9
+
10
+ install();
11
+ const copilot = spawn("node", [findCopilopt(), "--stream", "off", ...tools, "-p", prompt], {
12
+ cwd: env.CI_PROJECT_DIR,
13
+ ...(platform === "win32" && { windowsHide: true }),
14
+ });
15
+
16
+ let hasError = false;
17
+ const errorRegex = new RegExp(errorMessage, "i");
18
+ copilot.stdout.on("data", (data) => {
19
+ const str = String(data);
20
+ console.log(str);
21
+
22
+ if (errorRegex.test(str)) hasError = true;
23
+ });
24
+ copilot.stderr.on("data", (data) => console.error(String(data)));
25
+ copilot.on("close", () => {
26
+ if (hasError) exit(1);
27
+ else exit(0);
28
+ });
29
+
30
+ function install() {
31
+ if (!env.CI) return;
32
+ console.log("install dependencies...");
33
+ try {
34
+ const local =
35
+ platform !== "win32"
36
+ ? execSync("npm i -g @github/copilot --registry=https://registry.npmmirror.com --force")
37
+ : execSync("npm list @github/copilot -g --depth=0 --json").toString();
38
+ const localInfo = JSON.parse(local);
39
+ const localVersion = localInfo.dependencies?.["@github/copilot"]?.version;
40
+ const remoteVersion = execSync("npm view @github/copilot version --registry=https://registry.npmmirror.com")
41
+ .toString()
42
+ .trim();
43
+ if (localVersion !== remoteVersion) {
44
+ execSync("npm uninstall -g @github/copilot --force");
45
+ execSync("npm install -g @github/copilot --registry=https://registry.npmmirror.com", {
46
+ stdio: "inherit",
47
+ });
48
+ }
49
+ } catch (error) {
50
+ console.error(error);
51
+ }
52
+ }
53
+ function findCopilopt() {
54
+ let copilot = execSync("npm list @github/copilot -g -p").toString().trim();
55
+ if (!copilot) {
56
+ try {
57
+ const pathEnv = env.PATH || env.Path || "";
58
+ const pathSeparator = platform === "win32" ? ";" : ":";
59
+ const npm = pathEnv.split(pathSeparator).find((p) => p.includes("npm"));
60
+ if (npm) copilot = join(npm, "node_modules", "@github", "copilot");
61
+ } catch {}
62
+ }
63
+ const pkg = join(copilot, "package.json");
64
+ if (!existsSync(pkg)) throw new Error("找不到 copilot 包");
65
+ const copilotPackage = JSON.parse(readFileSync(pkg, "utf8"));
66
+ // return join(copilot, copilotPackage.bin.copilot);
67
+ // 兼容 bin 字段可能是字符串或对象的情况
68
+ const binPath =
69
+ typeof copilotPackage.bin === "string"
70
+ ? copilotPackage.bin
71
+ : copilotPackage.bin?.copilot || copilotPackage.bin?.["@github/copilot"];
72
+ if (!binPath) throw new Error("找不到 copilot 可执行文件路径");
73
+ return join(copilot, binPath);
74
+ }
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- const cli = 'hello @d5render/cli hah'
2
-
3
- export default cli