const fs = require('fs'); const path = require('path'); // 生成版本号(格式:YYYYMMDD-HHmmss) function generateVersion() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); return `${year}${month}${day}-${hours}${minutes}${seconds}`; } // 更新 index.html 中的版本号 function updateVersion() { const htmlPath = path.join(__dirname, '../index.html'); if (!fs.existsSync(htmlPath)) { console.error('❌ index.html 文件不存在:', htmlPath); process.exit(1); } let html = fs.readFileSync(htmlPath, 'utf8'); const version = generateVersion(); // 替换版本号 if (html.includes('/, `` ); } else { // 如果不存在版本号 meta 标签,在 charset 后面添加 html = html.replace( //, `\n \n ` ); } fs.writeFileSync(htmlPath, html, 'utf8'); console.log(`✅ 版本号已更新为: ${version}`); } updateVersion();