clash-verge/scripts/portable.mjs

60 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-03-12 19:52:31 +03:00
import fs from "fs-extra";
import path from "path";
import AdmZip from "adm-zip";
import { createRequire } from "module";
import { getOctokit, context } from "@actions/github";
/// Script for ci
/// 打包绿色版/便携版 (only Windows)
2022-04-12 20:17:40 +03:00
async function resolvePortable() {
2022-03-12 19:52:31 +03:00
if (process.platform !== "win32") return;
const releaseDir = "./src-tauri/target/release";
if (!(await fs.pathExists(releaseDir))) {
throw new Error("could not found the release dir");
}
const zip = new AdmZip();
zip.addLocalFile(path.join(releaseDir, "Clash Verge.exe"));
zip.addLocalFile(path.join(releaseDir, "clash.exe"));
2022-06-01 19:56:05 +03:00
zip.addLocalFile(path.join(releaseDir, "clash-meta.exe"));
2022-03-12 19:52:31 +03:00
zip.addLocalFolder(path.join(releaseDir, "resources"), "resources");
const require = createRequire(import.meta.url);
const packageJson = require("../package.json");
const { version } = packageJson;
2022-04-12 20:17:40 +03:00
const zipFile = `Clash.Verge_${version}_x64_portable.zip`;
2022-03-12 19:52:31 +03:00
zip.writeZip(zipFile);
2022-04-12 20:17:40 +03:00
console.log("[INFO]: create portable zip successfully");
2022-03-12 19:52:31 +03:00
// push release assets
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error("GITHUB_TOKEN is required");
}
const options = { owner: context.repo.owner, repo: context.repo.repo };
const github = getOctokit(process.env.GITHUB_TOKEN);
2022-11-21 19:16:30 +03:00
console.log("[INFO]: upload to ", process.env.TAG_NAME || `v${version}`);
2022-05-16 21:46:15 +03:00
const { data: release } = await github.rest.repos.getReleaseByTag({
...options,
2022-11-21 19:16:30 +03:00
tag: process.env.TAG_NAME || `v${version}`,
2022-05-16 21:46:15 +03:00
});
console.log(release.name);
await github.rest.repos.uploadReleaseAsset({
...options,
release_id: release.id,
name: zipFile,
data: zip.toBuffer(),
});
}
2022-11-21 19:16:30 +03:00
resolvePortable().catch(console.error);