Skip to content

Commit

Permalink
Merge pull request #16 from bridge-core/Thomas/UpdateNotifications
Browse files Browse the repository at this point in the history
feat: Add Update notifications
  • Loading branch information
ThomasOrs authored Nov 10, 2024
2 parents 6a0a60e + 63e7452 commit c797fa0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion importMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
33 changes: 33 additions & 0 deletions mod.ts
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'

Expand All @@ -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)
Expand Down

0 comments on commit c797fa0

Please sign in to comment.