Files
wechat_wc/scripts/patch-skyline-share-element.js
T
2026-08-05 10:13:52 +08:00

24 lines
1.4 KiB
JavaScript

const fs = require('fs')
const path = require('path')
// Taro's React custom tabBar does not emit its local WXSS. WeChat reads this
// file from the custom-tab-bar directory, so copy it after every build.
const tabBarStyleSource = path.join(process.cwd(), 'src', 'custom-tab-bar', 'index.wxss')
const tabBarStyleTarget = path.join(process.cwd(), 'dist', 'custom-tab-bar', 'index.wxss')
fs.copyFileSync(tabBarStyleSource, tabBarStyleTarget)
const templatePath = path.join(process.cwd(), 'dist', 'base.wxml')
const source = fs.readFileSync(templatePath, 'utf8')
const original = '<share-element key="{{i.p2}}" transform="{{xs.b(i.p3,false)}}" duration="{{xs.b(i.p0,300)}}" easing-function="{{xs.b(i.p1,\'ease-out\')}}" style="{{i.st}}" class="{{i.cl}}" bindtap="eh" id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">'
const replacement = '<share-element key="{{i.p2}}" transform="{{xs.b(i.p3,false)}}" duration="{{xs.b(i.p0,300)}}" easing-function="{{xs.b(i.p1,\'ease-out\')}}" transition-on-gesture shuttle-on-push="{{i.p0 === 301 ? \'from\' : \'to\'}}" rect-tween-type="linear" style="{{i.st}}" class="{{i.cl}}" bindtap="eh" id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">'
if (source.includes(replacement)) {
process.exit(0)
}
if (!source.includes(original)) {
throw new Error('Skyline share-element template was not found')
}
fs.writeFileSync(templatePath, source.replace(original, replacement), 'utf8')