diff --git a/importMap.json b/importMap.json index bc0e433..c5afc13 100644 --- a/importMap.json +++ b/importMap.json @@ -2,6 +2,7 @@ "imports": { "dash-compiler": "https://raw.githubusercontent.com/bridge-core/dash-compiler/main/dist/dash-compiler.bundled.es.js", "dash-compiler-local": "../dash-compiler/dist/dash-compiler.bundled.es.js", - "mc-project-core": "npm:mc-project-core" + "mc-project-core": "npm:mc-project-core", + "semver": "jsr:@std/semver@^1.0.3" } } diff --git a/mod.ts b/mod.ts index cb8931b..9545cd1 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,7 @@ // deno-lint-ignore-file no-explicit-any import { CLI } from './src/CLI.ts' import yargs from 'https://deno.land/x/yargs@v17.5.1-deno/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 +const CURRENT_VERSION = `0.4.7` + +async function fetchLatestVersion(): Promise { + 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)