微信端添加版本号;

修补信息泄露漏洞;
This commit is contained in:
2025-12-16 12:54:05 +08:00
parent ae10b928ba
commit 783364b695
9 changed files with 121 additions and 2629 deletions
+90 -20
View File
@@ -4,42 +4,88 @@ const path = require('path');
function changeVersion() {
// 直接读取.env文件中的版本号
const envPath = path.join(__dirname, '.env');
let version = '1.0.0'; // 默认版本号
let currentVersion = '1.0.0'; // 默认版本号
if (fs.existsSync(envPath)) {
const fileContent = fs.readFileSync(envPath, 'utf-8');
const versionMatch = fileContent.match(/VITE_APP_VERSION\s*=\s*([^\r\n]+)/);
if (versionMatch && versionMatch[1]) {
version = versionMatch[1].trim();
currentVersion = versionMatch[1].trim();
}
}
// 解析版本号
const versionParts = currentVersion.split('.');
if (versionParts.length < 3) {
throw new Error('Invalid version format');
}
// 获取当前环境
const env = process.env.NODE_ENV || 'development';
let newVersion;
if (version) {
// 将版本号按点号分割
const parts = version.split('.');
const lastPart = parts[parts.length - 1];
const lastPart = versionParts[versionParts.length - 1];
const today = new Date().toISOString().slice(0, 10).replace(/-/g, ''); // YYYYMMDD 格式 (8位)
// 查最后一部分中的数字
const numberMatch = lastPart.match(/(\d+)([^\d]*)$/);
if (numberMatch) {
// 递增数字部分
const number = parseInt(numberMatch[1]) + 1;
const suffix = numberMatch[2] || ''; // 非数字后缀
// 查最后一组是否以8位日期开头 (支持各种分隔符,如 20250906-01 或 20250906_01)
const dateMatch = lastPart.match(/^(\d{8})[^\d]?(\d*)$/);
// 替换最后一部分中的数字
parts[parts.length - 1] = lastPart.replace(/(\d+)([^\d]*)$/, number + suffix);
if (dateMatch) {
// 最后一组以8位日期开头
const currentDatePart = dateMatch[1];
const sequencePart = dateMatch[2];
if (currentDatePart === today) {
// 日期相同,根据环境递增序号
const currentSequence = sequencePart ? parseInt(sequencePart) : 0;
let newSequence;
if (env === 'production') {
// 生产环境:递增到下一个十位整数
newSequence = Math.ceil((currentSequence + 1) / 10) * 10;
} else if (env === 'test') {
// 测试环境:递增到下一个十位整数,但跳过二十及其倍数
newSequence = getNextTestSequence(currentSequence);
} else {
// 开发环境:递增但避开十位整数
newSequence = getNextDevSequence(currentSequence);
}
// 保持三位数格式,不足三位前面补0
const formattedSequence = newSequence.toString().padStart(2, '0');
versionParts[versionParts.length - 1] = today + '-' + formattedSequence;
} else {
// 如果最后一部分没有数字,则添加.1
parts.push('1');
// 日期不同,重置序号
let resetSequence;
if (env === 'production' || env === 'prod') {
resetSequence = '20';
} else if (env === 'test') {
resetSequence = '10';
} else {
resetSequence = '01';
}
versionParts[versionParts.length - 1] = today + '-' + resetSequence;
}
newVersion = parts.join('.');
} else {
// 如果没有找到版本号,使用默认值
newVersion = '1.0.1';
// 最后一组不是日期格式,检查是否为纯数字
if (/^\d+$/.test(lastPart)) {
// 是纯数字,按照原来的方式递增
versionParts[versionParts.length - 1] = parseInt(lastPart) + 1;
} else {
// 不是纯数字,添加新的日期序号
let initialSequence;
if (env === 'production' || env === 'prod') {
initialSequence = '20';
} else if (env === 'test') {
initialSequence = '10';
} else {
initialSequence = '01';
}
versionParts.push(today + '-' + initialSequence);
}
}
newVersion = versionParts.join('.');
// 修改版本号
if (fs.existsSync(envPath)) {
const file = fs.readFileSync(envPath, 'utf-8');
@@ -57,4 +103,28 @@ function changeVersion() {
return newVersion;
}
// 获取下一个测试环境序号(十位整数但跳过百位整数)
function getNextTestSequence(current) {
let next = Math.ceil((current + 1) / 10) * 10;
// 跳过百位整数
while (next % 20 === 0) {
next += 10;
}
return next;
}
// 获取下一个开发环境序号(避开十位整数)
function getNextDevSequence(current) {
let next = current + 1;
// 跳过十位整数和百位整数
while (next % 10 === 0) {
next++;
}
return next;
}
module.exports = changeVersion;