29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
// update-version.js — sincroniza version.txt → package.json + index.html
|
|
// Incrementa o PATCH automaticamente a cada deploy.
|
|
// Fonte de verdade: dental-server/version.txt
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const versionFile = path.join(__dirname, 'dental-server', 'version.txt');
|
|
const indexFile = path.join(__dirname, 'dental-server', 'public', 'index.html');
|
|
|
|
const current = fs.readFileSync(versionFile, 'utf8').trim();
|
|
const parts = current.split('.').map(Number);
|
|
parts[2]++; // bump PATCH
|
|
const next = parts.join('.');
|
|
|
|
// version.txt — fonte de verdade do número de versão
|
|
fs.writeFileSync(versionFile, next + '\n');
|
|
|
|
// index.html — substitui v{X.Y.Z} dentro do <span> da sidebar
|
|
// (package.json NÃO é alterado para preservar o cache de npm install no Docker)
|
|
let html = fs.readFileSync(indexFile, 'utf8');
|
|
html = html.replace(
|
|
/(RF Dental.*?<span[^>]*>)\s*v[\d.]+\s*(<\/span>)/s,
|
|
`$1v${next}$2`
|
|
);
|
|
fs.writeFileSync(indexFile, html);
|
|
|
|
console.log(`version: ${current} → ${next}`);
|