初始化

This commit is contained in:
leiking
2026-06-29 10:54:33 +08:00
parent 761cee968e
commit 4983006317
156 changed files with 25687 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
const fs = require('fs')
const path = require('path')
const vendorPath = path.join(__dirname, '..', 'unpackage', 'dist', 'dev', 'mp-weixin', 'common', 'vendor.js')
function patchMpWeixinVendor() {
if (!fs.existsSync(vendorPath)) {
return { ok: false, patched: false, reason: 'vendor.js not found' }
}
const s = fs.readFileSync(vendorPath, 'utf8')
const from = 'this.$vm.$mp.query = query; // 兼容 mpvue'
const toLegacy = 'if (this.$vm) {\\n if (!this.$vm.$mp) this.$vm.$mp = {};\\n this.$vm.$mp.query = query;\\n }'
const to = 'if (this.$vm) { if (!this.$vm.$mp) this.$vm.$mp = {}; this.$vm.$mp.query = query; }'
if (s.includes(to)) {
return { ok: true, patched: false, reason: 'already patched' }
}
if (s.includes(toLegacy)) {
fs.writeFileSync(vendorPath, s.replace(toLegacy, to), 'utf8')
return { ok: true, patched: true }
}
if (!s.includes(from)) {
return { ok: false, patched: false, reason: 'target snippet not found' }
}
fs.writeFileSync(vendorPath, s.replace(from, to), 'utf8')
return { ok: true, patched: true }
}
module.exports = patchMpWeixinVendor
if (require.main === module) {
patchMpWeixinVendor()
}