forked from Gitlink/gitlink-cli
Compare commits
1 Commits
master
...
fix/window
| Author | SHA1 | Date |
|---|---|---|
|
|
29d202c6da |
|
|
@ -27,38 +27,26 @@ jobs:
|
|||
run: |
|
||||
mkdir -p dist
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
MODULE="github.com/gitlink-org/gitlink-cli"
|
||||
LDFLAGS="-s -w -X ${MODULE}/cmd.Version=${VERSION}"
|
||||
|
||||
for pair in \
|
||||
"darwin amd64" \
|
||||
"darwin arm64" \
|
||||
"linux amd64" \
|
||||
"linux arm64" \
|
||||
"windows amd64" \
|
||||
"windows arm64"; do
|
||||
GOOS=$(echo "$pair" | cut -d' ' -f1)
|
||||
GOARCH=$(echo "$pair" | cut -d' ' -f2)
|
||||
OUT="gitlink-cli"
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
OUT="gitlink-cli.exe"
|
||||
fi
|
||||
|
||||
for pair in "darwin amd64" "darwin arm64" "linux amd64" "linux arm64" "windows amd64" "windows arm64"; do
|
||||
GOOS=$(echo $pair | cut -d' ' -f1)
|
||||
GOARCH=$(echo $pair | cut -d' ' -f2)
|
||||
echo "Building ${GOOS}-${GOARCH}..."
|
||||
BUILD_DIR="dist/gitlink-cli_${VERSION}_${GOOS}_${GOARCH}"
|
||||
mkdir -p "$BUILD_DIR"
|
||||
CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "$LDFLAGS" -o "$BUILD_DIR/$OUT" .
|
||||
|
||||
EXT=""
|
||||
if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi
|
||||
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-s -w -X 'github.com/gitlink-org/gitlink-cli/cmd.Version=${VERSION}'" -o "dist/gitlink-cli${EXT}" .
|
||||
|
||||
cd dist
|
||||
if [ "$GOOS" = "windows" ]; then
|
||||
(cd "$BUILD_DIR" && zip -q "../gitlink-cli_${VERSION}_${GOOS}_${GOARCH}.zip" "$OUT")
|
||||
zip "gitlink-cli_${VERSION}_${GOOS}_${GOARCH}.zip" "gitlink-cli${EXT}"
|
||||
else
|
||||
tar -czf "dist/gitlink-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz" -C "$BUILD_DIR" "$OUT"
|
||||
tar -czf "gitlink-cli_${VERSION}_${GOOS}_${GOARCH}.tar.gz" "gitlink-cli${EXT}"
|
||||
fi
|
||||
rm -rf "$BUILD_DIR"
|
||||
rm "gitlink-cli${EXT}"
|
||||
cd ..
|
||||
done
|
||||
|
||||
ls -lh dist
|
||||
|
||||
- name: Create Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
|
|
@ -67,27 +55,46 @@ jobs:
|
|||
dist/*.zip
|
||||
generate_release_notes: true
|
||||
|
||||
- name: Build npm package
|
||||
- name: Publish npm package
|
||||
run: |
|
||||
VERSION=${GITHUB_REF#refs/tags/v}
|
||||
export VERSION
|
||||
rm -rf npm-pkg
|
||||
mkdir -p npm-pkg
|
||||
cp -R npm/. npm-pkg/
|
||||
cp README.md npm-pkg/README.md
|
||||
rm -rf npm-pkg/skills
|
||||
cp -R skills npm-pkg/skills
|
||||
mkdir -p npm-pkg/bin npm-pkg/scripts npm-pkg/skills
|
||||
|
||||
node <<'NODE'
|
||||
const fs = require('fs');
|
||||
const pkgPath = 'npm-pkg/package.json';
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
||||
pkg.version = process.env.VERSION;
|
||||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
||||
NODE
|
||||
cp -r skills/* npm-pkg/skills/
|
||||
cp npm/bin/cli.js npm-pkg/bin/
|
||||
cp npm/bin/install-skills.js npm-pkg/bin/
|
||||
cp npm/scripts/install.js npm-pkg/scripts/
|
||||
cp README.md npm-pkg/
|
||||
|
||||
chmod +x npm-pkg/bin/cli.js
|
||||
chmod +x npm-pkg/bin/install-skills.js
|
||||
cat > npm-pkg/package.json << PKGEOF
|
||||
{
|
||||
"name": "@gitlink-ai/cli",
|
||||
"version": "${VERSION}",
|
||||
"description": "GitLink CLI — 面向 AI Agent 的 GitLink 命令行工具",
|
||||
"main": "bin/cli.js",
|
||||
"bin": {
|
||||
"gitlink-cli": "./bin/cli.js",
|
||||
"gitlink-cli-install-skills": "./bin/install-skills.js"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node scripts/install.js"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"scripts/",
|
||||
"skills/",
|
||||
"README.md",
|
||||
"package.json"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://www.gitlink.org.cn/Gitlink/gitlink-cli.git"
|
||||
},
|
||||
"keywords": ["gitlink", "cli", "ai-agent", "skills"],
|
||||
"author": "GitLink <support@gitlink.org.cn>",
|
||||
"license": "MulanPSL-2.0"
|
||||
}
|
||||
PKGEOF
|
||||
|
||||
cd npm-pkg
|
||||
npm publish --access public
|
||||
|
|
|
|||
10
README.md
10
README.md
|
|
@ -407,16 +407,6 @@ gitlink-cli auth status # Shows "✓ Logged in via GITLINK_TOKEN environment v
|
|||
|
||||
Priority: `GITLINK_TOKEN` env var > keyring/file stored token. When the env var is not set, the original interactive login flow works as before.
|
||||
|
||||
### Q: What if npm installs successfully but `gitlink-cli` reports a missing binary?
|
||||
|
||||
Reinstall first:
|
||||
|
||||
```bash
|
||||
npm install -g @gitlink-ai/cli
|
||||
```
|
||||
|
||||
If the error persists, check whether the release page contains the asset for your platform, for example `gitlink-cli_<version>_windows_amd64.zip` on Windows x64. You can also download the binary manually from the release page or build from source with `go install .`.
|
||||
|
||||
### Q: Where are credentials stored on Windows?
|
||||
|
||||
gitlink-cli uses Windows Credential Manager for secure token storage. If Credential Manager is unavailable, it automatically falls back to file storage (`~/.config/gitlink-cli/credentials`).
|
||||
|
|
|
|||
|
|
@ -386,16 +386,6 @@ gitlink-cli auth status # 显示 "✓ Logged in via GITLINK_TOKEN environment
|
|||
|
||||
Token 优先级:`GITLINK_TOKEN` 环境变量 > keyring/文件存储的 token。不设置环境变量时完全兼容原有交互式登录。
|
||||
|
||||
### Q: npm 安装成功但 `gitlink-cli` 提示缺少二进制怎么办?
|
||||
|
||||
先尝试重新安装:
|
||||
|
||||
```bash
|
||||
npm install -g @gitlink-ai/cli
|
||||
```
|
||||
|
||||
如果仍然失败,请检查 Release 页面是否包含当前平台的资产,例如 Windows x64 对应 `gitlink-cli_<version>_windows_amd64.zip`。也可以从 Release 页面手动下载二进制,或使用 `go install .` 从源码构建。
|
||||
|
||||
### Q: Windows 上凭证存储在哪里?
|
||||
|
||||
gitlink-cli 使用 Windows Credential Manager 安全存储 Token。如果 Credential Manager 不可用,会自动降级到文件存储(`~/.config/gitlink-cli/credentials`)。
|
||||
|
|
|
|||
|
|
@ -6,74 +6,29 @@ const fs = require("fs");
|
|||
const path = require("path");
|
||||
const { execFileSync } = require("child_process");
|
||||
|
||||
const BINARY_NAME = "gitlink-cli";
|
||||
const ext = process.platform === "win32" ? ".exe" : "";
|
||||
const binaryPath = path.join(__dirname, "gitlink-cli" + ext);
|
||||
|
||||
function getBinaryName(platform = process.platform) {
|
||||
return platform === "win32" ? `${BINARY_NAME}.exe` : BINARY_NAME;
|
||||
if (!fs.existsSync(binaryPath)) {
|
||||
console.error(
|
||||
`Error: gitlink-cli binary not found at ${binaryPath}\n\n` +
|
||||
`The binary was not downloaded during installation.\n` +
|
||||
`This usually happens when the postinstall script failed (e.g. network issues).\n\n` +
|
||||
`To fix, try one of:\n` +
|
||||
` 1. Reinstall: npm install -g @gitlink-ai/cli\n` +
|
||||
` 2. Manual download from:\n` +
|
||||
` https://www.gitlink.org.cn/Gitlink/gitlink-cli/releases\n` +
|
||||
` Then place the binary at: ${binaryPath}\n`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function getBinaryPath(platform = process.platform, baseDir = __dirname) {
|
||||
return path.join(baseDir, getBinaryName(platform));
|
||||
}
|
||||
|
||||
function formatMissingBinaryError(
|
||||
binaryPath,
|
||||
platform = process.platform,
|
||||
arch = process.arch
|
||||
) {
|
||||
return [
|
||||
`Error: ${BINARY_NAME} binary not found at ${binaryPath}`,
|
||||
`Platform: ${platform}/${arch}`,
|
||||
"",
|
||||
"The npm package was installed, but the native binary is missing.",
|
||||
"This usually means the release asset for your platform is unavailable or postinstall failed.",
|
||||
"",
|
||||
"Try reinstalling:",
|
||||
" npm install -g @gitlink-ai/cli",
|
||||
"",
|
||||
"If the problem persists, check the GitLink CLI release assets:",
|
||||
" https://www.gitlink.org.cn/Gitlink/gitlink-cli/releases",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function run(args = process.argv.slice(2), options = {}) {
|
||||
const platform = options.platform || process.platform;
|
||||
const arch = options.arch || process.arch;
|
||||
const binaryPath = options.binaryPath || getBinaryPath(platform);
|
||||
const execFile = options.execFileSync || execFileSync;
|
||||
const stderr = options.stderr || process.stderr;
|
||||
const exit = options.exit || process.exit;
|
||||
|
||||
function failMissingBinary() {
|
||||
stderr.write(`${formatMissingBinaryError(binaryPath, platform, arch)}\n`);
|
||||
return exit(1);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(binaryPath)) {
|
||||
return failMissingBinary();
|
||||
}
|
||||
|
||||
try {
|
||||
execFile(binaryPath, args, { stdio: "inherit" });
|
||||
} catch (err) {
|
||||
if (err.code === "ENOENT") {
|
||||
return failMissingBinary();
|
||||
}
|
||||
if (err.status !== undefined) {
|
||||
return exit(err.status);
|
||||
}
|
||||
stderr.write(`Failed to run ${BINARY_NAME}: ${err.message}\n`);
|
||||
return exit(1);
|
||||
try {
|
||||
execFileSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
||||
} catch (err) {
|
||||
if (err.status !== undefined) {
|
||||
process.exit(err.status);
|
||||
}
|
||||
console.error(`Failed to run gitlink-cli: ${err.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getBinaryName,
|
||||
getBinaryPath,
|
||||
formatMissingBinaryError,
|
||||
run,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
"gitlink-cli-install-skills": "bin/install-skills.js"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node scripts/install.js",
|
||||
"test": "node test/install.test.js && node test/cli.test.js"
|
||||
"postinstall": "node scripts/install.js"
|
||||
},
|
||||
"keywords": [
|
||||
"gitlink",
|
||||
|
|
|
|||
|
|
@ -13,14 +13,20 @@ const PACKAGE = require("../package.json");
|
|||
const VERSION = PACKAGE.version;
|
||||
const BINARY_NAME = "gitlink-cli";
|
||||
|
||||
// GitLink release download base URL
|
||||
// Format: https://www.gitlink.org.cn/Gitlink/gitlink-cli/releases
|
||||
// Attachment download: https://www.gitlink.org.cn/api/attachments/{attachment_id}
|
||||
// GitLink release download (primary)
|
||||
const RELEASE_BASE = "https://www.gitlink.org.cn";
|
||||
const REPO_OWNER = "Gitlink";
|
||||
const REPO_NAME = "gitlink-cli";
|
||||
|
||||
function getPlatformInfo(platform = os.platform(), arch = os.arch()) {
|
||||
// GitHub release download (fallback for users who cannot reach GitLink CDN)
|
||||
const GITHUB_RELEASE_BASE = "https://github.com";
|
||||
const GITHUB_REPO_OWNER = "ccfos";
|
||||
const GITHUB_REPO_NAME = "gitlink-cli";
|
||||
|
||||
function getPlatformInfo() {
|
||||
const platform = os.platform();
|
||||
const arch = os.arch();
|
||||
|
||||
const platformMap = {
|
||||
darwin: "darwin",
|
||||
linux: "linux",
|
||||
|
|
@ -120,7 +126,6 @@ function fetch(url, options = {}) {
|
|||
|
||||
async function findReleaseAsset(platform, arch) {
|
||||
const archiveName = getArchiveName(platform, arch);
|
||||
const tagName = `v${VERSION}`;
|
||||
|
||||
// Try fetching release info from GitLink API
|
||||
const apiUrl = `${RELEASE_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases.json`;
|
||||
|
|
@ -131,6 +136,7 @@ async function findReleaseAsset(platform, arch) {
|
|||
|
||||
// Find the release matching our version
|
||||
let release = null;
|
||||
const tagName = `v${VERSION}`;
|
||||
|
||||
if (Array.isArray(releases)) {
|
||||
release = releases.find(
|
||||
|
|
@ -177,8 +183,9 @@ async function findReleaseAsset(platform, arch) {
|
|||
console.log(`Warning: Could not fetch release info: ${e.message}`);
|
||||
}
|
||||
|
||||
// Fallback: try direct download URL pattern
|
||||
return `${RELEASE_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases/${tagName}/assets/${archiveName}`;
|
||||
// Fallback: download from GitHub releases
|
||||
const tagName = `v${VERSION}`;
|
||||
return `${GITHUB_RELEASE_BASE}/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/download/${tagName}/${archiveName}`;
|
||||
}
|
||||
|
||||
async function downloadAndExtract(url, destDir, platform) {
|
||||
|
|
@ -231,15 +238,9 @@ async function downloadAndExtract(url, destDir, platform) {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
let platformInfo = null;
|
||||
let archiveName = null;
|
||||
|
||||
try {
|
||||
platformInfo = getPlatformInfo();
|
||||
const { platform, arch } = platformInfo;
|
||||
archiveName = getArchiveName(platform, arch);
|
||||
const { platform, arch } = getPlatformInfo();
|
||||
console.log(`Platform: ${platform}-${arch}`);
|
||||
console.log(`Expected release asset: ${archiveName}`);
|
||||
|
||||
const binDir = path.join(__dirname, "..", "bin");
|
||||
if (!fs.existsSync(binDir)) {
|
||||
|
|
@ -267,12 +268,6 @@ async function main() {
|
|||
await downloadAndExtract(downloadUrl, binDir, platform);
|
||||
} catch (err) {
|
||||
console.error(`\nFailed to install ${BINARY_NAME}: ${err.message}`);
|
||||
if (platformInfo) {
|
||||
console.error(`Platform: ${platformInfo.platform}/${platformInfo.arch}`);
|
||||
}
|
||||
if (archiveName) {
|
||||
console.error(`Expected release asset: ${archiveName}`);
|
||||
}
|
||||
console.error(
|
||||
`\nYou can install manually:\n` +
|
||||
` 1. Download from https://www.gitlink.org.cn/${REPO_OWNER}/${REPO_NAME}/releases\n` +
|
||||
|
|
@ -283,13 +278,4 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getPlatformInfo,
|
||||
getBinaryName,
|
||||
getArchiveName,
|
||||
findReleaseAsset,
|
||||
};
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const cli = require("../bin/cli.js");
|
||||
|
||||
assert.equal(cli.getBinaryName("win32"), "gitlink-cli.exe");
|
||||
assert.equal(cli.getBinaryName("linux"), "gitlink-cli");
|
||||
assert.equal(cli.getBinaryName("darwin"), "gitlink-cli");
|
||||
|
||||
assert.equal(
|
||||
cli.getBinaryPath("win32", "C:\\tmp\\gitlink"),
|
||||
path.join("C:\\tmp\\gitlink", "gitlink-cli.exe")
|
||||
);
|
||||
|
||||
const message = cli.formatMissingBinaryError(
|
||||
"C:\\tmp\\gitlink-cli.exe",
|
||||
"win32",
|
||||
"x64"
|
||||
);
|
||||
assert.match(message, /binary not found/);
|
||||
assert.match(message, /Platform: win32\/x64/);
|
||||
assert.match(message, /npm install -g @gitlink-ai\/cli/);
|
||||
|
||||
let exitCode = null;
|
||||
const stderr = {
|
||||
output: "",
|
||||
write(text) {
|
||||
this.output += text;
|
||||
},
|
||||
};
|
||||
|
||||
cli.run(["version"], {
|
||||
binaryPath: path.join(os.tmpdir(), "gitlink-cli-test-missing-binary"),
|
||||
platform: "win32",
|
||||
arch: "x64",
|
||||
stderr,
|
||||
exit(code) {
|
||||
exitCode = code;
|
||||
return code;
|
||||
},
|
||||
execFileSync() {
|
||||
throw new Error("execFileSync should not be called for a missing binary");
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(exitCode, 1);
|
||||
assert.match(stderr.output, /gitlink-cli binary not found/);
|
||||
assert.match(stderr.output, /Platform: win32\/x64/);
|
||||
|
||||
console.log("cli wrapper tests passed");
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const install = require("../scripts/install.js");
|
||||
const pkg = require("../package.json");
|
||||
|
||||
assert.deepStrictEqual(install.getPlatformInfo("win32", "x64"), {
|
||||
platform: "windows",
|
||||
arch: "amd64",
|
||||
isWindows: true,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(install.getPlatformInfo("win32", "arm64"), {
|
||||
platform: "windows",
|
||||
arch: "arm64",
|
||||
isWindows: true,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(install.getPlatformInfo("darwin", "arm64"), {
|
||||
platform: "darwin",
|
||||
arch: "arm64",
|
||||
isWindows: false,
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(install.getPlatformInfo("linux", "x64"), {
|
||||
platform: "linux",
|
||||
arch: "amd64",
|
||||
isWindows: false,
|
||||
});
|
||||
|
||||
assert.equal(install.getBinaryName("windows"), "gitlink-cli.exe");
|
||||
assert.equal(install.getBinaryName("linux"), "gitlink-cli");
|
||||
assert.equal(install.getBinaryName("darwin"), "gitlink-cli");
|
||||
|
||||
assert.equal(
|
||||
install.getArchiveName("windows", "amd64"),
|
||||
`gitlink-cli_${pkg.version}_windows_amd64.zip`
|
||||
);
|
||||
assert.equal(
|
||||
install.getArchiveName("windows", "arm64"),
|
||||
`gitlink-cli_${pkg.version}_windows_arm64.zip`
|
||||
);
|
||||
assert.equal(
|
||||
install.getArchiveName("linux", "amd64"),
|
||||
`gitlink-cli_${pkg.version}_linux_amd64.tar.gz`
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => install.getPlatformInfo("freebsd", "x64"),
|
||||
/Unsupported platform/
|
||||
);
|
||||
|
||||
console.log("install helper tests passed");
|
||||
|
|
@ -74,14 +74,13 @@ rm -rf "$NPM_DIR/skills"
|
|||
cp -r "$PROJECT_DIR/skills" "$NPM_DIR/skills"
|
||||
|
||||
# Ensure bin dir exists and wrapper is executable
|
||||
chmod +x "$NPM_DIR/bin/cli.js"
|
||||
chmod +x "$NPM_DIR/bin/install-skills.js"
|
||||
chmod +x "$NPM_DIR/bin/gitlink-cli"
|
||||
|
||||
echo ""
|
||||
echo "=== Done ==="
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Upload dist/*.tar.gz and dist/*.zip to GitLink Release v${VERSION}"
|
||||
echo " 1. Upload dist/*.tar.gz to GitLink Release v${VERSION}"
|
||||
echo " URL: https://www.gitlink.org.cn/Gitlink/gitlink-cli/releases"
|
||||
echo ""
|
||||
echo " 2. Publish npm package:"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ const RELEASE_BASE = "https://www.gitlink.org.cn";
|
|||
const REPO_OWNER = "Gitlink";
|
||||
const REPO_NAME = "gitlink-cli";
|
||||
|
||||
const GITHUB_RELEASE_BASE = "https://github.com";
|
||||
const GITHUB_REPO_OWNER = "ccfos";
|
||||
const GITHUB_REPO_NAME = "gitlink-cli";
|
||||
|
||||
function getPlatformInfo() {
|
||||
const platform = os.platform();
|
||||
const arch = os.arch();
|
||||
|
|
@ -30,6 +34,18 @@ function getPlatformInfo() {
|
|||
return { platform: goPlatform, arch: goArch, isWindows: platform === "win32" };
|
||||
}
|
||||
|
||||
function getBinaryName(isWindows) {
|
||||
return isWindows ? BINARY_NAME + ".exe" : BINARY_NAME;
|
||||
}
|
||||
|
||||
function getArchiveExt(isWindows) {
|
||||
return isWindows ? ".zip" : ".tar.gz";
|
||||
}
|
||||
|
||||
function getArchiveName(platform, arch, isWindows) {
|
||||
return `${BINARY_NAME}_${VERSION}_${platform}_${arch}${getArchiveExt(isWindows)}`;
|
||||
}
|
||||
|
||||
function fetch(url, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const maxRedirects = options.maxRedirects || 5;
|
||||
|
|
@ -65,14 +81,14 @@ function fetch(url, options = {}) {
|
|||
}
|
||||
});
|
||||
req.on("error", reject);
|
||||
req.setTimeout(30000, () => { req.destroy(); reject(new Error("Timeout")); });
|
||||
req.setTimeout(60000, () => { req.destroy(); reject(new Error("Timeout")); });
|
||||
}
|
||||
doRequest(url);
|
||||
});
|
||||
}
|
||||
|
||||
async function findReleaseAsset(platform, arch) {
|
||||
const archiveName = `gitlink-cli_${VERSION}_${platform}_${arch}.tar.gz`;
|
||||
async function findReleaseAsset(platform, arch, isWindows) {
|
||||
const archiveName = getArchiveName(platform, arch, isWindows);
|
||||
const tagName = `v${VERSION}`;
|
||||
const apiUrl = `${RELEASE_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases.json`;
|
||||
|
||||
|
|
@ -85,7 +101,7 @@ async function findReleaseAsset(platform, arch) {
|
|||
if (release && release.attachments) {
|
||||
let asset = release.attachments.find(a => a.title === archiveName || a.filename === archiveName);
|
||||
if (!asset) {
|
||||
const pattern = `_${platform}_${arch}.tar.gz`;
|
||||
const pattern = `_${platform}_${arch}${getArchiveExt(isWindows)}`;
|
||||
asset = release.attachments.find(a => (a.title || a.filename || "").endsWith(pattern));
|
||||
}
|
||||
if (asset) {
|
||||
|
|
@ -94,36 +110,53 @@ async function findReleaseAsset(platform, arch) {
|
|||
return url;
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
console.log(`Warning: GitLink API failed: ${e.message}, trying GitHub...`);
|
||||
}
|
||||
|
||||
return `${RELEASE_BASE}/api/${REPO_OWNER}/${REPO_NAME}/releases/${tagName}/assets/${archiveName}`;
|
||||
return `${GITHUB_RELEASE_BASE}/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/download/${tagName}/${archiveName}`;
|
||||
}
|
||||
|
||||
async function downloadAndExtract(url, destDir, platform) {
|
||||
async function downloadAndExtract(url, destDir, isWindows) {
|
||||
console.log(`Downloading ${BINARY_NAME} from ${url}...`);
|
||||
|
||||
const data = await fetch(url);
|
||||
const archivePath = path.join(destDir, "download.tar.gz");
|
||||
console.log(`Downloaded ${(data.length / 1024 / 1024).toFixed(1)} MB`);
|
||||
|
||||
const archivePath = path.join(destDir, "download" + getArchiveExt(isWindows));
|
||||
fs.writeFileSync(archivePath, data);
|
||||
execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "pipe" });
|
||||
|
||||
if (isWindows) {
|
||||
execSync(
|
||||
`powershell -NoProfile -Command "Expand-Archive -Force -Path '${archivePath}' -DestinationPath '${destDir}'"`,
|
||||
{ stdio: "pipe" }
|
||||
);
|
||||
} else {
|
||||
execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "pipe" });
|
||||
}
|
||||
fs.unlinkSync(archivePath);
|
||||
|
||||
const binaryPath = path.join(destDir, BINARY_NAME);
|
||||
const binaryName = getBinaryName(isWindows);
|
||||
const binaryPath = path.join(destDir, binaryName);
|
||||
if (!fs.existsSync(binaryPath)) {
|
||||
const files = fs.readdirSync(destDir);
|
||||
for (const file of files) {
|
||||
const subPath = path.join(destDir, file, BINARY_NAME);
|
||||
const subPath = path.join(destDir, file, binaryName);
|
||||
if (fs.existsSync(subPath)) { fs.renameSync(subPath, binaryPath); break; }
|
||||
}
|
||||
}
|
||||
if (!fs.existsSync(binaryPath)) throw new Error("Binary not found after extraction");
|
||||
fs.chmodSync(binaryPath, 0o755);
|
||||
if (!fs.existsSync(binaryPath)) throw new Error(`Binary "${binaryName}" not found after extraction`);
|
||||
if (!isWindows) fs.chmodSync(binaryPath, 0o755);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { platform, arch } = getPlatformInfo();
|
||||
const { platform, arch, isWindows } = getPlatformInfo();
|
||||
console.log(`Platform: ${platform}-${arch}`);
|
||||
|
||||
const binDir = path.join(__dirname, "..", "bin");
|
||||
if (!fs.existsSync(binDir)) { fs.mkdirSync(binDir, { recursive: true }); }
|
||||
|
||||
const binaryPath = path.join(binDir, BINARY_NAME);
|
||||
const binaryPath = path.join(binDir, getBinaryName(isWindows));
|
||||
if (fs.existsSync(binaryPath)) {
|
||||
try {
|
||||
const output = execSync(`"${binaryPath}" version`, { encoding: "utf-8", stdio: "pipe", timeout: 5000 });
|
||||
|
|
@ -131,19 +164,24 @@ async function main() {
|
|||
console.log(`${BINARY_NAME} v${VERSION} already installed.`);
|
||||
return;
|
||||
}
|
||||
console.log(`Version mismatch (got: ${output.trim()}, want: ${VERSION}), updating...`);
|
||||
} catch (e) {}
|
||||
fs.unlinkSync(binaryPath);
|
||||
}
|
||||
|
||||
try {
|
||||
const downloadUrl = await findReleaseAsset(platform, arch);
|
||||
await downloadAndExtract(downloadUrl, binDir, platform);
|
||||
console.log(`${BINARY_NAME} v${VERSION} installed.`);
|
||||
const downloadUrl = await findReleaseAsset(platform, arch, isWindows);
|
||||
await downloadAndExtract(downloadUrl, binDir, isWindows);
|
||||
console.log(`${BINARY_NAME} v${VERSION} installed successfully.`);
|
||||
} catch (err) {
|
||||
// Don't fail npm install — binary can be installed later
|
||||
console.warn(`⚠ ${BINARY_NAME} binary download failed: ${err.message}`);
|
||||
console.warn(` Skills are installed. You can install the binary manually later:`);
|
||||
console.warn(` npm run postinstall`);
|
||||
console.error(`\n Failed to install ${BINARY_NAME}: ${err.message}`);
|
||||
console.error(
|
||||
`\n You can install manually:\n` +
|
||||
` 1. Download from https://www.gitlink.org.cn/${REPO_OWNER}/${REPO_NAME}/releases\n` +
|
||||
` 2. Extract and place the binary in: ${binDir}\n` +
|
||||
` 3. Or retry: npm run postinstall\n`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue