diff --git a/ports/fx_ghrel.ts b/ports/fx_ghrel.ts new file mode 100644 index 0000000..c692000 --- /dev/null +++ b/ports/fx_ghrel.ts @@ -0,0 +1,72 @@ +import { + $, + DownloadArgs, + dwnUrlOut, + GithubReleasePort, + InstallArgs, + InstallConfigSimple, + osXarch, +} from "../port.ts"; +import { GithubReleasesInstConf, readGhVars } from "../modules/ports/ghrel.ts"; + +const manifest = { + ty: "denoWorker@v1" as const, + name: "fx_ghrel", + version: "0.1.0-alpha", + moduleSpecifier: import.meta.url, + platforms: osXarch(["linux", "windows", "darwin"], ["aarch64", "x86_64"]), +}; + +export default function conf( + config: InstallConfigSimple & GithubReleasesInstConf = {}, +) { + return { + ...readGhVars(), + ...config, + port: manifest, + }; +} + +export class Port extends GithubReleasePort { + repoOwner = "antonmedv"; + repoName = "fx"; + + override downloadUrls(args: DownloadArgs) { + const { installVersion, platform } = args; + let arch; + switch (platform.arch) { + case "x86_64": + arch = "amd64"; + break; + case "aarch64": + arch = "arm64"; + break; + default: + throw new Error(`unsupported: ${platform.arch}`); + } + const os = platform.os; + let ext; + switch (os) { + case "linux": + case "darwin": + ext = ""; + break; + case "windows": + ext = ".exe"; + break; + default: + throw new Error(`unsupported: ${platform.arch}`); + } + return [this.releaseArtifactUrl(installVersion, `fx_${os}_${arch}${ext}`)] + .map(dwnUrlOut) + .map((dwn) => ({ ...dwn, name: `fx${ext}`, mode: 0o700 })); + } + + override async install(args: InstallArgs) { + const installPath = $.path(args.installPath); + if (await installPath.exists()) { + await installPath.remove({ recursive: true }); + } + await $.path(args.downloadPath).copy(installPath.join("bin")); + } +} diff --git a/ports/livekit_cli_ghrel.ts b/ports/livekit_cli_ghrel.ts new file mode 100644 index 0000000..04ed9f5 --- /dev/null +++ b/ports/livekit_cli_ghrel.ts @@ -0,0 +1,90 @@ +import { + $, + DownloadArgs, + dwnUrlOut, + GithubReleasePort, + InstallArgs, + InstallConfigSimple, + osXarch, + std_path, + unarchive, +} from "../port.ts"; +import { GithubReleasesInstConf, readGhVars } from "../modules/ports/ghrel.ts"; + +const manifest = { + ty: "denoWorker@v1" as const, + name: "livekit_cli_ghrel", + version: "0.1.0", + moduleSpecifier: import.meta.url, + // darwin releases only avail on brew + platforms: osXarch(["linux", "windows"], ["aarch64", "x86_64"]), +}; + +export default function conf( + config: InstallConfigSimple & GithubReleasesInstConf = {}, +) { + return { + ...readGhVars(), + ...config, + port: manifest, + }; +} + +export class Port extends GithubReleasePort { + repoOwner = "livekit"; + repoName = "livekit-cli"; + + override downloadUrls(args: DownloadArgs) { + const { installVersion, platform } = args; + let arch; + switch (platform.arch) { + case "x86_64": + arch = "amd64"; + break; + case "aarch64": + arch = "arm64"; + break; + default: + throw new Error(`unsupported: ${platform.arch}`); + } + const os = platform.os; + let ext; + switch (os) { + case "linux": + ext = "tar.gz"; + break; + case "windows": + ext = "zip"; + break; + default: + throw new Error(`unsupported: ${platform.arch}`); + } + return [ + this.releaseArtifactUrl( + installVersion, + `lk_${installVersion.replace(/^v/, "")}_${os}_${arch}.${ext}`, + ), + ].map(dwnUrlOut); + } + + override async install(args: InstallArgs) { + const [{ name: fileName }] = this.downloadUrls(args); + + const fileDwnPath = std_path.resolve(args.downloadPath, fileName); + await unarchive(fileDwnPath, args.tmpDirPath); + + const tmpDir = $.path(args.tmpDirPath); + const binDir = await tmpDir.join("bin").ensureDir(); + for (const fileName of ["lk"]) { + await tmpDir + .join(args.platform.os == "windows" ? fileName + ".exe" : fileName) + .renameToDir(binDir); + } + + const installPath = $.path(args.installPath); + if (await installPath.exists()) { + await installPath.remove({ recursive: true }); + } + await tmpDir.rename(installPath); + } +} diff --git a/ports/mod.ts b/ports/mod.ts index 8e21ba3..4b23bed 100644 --- a/ports/mod.ts +++ b/ports/mod.ts @@ -8,9 +8,11 @@ export { default as cpy_bs } from "./cpy_bs.ts"; export { default as curl } from "./curl.ts"; export { default as deno_ghrel } from "./deno_ghrel.ts"; export { default as earthly } from "./earthly.ts"; +export { default as fx_ghrel } from "./fx_ghrel.ts"; export { default as git } from "./git.ts"; export { default as infisical } from "./infisical.ts"; export { default as jq_ghrel } from "./jq_ghrel.ts"; +export { default as livekit_cli_ghrel } from "./livekit_cli_ghrel.ts"; export { default as meta_cli_ghrel } from "./meta_cli_ghrel.ts"; export { default as mold } from "./mold.ts"; export { default as node } from "./node.ts"; diff --git a/tests/ports.ts b/tests/ports.ts index d659aab..2d8b0a9 100644 --- a/tests/ports.ts +++ b/tests/ports.ts @@ -71,6 +71,19 @@ const cases: CustomE2eTestCase[] = [ installConf: ports.rustup(), ePoint: `rustup-init --version`, }, + // 15 megs + { + name: "fx_ghrel", + installConf: ports.fx_ghrel(), + ePoint: `fx --version`, + }, + // 22 megs + { + name: "livekit_cli_ghrel", + installConf: ports.livekit_cli_ghrel(), + ePoint: `lk --version`, + ignore: Deno.build.os == "darwin", + }, // 23 megs { name: "temporal",