|
| 1 | +import { remove, exists, chmod } from "fs-extra"; |
| 2 | +import { downloadRelease } from "@terascope/fetch-github-release"; |
| 3 | +import { arch, platform } from "os"; |
| 4 | +import { spawnSync } from "child_process"; |
| 5 | +import { isArray } from "es-toolkit/compat"; |
| 6 | +import { join } from "path"; |
| 7 | + |
| 8 | +const dld = async (targetPath: string) => { |
| 9 | + const dufsName = platform() === "win32" ? "dufs.exe" : "dufs"; |
| 10 | + const dufsPath = join(targetPath, dufsName); |
| 11 | + const dufsExists = await exists(dufsPath); |
| 12 | + if (dufsExists) return; |
| 13 | + |
| 14 | + // 下载最新 dufs |
| 15 | + const user = "sigoden"; |
| 16 | + const repo = "dufs"; |
| 17 | + const leaveZipped = false; |
| 18 | + const disableLogging = false; |
| 19 | + |
| 20 | + const a = arch() |
| 21 | + .replace("arm64", "aarch64") |
| 22 | + .replace("ia32", "i686") |
| 23 | + .replace("x64", "x86_64"); |
| 24 | + |
| 25 | + const p = platform().replace("win32", "windows"); |
| 26 | + |
| 27 | + const names = await downloadRelease( |
| 28 | + user, |
| 29 | + repo, |
| 30 | + targetPath, |
| 31 | + (release) => release.prerelease === false, |
| 32 | + (asset) => asset.name.includes(p) && asset.name.includes(a), |
| 33 | + leaveZipped, |
| 34 | + disableLogging |
| 35 | + ); |
| 36 | + |
| 37 | + const target = (isArray(names) ? names : names.assetFileNames).at(0); |
| 38 | + |
| 39 | + if (target && (await exists(target))) { |
| 40 | + spawnSync("tar", ["-zxvf", target, "-C", targetPath], { |
| 41 | + stdio: "inherit", |
| 42 | + }); |
| 43 | + await remove(target); |
| 44 | + await chmod(join(targetPath, dufsName), 777); |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +await dld("dist/main"); |
0 commit comments