mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
feat: add bsk CLI auto update
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,10 +8,13 @@
|
||||
* --repo Tencent/BrowserSkill \
|
||||
* --server-url https://github.com \
|
||||
* --branch main \
|
||||
* --dist dist \
|
||||
* --out version.json
|
||||
*/
|
||||
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { parseArgs } from "node:util";
|
||||
|
||||
/** Platform key -> Rust target triple */
|
||||
@@ -29,6 +32,7 @@ const { values } = parseArgs({
|
||||
repo: { type: "string" },
|
||||
"server-url": { type: "string", default: "https://github.com" },
|
||||
branch: { type: "string", default: "main" },
|
||||
dist: { type: "string" },
|
||||
out: { type: "string" },
|
||||
},
|
||||
});
|
||||
@@ -37,11 +41,12 @@ const version = values.version?.replace(/^v/, "");
|
||||
const repo = values.repo;
|
||||
const serverUrl = values["server-url"]?.replace(/\/$/, "") ?? "https://github.com";
|
||||
const branch = values.branch ?? "main";
|
||||
const dist = values.dist;
|
||||
const out = values.out;
|
||||
|
||||
if (!version || !repo || !out) {
|
||||
console.error(
|
||||
"Usage: --version <semver> --repo <owner/repo> --out <path> [--server-url URL] [--branch main]",
|
||||
"Usage: --version <semver> --repo <owner/repo> --out <path> [--server-url URL] [--branch main] [--dist dist]",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -56,10 +61,33 @@ function assetFilename(platformKey, triple) {
|
||||
return `bsk-v${version}-${triple}.tar.gz`;
|
||||
}
|
||||
|
||||
function sha256File(path) {
|
||||
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
||||
}
|
||||
|
||||
function assetEntry(platformKey, triple) {
|
||||
const filename = assetFilename(platformKey, triple);
|
||||
const url = `${releaseBase}/${filename}`;
|
||||
if (!dist) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const path = join(dist, filename);
|
||||
if (!existsSync(path)) {
|
||||
console.error(`missing release asset for checksum: ${path}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return {
|
||||
url,
|
||||
sha256: sha256File(path),
|
||||
};
|
||||
}
|
||||
|
||||
const assets = Object.fromEntries(
|
||||
Object.entries(PLATFORMS).map(([key, triple]) => [
|
||||
key,
|
||||
`${releaseBase}/${assetFilename(key, triple)}`,
|
||||
assetEntry(key, triple),
|
||||
]),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user