@kizuhiko/cr 0.1.0
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/cr +32 -0
- package/install.js +131 -0
- package/package.json +23 -0
package/bin/cr
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper script that executes the Go binary.
|
|
5
|
+
* This is the npm bin entry point.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { execFileSync } = require("child_process");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
|
|
12
|
+
const binaryName = process.platform === "win32" ? "cr.exe" : "cr";
|
|
13
|
+
const binaryPath = path.join(__dirname, binaryName);
|
|
14
|
+
|
|
15
|
+
if (!fs.existsSync(binaryPath)) {
|
|
16
|
+
console.error(
|
|
17
|
+
"cr binary not found. Try reinstalling: npm install -g @kizuhiko/cr"
|
|
18
|
+
);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
execFileSync(binaryPath, process.argv.slice(2), {
|
|
24
|
+
stdio: "inherit",
|
|
25
|
+
env: process.env,
|
|
26
|
+
});
|
|
27
|
+
} catch (err) {
|
|
28
|
+
if (err.status !== undefined) {
|
|
29
|
+
process.exit(err.status);
|
|
30
|
+
}
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall script for the cr npm package.
|
|
5
|
+
* Downloads the correct Go binary for the user's platform.
|
|
6
|
+
*
|
|
7
|
+
* Follows the esbuild/turbo pattern:
|
|
8
|
+
* - Detects OS + arch
|
|
9
|
+
* - Downloads prebuilt binary from GitHub releases
|
|
10
|
+
* - Places it in bin/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const https = require("https");
|
|
14
|
+
const http = require("http");
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const { execSync } = require("child_process");
|
|
18
|
+
const os = require("os");
|
|
19
|
+
|
|
20
|
+
const VERSION = "0.1.0";
|
|
21
|
+
const BINARY_NAME = process.platform === "win32" ? "cr.exe" : "cr";
|
|
22
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
23
|
+
const BINARY_PATH = path.join(BIN_DIR, BINARY_NAME);
|
|
24
|
+
|
|
25
|
+
// GitHub release URL pattern
|
|
26
|
+
// Update this to your actual GitHub releases URL
|
|
27
|
+
const REPO = "qzhello/code-review";
|
|
28
|
+
const BASE_URL = `https://github.com/${REPO}/releases/download/v${VERSION}`;
|
|
29
|
+
|
|
30
|
+
function getPlatformKey() {
|
|
31
|
+
const platform = process.platform;
|
|
32
|
+
const arch = process.arch;
|
|
33
|
+
|
|
34
|
+
const platformMap = {
|
|
35
|
+
darwin: "darwin",
|
|
36
|
+
linux: "linux",
|
|
37
|
+
win32: "windows",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const archMap = {
|
|
41
|
+
x64: "amd64",
|
|
42
|
+
arm64: "arm64",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const os = platformMap[platform];
|
|
46
|
+
const cpu = archMap[arch];
|
|
47
|
+
|
|
48
|
+
if (!os || !cpu) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Unsupported platform: ${platform}-${arch}. ` +
|
|
51
|
+
`Supported: darwin-x64, darwin-arm64, linux-x64, linux-arm64, win32-x64`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return `${os}-${cpu}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getDownloadUrl() {
|
|
59
|
+
const key = getPlatformKey();
|
|
60
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
61
|
+
return `${BASE_URL}/cr-${key}${ext}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function download(url) {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const get = url.startsWith("https") ? https.get : http.get;
|
|
67
|
+
get(url, (res) => {
|
|
68
|
+
// Follow redirects
|
|
69
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
70
|
+
return download(res.headers.location).then(resolve).catch(reject);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (res.statusCode !== 200) {
|
|
74
|
+
reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const chunks = [];
|
|
79
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
80
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
81
|
+
res.on("error", reject);
|
|
82
|
+
}).on("error", reject);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function main() {
|
|
87
|
+
// Skip if binary already exists (e.g., from local build)
|
|
88
|
+
if (fs.existsSync(BINARY_PATH)) {
|
|
89
|
+
try {
|
|
90
|
+
execSync(`"${BINARY_PATH}" version`, { stdio: "pipe" });
|
|
91
|
+
console.log(`cr binary already exists at ${BINARY_PATH}`);
|
|
92
|
+
return;
|
|
93
|
+
} catch {
|
|
94
|
+
// Binary exists but doesn't work, re-download
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Ensure bin directory exists
|
|
99
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
100
|
+
|
|
101
|
+
const url = getDownloadUrl();
|
|
102
|
+
const platformKey = getPlatformKey();
|
|
103
|
+
|
|
104
|
+
console.log(`Downloading cr ${VERSION} for ${platformKey}...`);
|
|
105
|
+
console.log(` URL: ${url}`);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const data = await download(url);
|
|
109
|
+
fs.writeFileSync(BINARY_PATH, data);
|
|
110
|
+
fs.chmodSync(BINARY_PATH, 0o755);
|
|
111
|
+
console.log(` Installed cr to ${BINARY_PATH}`);
|
|
112
|
+
|
|
113
|
+
// Verify
|
|
114
|
+
try {
|
|
115
|
+
const version = execSync(`"${BINARY_PATH}" version`, {
|
|
116
|
+
encoding: "utf-8",
|
|
117
|
+
}).trim();
|
|
118
|
+
console.log(` ${version}`);
|
|
119
|
+
} catch {
|
|
120
|
+
console.warn(" Warning: binary installed but version check failed");
|
|
121
|
+
}
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.error(`\nFailed to download cr binary: ${err.message}`);
|
|
124
|
+
console.error(`\nYou can build from source instead:`);
|
|
125
|
+
console.error(` git clone https://github.com/${REPO}.git`);
|
|
126
|
+
console.error(` cd code-review && go build -o cr .`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kizuhiko/cr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Code Review CLI — hybrid rule + AI agent code review tool",
|
|
5
|
+
"keywords": ["code-review", "lint", "ai", "openai", "git", "cli"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"cr": "bin/cr"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node install.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin/",
|
|
15
|
+
"install.js",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=16"
|
|
20
|
+
},
|
|
21
|
+
"os": ["darwin", "linux", "win32"],
|
|
22
|
+
"cpu": ["x64", "arm64"]
|
|
23
|
+
}
|