diff --git a/package-lock.json b/package-lock.json index 9a3e687..ab868ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pa-website-validator-ng-gui", - "version": "1.0.26", + "version": "1.0.27", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pa-website-validator-ng-gui", - "version": "1.0.26", + "version": "1.0.27", "license": "BSD-3-Clause", "dependencies": { "@types/express": "^5.0.0", @@ -14,7 +14,7 @@ "dotenv": "^16.4.5", "ejs": "^3.1.10", "express": "^4.21.1", - "pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.9", + "pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.10", "sqlite3": "^5.1.7", "typeorm": "^0.3.20", "yargs": "^17.7.2", @@ -7213,8 +7213,8 @@ } }, "node_modules/pa-website-validator-ng": { - "version": "1.1.9", - "resolved": "git+ssh://git@github.com/italia/pa-website-validator-ng.git#4c6474080be30f6a8918b0add229e176c7548d82", + "version": "1.1.10", + "resolved": "git+ssh://git@github.com/italia/pa-website-validator-ng.git#a7ba4b20b3a21bb7b9e771352a70c839cb5b3746", "dependencies": { "axios": "^1.7.4", "cheerio": "^1.0.0-rc.12", diff --git a/package.json b/package.json index 2f3cd6c..0c5fd8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pa-website-validator-ng-gui", - "version": "1.0.26", + "version": "1.0.27", "main": "dist/main.js", "type": "module", "scripts": { @@ -27,7 +27,7 @@ "dotenv": "^16.4.5", "ejs": "^3.1.10", "express": "^4.21.1", - "pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.9", + "pa-website-validator-ng": "github:italia/pa-website-validator-ng#v1.1.10", "sqlite3": "^5.1.7", "typeorm": "^0.3.20", "yargs": "^17.7.2", diff --git a/src/main.ts b/src/main.ts index 4dced78..3d854e9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import { cleanConsoleOutput, AuditI, getChromePath, + checkNewerRelease, } from "./utils.js"; import { municipalityAudits, schoolAudits } from "./storage/auditMapping.js"; import { Item } from "./entities/Item"; @@ -134,6 +135,8 @@ const loadPage = async ( timeout?: string, pages?: string, ) => { + const checkVersionResult = await checkNewerRelease(); + const queryParam = url?.split("id=")[1]; const item = await getItemById(queryParam ?? ""); const mappedAuditsFailedObject: ( @@ -184,6 +187,12 @@ const loadPage = async ( const data = { crawlerVersion: VERSION_VALIDATOR, guiVersion: VERSION, + isLatestVersion: checkVersionResult?.isLatest, + latestVersion: checkVersionResult?.latestVersion, + latestVersionURL: + checkVersionResult?.isLatest == false + ? checkVersionResult.latestVersionURL + : "", basePathCss: path.join(__dirname, "public/css/"), basePathJs: path.join(__dirname, "public/js/"), basePathImages: path.join(__dirname, "public/images/"), diff --git a/src/utils.ts b/src/utils.ts index b9b9f6c..2169d8d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,12 +1,18 @@ import { readFileSync, readdirSync, statSync } from "fs"; import path from "path"; import puppeteer from "puppeteer"; +import { VERSION as currentVersion } from "./versions.js"; export interface AuditI { text: string; status: string; } +const GITHUBReleaseUrl = + "https://api.github.com/repos/italia/pa-website-validator-gui/releases/latest"; + +let releaseInfo: null | any = null; + const getDataFromJSONReport = (reportPath: string) => { let successCount = 0; let failedCount = 0; @@ -120,4 +126,40 @@ const getChromePath = () => { } }; -export { getDataFromJSONReport, cleanConsoleOutput, getChromePath }; +const checkNewerRelease = async () => { + if (releaseInfo) return releaseInfo; + + try { + const response = await fetch(GITHUBReleaseUrl); + if (!response.ok) { + throw new Error(`GitHub API error: ${response.statusText}`); + } + const latestRelease = await response.json(); + const latestVersion = latestRelease.tag_name; + const latestVersionURL = latestRelease.html_url; + + const isLatest = currentVersion >= latestVersion.replace("v", ""); + + releaseInfo = { + isLatest, + currentVersion, + latestVersion, + latestVersionURL, + }; + } catch (error) { + if (error instanceof Error) console.log(`${error.message}`); + releaseInfo = { + isLatest: true, + currentVersion, + }; + } + + return releaseInfo; +}; + +export { + getDataFromJSONReport, + cleanConsoleOutput, + getChromePath, + checkNewerRelease, +}; diff --git a/src/views/partials/header.ejs b/src/views/partials/header.ejs index dbaa026..28f6d6e 100644 --- a/src/views/partials/header.ejs +++ b/src/views/partials/header.ejs @@ -1,3 +1,8 @@ +<% if (!isLatestVersion ) { %> + +<% } %>
<%- include('components/skip-links'); %>
@@ -8,15 +13,14 @@

Versione GUI: <%- guiVersion %>

Versione validatore: <%- crawlerVersion %>

@@ -32,9 +36,7 @@