-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from bridge-core/Thomas/UpdateNotifications
feat: Add Update notifications
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// deno-lint-ignore-file no-explicit-any | ||
import { CLI } from './src/CLI.ts' | ||
import yargs from 'https://deno.land/x/[email protected]/deno.ts' | ||
import { parse as semverParse, compare as semverCompare } from "jsr:@std/semver"; | ||
import { comMojangFolder } from './src/comMojangFolder.ts' | ||
import { initRuntimes, swcVersion } from './src/deps.ts' | ||
|
||
|
@@ -13,10 +14,42 @@ window.process = { | |
} | ||
|
||
type YargsInstance = ReturnType<typeof yargs> | ||
const CURRENT_VERSION = `0.4.7` | ||
|
||
async function fetchLatestVersion(): Promise<string | null> { | ||
try { | ||
const response = await fetch('https://api.github.com/repos/bridge-core/deno-dash-compiler/releases/latest'); | ||
if (!response.ok) { | ||
return null; | ||
} | ||
const data = await response.json(); | ||
return data.tag_name; | ||
} catch (error) { | ||
console.error('Error fetching the latest version:', error); | ||
return null; | ||
} | ||
} | ||
|
||
function compareVersions(current: string, latest: string): boolean { | ||
const currentVersion = semverParse(current); | ||
const latestVersion = semverParse(latest); | ||
if (!currentVersion || !latestVersion) { | ||
throw new Error('Invalid version format'); | ||
} | ||
return semverCompare(currentVersion, latestVersion) < 0; | ||
} | ||
|
||
async function checkForUpdates() { | ||
const latestVersion = await fetchLatestVersion(); | ||
if (latestVersion && compareVersions(CURRENT_VERSION, latestVersion)) { | ||
console.log(`%cA new version (${latestVersion}) is available. You are currently using version v${CURRENT_VERSION}.`, 'color: red; font-weight:bold;'); | ||
} | ||
} | ||
|
||
initRuntimes(`https://esm.sh/@swc/wasm-web@${swcVersion}/wasm-web_bg.wasm`) | ||
|
||
if (import.meta.main) { | ||
await checkForUpdates(); | ||
const cli = new CLI() | ||
|
||
yargs(Deno.args) | ||
|