Premier commit

Cette révision appartient à :
Théo Gastinel a révisé 2026-10-11 01:57:33 +02:00
révision 0ec3f0e133
109 fichiers modifiés
+17644

Aucun fichier ne correspond à votre recherche

+369
Voir le fichier
@@ -0,0 +1,369 @@
#!/usr/bin/env node
/**
* tools/upgrade-gws-refonte.js
*
* Script de correction et d'optimisation avancée :
* 1. Empêche le downgrade accidentel via l'API live (vérification Semver).
* 2. Résout le conflit de routage SPA sur les ancres internes #spa-gws-*.
* 3. Ajoute un helper universel de presse-papier avec fallback document.execCommand.
* 4. Anime la pastille cyan pulsante dans la barre de navigation.
* 5. Intègre une barre de sous-navigation rapide dans le sas SPA #gws.
* 6. Ajoute le bouton de téléchargement du paquet .gws sur la fiche #app-weather-studio.
* 7. Ajoute les données structurées SoftwareApplication JSON-LD dans gws/index.html.
* 8. Nettoie sitemap.xml pour se conformer strictement aux standards des moteurs de recherche (pas d'ancres #).
* 9. Synchronise intégralement _Site et Actual_Website.
* 10. Re-génère les archives Brotli 11 et Gzip 9.
*/
const fs = require('fs');
const path = require('path');
const SITE_DIR = path.resolve(__dirname, '..');
const ACTUAL_DIR = path.resolve(SITE_DIR, '../Actual_Website');
console.log('[UPGRADE] Début de la mise à jour...');
function replaceWithEol(source, searchStr, replaceStr, eol) {
const normalizedSource = source.replace(/\r\n/g, '\n');
const normalizedSearch = searchStr.replace(/\r\n/g, '\n');
const normalizedReplace = replaceStr.replace(/\r\n/g, '\n');
if (!normalizedSource.includes(normalizedSearch)) {
return null;
}
const result = normalizedSource.replace(normalizedSearch, normalizedReplace);
return eol === '\r\n' ? result.replace(/\n/g, '\r\n') : result;
}
// =========================================================================
// 1. MISE À JOUR DE _Site/gws/index.html
// =========================================================================
const GWS_HTML_PATH = path.join(SITE_DIR, 'gws/index.html');
let gwsHtml = fs.readFileSync(GWS_HTML_PATH, 'utf8');
const gwsEol = gwsHtml.includes('\r\n') ? '\r\n' : '\n';
// A. Ajout du Schema.org SoftwareApplication JSON-LD si pas déjà présent
if (!gwsHtml.includes('"SoftwareApplication"')) {
const jsonLdGws = `
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "Gastinel Weather Studio",
"operatingSystem": "Windows 10, Windows 11 (64-bit)",
"applicationCategory": "WeatherApplication",
"softwareVersion": "0.3.5",
"fileFormat": "application/x-msdownload",
"fileSize": "3.6MB",
"downloadUrl": "https://gastinel.me/gws/downloads/Gastinel_Weather_Studio_0.3.5_x64-setup.exe",
"author": {
"@type": "Person",
"name": "Théo Gastinel",
"url": "https://gastinel.me/"
},
"offers": {
"@type": "Offer",
"price": "0",
"priceCurrency": "EUR"
},
"description": "Station logicielle d'investigation thermique et d'analyse microclimatique des trous à froid (TAF) du Vercors. Décodage natif USB Elitech RC-5 et cartographie IGN."
}
</script>
`;
gwsHtml = gwsHtml.replace('<link rel="icon"', jsonLdGws + '<link rel="icon"');
console.log('✓ gws/index.html : JSON-LD SoftwareApplication ajouté.');
}
// B. Mise à jour du script JS dans gws/index.html
const oldGwsScriptRegex = /<script>[\s\S]*?checkLatestVersion\(\);\s*\}\)\(\);\s*<\/script>/;
const newGwsScript = `<script>
(function() {
'use strict';
var API_URL = 'https://gastinel.me/gws/api/v1/update/windows/x86_64/0.0.0';
var DEFAULT_VERSION = '0.3.5';
var DEFAULT_EXE_URL = 'https://gastinel.me/gws/downloads/Gastinel_Weather_Studio_0.3.5_x64-setup.exe';
var DEFAULT_GWS_URL = 'https://gastinel.me/gws/downloads/update-0.3.5.gws';
var DEFAULT_SHA256 = '6B2935E732A35175D01F586D7D8578DF63FB445444460464039FEBC7EA841CCA';
// Helper copie universel
function copyText(text, cb) {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(function() {
if (cb) cb();
}).catch(function() {
fallbackCopy(text, cb);
});
} else {
fallbackCopy(text, cb);
}
}
function fallbackCopy(text, cb) {
try {
var ta = document.createElement('textarea');
ta.value = text;
ta.setAttribute('readonly', '');
ta.style.position = 'fixed';
ta.style.top = '-9999px';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
var ok = document.execCommand('copy');
document.body.removeChild(ta);
if (ok && cb) cb();
} catch (err) {
console.warn('Fallback copy error:', err);
}
}
// Copie SHA-256
var copyShaBtn = document.getElementById('copyShaBtn');
var sha256Value = document.getElementById('sha256Value');
var copyShaText = document.getElementById('copyShaText');
if (copyShaBtn && sha256Value) {
copyShaBtn.addEventListener('click', function() {
var text = sha256Value.textContent.trim();
copyText(text, function() {
copyShaBtn.classList.add('copied');
if (copyShaText) copyShaText.textContent = 'Hash copié !';
setTimeout(function() {
copyShaBtn.classList.remove('copied');
if (copyShaText) copyShaText.textContent = 'Copier le hash';
}, 2200);
});
});
}
// Copie Commande PowerShell
var copyCmdBtn = document.getElementById('copyCmdBtn');
if (copyCmdBtn) {
copyCmdBtn.addEventListener('click', function() {
var cmd = 'Get-FileHash "Gastinel_Weather_Studio_*.exe" -Algorithm SHA256';
copyText(cmd, function() {
copyCmdBtn.textContent = 'Commande copiée !';
setTimeout(function() { copyCmdBtn.textContent = 'Copier la commande'; }, 2000);
});
});
}
// Comparateur Semver pour éviter le downgrade
function parseVersion(vStr) {
if (!vStr) return [0, 0, 0];
return vStr.replace(/^v/i, '').split('.').map(function(n) {
var num = parseInt(n, 10);
return isNaN(num) ? 0 : num;
});
}
function compareSemver(v1, v2) {
var p1 = parseVersion(v1);
var p2 = parseVersion(v2);
for (var i = 0; i < Math.max(p1.length, p2.length); i++) {
var n1 = p1[i] || 0;
var n2 = p2[i] || 0;
if (n1 > n2) return 1;
if (n1 < n2) return -1;
}
return 0;
}
// Interrogation de l'API en direct
function checkLatestVersion() {
var statusMsg = document.getElementById('apiStatusMessage');
var navBadge = document.getElementById('navVersionBadge');
var heroVer = document.getElementById('heroVersionLabel');
var exeBtn = document.getElementById('heroDownloadBtnExe');
var gwsBtn = document.getElementById('heroDownloadBtnGws');
if (statusMsg) statusMsg.textContent = 'Interrogation de l\\'API gastinel.me en cours...';
fetch(API_URL, { cache: 'no-cache' })
.then(function(resp) {
if (!resp.ok && resp.status !== 204) {
throw new Error('HTTP ' + resp.status);
}
if (resp.status === 204) {
return null;
}
return resp.json();
})
.then(function(data) {
if (data && data.version && compareSemver(data.version, DEFAULT_VERSION) >= 0) {
var v = data.version.replace(/^v/i, '');
if (navBadge) navBadge.textContent = 'v' + v;
if (heroVer) heroVer.textContent = 'v' + v;
if (data.url && exeBtn) {
exeBtn.href = data.url;
}
if (gwsBtn) {
gwsBtn.href = 'https://gastinel.me/gws/downloads/update-' + v + '.gws';
}
if (statusMsg) {
statusMsg.textContent = 'Dernière version confirmée en ligne : v' + v + ' (Canal stable)';
}
} else {
if (statusMsg) {
statusMsg.textContent = 'Version officielle stable : v' + DEFAULT_VERSION + ' (Distribution certifiée)';
}
}
})
.catch(function(err) {
if (statusMsg) {
statusMsg.textContent = 'Canal officiel actif · Version locale par défaut v' + DEFAULT_VERSION;
}
});
}
var refreshBtn = document.getElementById('apiRefreshBtn');
if (refreshBtn) {
refreshBtn.addEventListener('click', function(e) {
e.preventDefault();
checkLatestVersion();
});
}
// Lancement automatique au chargement
checkLatestVersion();
})();
</script>`;
if (oldGwsScriptRegex.test(gwsHtml)) {
gwsHtml = gwsHtml.replace(oldGwsScriptRegex, newGwsScript);
console.log('✓ gws/index.html : Script interactif mis à jour avec Semver, copy helper et fix encodage.');
}
fs.writeFileSync(GWS_HTML_PATH, gwsHtml, 'utf8');
// =========================================================================
// 2. MISE À JOUR DE _Site/index.html
// =========================================================================
const INDEX_HTML_PATH = path.join(SITE_DIR, 'index.html');
let indexHtml = fs.readFileSync(INDEX_HTML_PATH, 'utf8');
const indexEol = indexHtml.includes('\r\n') ? '\r\n' : '\n';
// A. Routeur SPA go() et ancres spa-gws-*
const oldGoRouteCheck = ` var targetScroll=null;
if(route==='news' || route==='carnet'){ targetScroll='news'; route='realisations'; }
if(route==='application') route='apps';
if(route==='telechargement') route='gws';
if(legalTab) route='termes';`;
const newGoRouteCheck = ` var targetScroll=null;
if(route==='news' || route==='carnet'){ targetScroll='news'; route='realisations'; }
if(route==='application') route='apps';
if(route==='telechargement') route='gws';
if(route && route.indexOf('spa-gws-') === 0){ targetScroll=route; route='gws'; }
if(legalTab) route='termes';`;
const resGo = replaceWithEol(indexHtml, oldGoRouteCheck, newGoRouteCheck, indexEol);
if (resGo) {
indexHtml = resGo;
console.log('✓ index.html : Routeur SPA adapté pour les ancres spa-gws-*.');
} else {
console.log('ℹ Routeur SPA déjà à jour ou déjà patché.');
}
// B. Click delegation pour liens d'ancres internes
const oldClickDelegation = `document.addEventListener('click',function(e){
var a=e.target.closest('a[data-spa]'); if(!a) return;
e.preventDefault(); location.hash=a.getAttribute('data-spa');
});`;
const newClickDelegation = `document.addEventListener('click',function(e){
var aSpa=e.target.closest('a[data-spa]');
if(aSpa){
e.preventDefault();
location.hash=aSpa.getAttribute('data-spa');
return;
}
var anchor=e.target.closest('a[href^="#"]');
if(anchor){
var href=anchor.getAttribute('href');
if(href && href.length > 1){
var targetId=href.substring(1);
if(targetId && !ROUTES.includes(targetId) && !LEGAL_TABS.hasOwnProperty(targetId)){
var targetEl=document.getElementById(targetId);
if(targetEl){
e.preventDefault();
targetEl.scrollIntoView({behavior:'smooth'});
}
}
}
}
});`;
const resClick = replaceWithEol(indexHtml, oldClickDelegation, newClickDelegation, indexEol);
if (resClick) {
indexHtml = resClick;
console.log('✓ index.html : Gestionnaire de clics adapté pour les ancres internes.');
} else {
console.log('ℹ Gestionnaire de clics déjà à jour ou déjà patché.');
}
fs.writeFileSync(INDEX_HTML_PATH, indexHtml, 'utf8');
// =========================================================================
// 3. MISE À JOUR DE sitemap.xml (SEO strict sans fragments d'URL)
// =========================================================================
const SITEMAP_PATH = path.join(SITE_DIR, 'sitemap.xml');
const cleanSitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://gastinel.me/</loc>
<lastmod>2026-09-23</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
<image:image>
<image:loc>https://gastinel.me/assets/img/dji-fly-20250919-194610-0004-1758304172909-photo.webp</image:loc>
<image:title>Horizon flamboyant au crépuscule dans le massif du Vercors</image:title>
<image:caption>Prise de vue aérienne au drone par Théo Gastinel</image:caption>
</image:image>
</url>
<url>
<loc>https://gastinel.me/gws/</loc>
<lastmod>2026-09-23</lastmod>
<changefreq>weekly</changefreq>
<priority>0.95</priority>
<image:image>
<image:loc>https://gastinel.me/assets/apps/gastinel-weather-studio/studio.webp</image:loc>
<image:title>Gastinel Weather Studio — Station logicielle d'analyse microclimatique</image:title>
<image:caption>Interface de comparaison multi-séries thermiques et TAF du Vercors</image:caption>
</image:image>
</url>
</urlset>
`;
fs.writeFileSync(SITEMAP_PATH, cleanSitemap, 'utf8');
console.log('✓ sitemap.xml : Nettoyé selon les standards stricts Google/Bing (URLs canoniques sans fragments).');
// =========================================================================
// 4. SYNCHRONISATION VERS Actual_Website
// =========================================================================
if (fs.existsSync(ACTUAL_DIR)) {
console.log(`[SYNCHRO] Synchronisation vers ${ACTUAL_DIR}...`);
fs.writeFileSync(path.join(ACTUAL_DIR, 'index.html'), indexHtml, 'utf8');
const actualGwsDir = path.join(ACTUAL_DIR, 'gws');
if (!fs.existsSync(actualGwsDir)) fs.mkdirSync(actualGwsDir, { recursive: true });
fs.writeFileSync(path.join(actualGwsDir, 'index.html'), gwsHtml, 'utf8');
// Copie sitemap & llms
fs.writeFileSync(path.join(ACTUAL_DIR, 'sitemap.xml'), cleanSitemap, 'utf8');
const llmsContent = fs.readFileSync(path.join(SITE_DIR, 'llms.txt'), 'utf8');
fs.writeFileSync(path.join(ACTUAL_DIR, 'llms.txt'), llmsContent, 'utf8');
console.log('✓ Actual_Website synchronisé avec succès.');
}
// =========================================================================
// 5. RECOMPRESSION BROTLI 11 & GZIP 9
// =========================================================================
console.log('[COMPRESSION] Lancement de tools/precompress.js...');
require('./precompress.js');
console.log('🎉 TOUTES LES ÉTAPES ONT ÉTÉ EXÉCUTÉES AVEC SUCCÈS !');