From 922c6c1945264963216499c092ba12f3e3954c65 Mon Sep 17 00:00:00 2001 From: Thomas Orsbourne Date: Sat, 9 Nov 2024 20:10:50 -0400 Subject: [PATCH 1/3] feat: Update notifications --- importMap.json | 3 ++- mod.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) 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..430eefa 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,43 @@ window.process = { } type YargsInstance = ReturnType +const CURRENT_VERSION = `0.4.6` + +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;'); + console.log('%cPlease update to the latest version: https://github.com/bridge-core/deno-dash-compiler\n', '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) From 1d13fa60c4917b858201f9bd39e781f8be38419f Mon Sep 17 00:00:00 2001 From: Thomas Orsbourne Date: Sat, 9 Nov 2024 20:35:46 -0400 Subject: [PATCH 2/3] Remove please update line --- mod.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mod.ts b/mod.ts index 430eefa..1307faa 100644 --- a/mod.ts +++ b/mod.ts @@ -14,7 +14,7 @@ window.process = { } type YargsInstance = ReturnType -const CURRENT_VERSION = `0.4.6` +const CURRENT_VERSION = `0.4.4` async function fetchLatestVersion(): Promise { try { @@ -43,7 +43,6 @@ 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;'); - console.log('%cPlease update to the latest version: https://github.com/bridge-core/deno-dash-compiler\n', 'font-weight:bold;'); } } From 63e74525cc886e92a055b7001f7de27019874337 Mon Sep 17 00:00:00 2001 From: Thomas Orsbourne Date: Sat, 9 Nov 2024 20:36:18 -0400 Subject: [PATCH 3/3] Bump version to 0.4.7 --- mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.ts b/mod.ts index 1307faa..9545cd1 100644 --- a/mod.ts +++ b/mod.ts @@ -14,7 +14,7 @@ window.process = { } type YargsInstance = ReturnType -const CURRENT_VERSION = `0.4.4` +const CURRENT_VERSION = `0.4.7` async function fetchLatestVersion(): Promise { try {