feat: custom download url, custom repository

This commit is contained in:
xHyroM 2022-07-28 07:50:56 +02:00
parent 27a94d6f80
commit e6a8865f72
9 changed files with 135 additions and 21 deletions

View file

@ -1,4 +1,5 @@
import fetch from 'node-fetch';
import { getArchitecture } from './getAsset';
export interface Asset {
name: string;
@ -14,12 +15,28 @@ export interface Release {
version: string;
}
export default async(version: string, token: string, miscTestBuilds: boolean): Promise<Release> => {
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : 'oven-sh/bun'
export default async(version: string, token: string, fullRepository: string, customDownloadUrl: string | null, miscTestBuilds: boolean): Promise<Release> => {
const repository = miscTestBuilds ? 'oven-sh/misc-test-builds' : fullRepository.split('/').slice(3).join('/');
let url;
if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
if (customDownloadUrl) url = customDownloadUrl;
else if (version === 'latest' || miscTestBuilds) url = `https://api.github.com/repos/${repository}/releases/latest`;
else url = `https://api.github.com/repos/${repository}/releases/tags/${version.includes('canary') ? version : `bun-v${version}`}`;
if (customDownloadUrl) {
return {
name: 'custom',
version: version + Math.random().toString(36).slice(-8),
html_url: customDownloadUrl,
tag_name: 'custom',
assets: [
{
name: `bun-${process.platform}-${getArchitecture()}`,
browser_download_url: customDownloadUrl
}
]
};
}
const release: any = await (await fetch(url, {
headers: {
'Content-Type': 'application/json',