77 lines
2.8 KiB
JavaScript
77 lines
2.8 KiB
JavaScript
const fs = require('fs')
|
||
const path = require('path')
|
||
|
||
|
||
// 脚本执行之前的操作
|
||
var iosUrl = "https://apps.apple.com/kr/app/id6467117398"
|
||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
||
|
||
// 版本一(英文版)
|
||
// 安卓:https://play.google.com/store/apps/details?id=com.mxdzzus.google
|
||
// iOS:https://apps.apple.com/app/legend-of-mushroom/id6475333787
|
||
|
||
// 版本二(韩语)
|
||
// 安卓:https://play.google.com/store/apps/details?id=com.mxdzzkr.google
|
||
// iOS:https://apps.apple.com/kr/app/id6467117398
|
||
|
||
|
||
function removeDist() {
|
||
const isExists = fs.existsSync(path.join(__dirname, 'dist'))
|
||
if (isExists) {
|
||
fs.rmdirSync(path.join(__dirname, 'dist'), { recursive: true })
|
||
}
|
||
if (!isExists) {
|
||
fs.mkdirSync(path.join(__dirname, 'dist'))
|
||
}
|
||
}
|
||
|
||
|
||
function replaceAppStoreUrl() {
|
||
// 1. 替换mraid_support.js文件中的iosUrl和androidUrl
|
||
var mraid_support_js = fs.readFileSync(path.join(__dirname, 'networks', 'mraid_support.js'), 'utf8')
|
||
mraid_support_js = mraid_support_js.replace(/var iosurl\s*=\s*".*"/g, `var iosUrl = "${iosUrl}"`)
|
||
mraid_support_js = mraid_support_js.replace(/var androidUrl\s*=\s*".*"/g, `var androidUrl = "${androidUrl}"`);
|
||
fs.writeFileSync(path.join(__dirname, 'networks', 'mraid_support.js'), mraid_support_js, 'utf8')
|
||
}
|
||
|
||
function replaceCss() {
|
||
// 获取 web-mobile 目录中的 splash 开头的 png 文件
|
||
const splashFile = fs.readdirSync('web-mobile').find(file => file.startsWith('splash') && file.endsWith('.png'));
|
||
if (!splashFile) return;
|
||
|
||
// 读取并转换为 base64
|
||
const splashFilePath = path.join('web-mobile', splashFile);
|
||
const splashBase64 = fs.readFileSync(splashFilePath, 'base64');
|
||
const splashBase64Url = `url(data:image/png;base64,${splashBase64})`;
|
||
|
||
// 使用正则表达式查找带有哈希值的 CSS 文件
|
||
const cssFiles = fs.readdirSync('web-mobile').filter(file => {
|
||
return /style-(mobile|desktop)\.[a-f0-9]+\.css$/.test(file)
|
||
});
|
||
cssFiles.forEach(cssFile => {
|
||
const cssFilePath = path.join('web-mobile', cssFile);
|
||
let cssContent = fs.readFileSync(cssFilePath, 'utf8');
|
||
|
||
const splashRegex = /url\(\.\/splash\.\w+\.png\)/g;
|
||
if (splashRegex.test(cssContent)) {
|
||
cssContent = cssContent.replace(splashRegex, splashBase64Url);
|
||
}
|
||
|
||
if (cssFile.includes('desktop') && !cssContent.includes('orientation: landscape')) {
|
||
const mediaRule = '\n@media (orientation: landscape) {#splash {background-size: 15% !important;}}';
|
||
cssContent += mediaRule;
|
||
}
|
||
|
||
fs.writeFileSync(cssFilePath, cssContent, 'utf8');
|
||
});
|
||
}
|
||
|
||
|
||
function startScript() {
|
||
removeDist()
|
||
replaceCss()
|
||
replaceAppStoreUrl()
|
||
console.log('脚本执行完毕')
|
||
}
|
||
|
||
startScript() |