#!/usr/bin/env node function parseVersion(value) { const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/i.exec(String(value ?? '').trim()) return match ? [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)] : null } function nextVersion(value) { const version = parseVersion(value) if (!version) throw new Error(`版本号格式无效: ${value}`) version[2] += 1 return version.join('.') } if (process.argv.includes('--self-test')) { if (nextVersion('1.0.9') !== '1.0.10' || nextVersion('v2.3') !== '2.3.1') { throw new Error('wechat-next-version self-test failed') } console.log('wechat-next-version self-test passed') } else { const current = process.argv[2] console.log(current ? nextVersion(current) : (process.env.WECHAT_VERSION_FALLBACK || '1.0.2')) }