From ad6ee5950c103cbd7f826111dae1d1744c045a0c Mon Sep 17 00:00:00 2001 From: xHyroM Date: Tue, 12 Jul 2022 08:39:36 +0200 Subject: [PATCH] feat: clean version --- src/index.ts | 2 +- src/utils/getAsset.ts | 17 ++++------------- src/utils/getGithubRelease.ts | 8 ++++++-- src/utils/install.ts | 5 +++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/index.ts b/src/index.ts index 911f9d4..8e66159 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ const main = async() => { const release = await getGithubRelease(version, token); if (release?.message === 'Not Found') return exit('Invalid bun version.'); - info(`Going to install release ${release.tag_name}`); + info(`Going to install release ${release.version}`); await install(release); diff --git a/src/utils/getAsset.ts b/src/utils/getAsset.ts index 2ea159d..ed909bd 100644 --- a/src/utils/getAsset.ts +++ b/src/utils/getAsset.ts @@ -13,20 +13,11 @@ export default (assets: Asset[]) => { throw new Error(`Unsupported architechture ${process.arch}.`); } - let platform; - switch (process.platform) { - case 'linux': - platform = 'linux' - break; - case 'darwin': - platform = 'darwin' - break; - default: - throw new Error(`Unsupported platform ${process.platform}.`); - } + if (!['linux', 'darwin'].some(platform => process.platform === platform)) + throw new Error(`Unsupported platform ${process.platform}.`); return { - name: `bun-${platform}-${arch}.zip`, - asset: assets.find(asset => asset.name === `bun-${platform}-${arch}.zip`), + name: `bun-${process.platform}-${arch}.zip`, + asset: assets.find(asset => asset.name === `bun-${process.platform}-${arch}.zip`), } } \ No newline at end of file diff --git a/src/utils/getGithubRelease.ts b/src/utils/getGithubRelease.ts index 63d7611..9d6bc0a 100644 --- a/src/utils/getGithubRelease.ts +++ b/src/utils/getGithubRelease.ts @@ -9,7 +9,8 @@ export interface Release { html_url: string; tag_name: string; message?: string; - assets: Asset[] + assets: Asset[]; + version: string; } export default async(version: string, token: string): Promise => { @@ -25,5 +26,8 @@ export default async(version: string, token: string): Promise => { } })).json(); - return release; + return { + ...release, + version: release.tag_name.replace('bun-v', '') + }; } \ No newline at end of file diff --git a/src/utils/install.ts b/src/utils/install.ts index 14f01e7..65b09d8 100644 --- a/src/utils/install.ts +++ b/src/utils/install.ts @@ -6,7 +6,8 @@ import getHomeDir from './getHomeDir.js'; import { join } from 'path'; export default async(release: Release) => { - const cache = find('bun', release.tag_name); + const cache = find('bun', release.version); + console.log(cache); if (cache) { info(`Using cached Bun installation from ${cache}.`); addPath(cache); @@ -23,7 +24,7 @@ export default async(release: Release) => { const newCache = await cacheDir( extracted, 'bun', - release.tag_name + release.version ); info(`Cached Bun to ${newCache}.`);