Skip to content

Commit

Permalink
feat(port): fx and lk
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Nov 16, 2024
1 parent e45b86c commit 8f044cf
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 0 deletions.
72 changes: 72 additions & 0 deletions ports/fx_ghrel.ts
Original file line number Diff line number Diff line change
@@ -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"));
}
}
90 changes: 90 additions & 0 deletions ports/livekit_cli_ghrel.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions ports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 13 additions & 0 deletions tests/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8f044cf

Please sign in to comment.