81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
import zipChannel from './zipChannelScript.js'
|
|
import htmlChannel from './htmlChannelScript.js'
|
|
import { fileURLToPath } from 'url'
|
|
import { removeDist, createDist } from './common/utils.js'
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
|
|
|
|
|
|
// 脚本执行之前的操作
|
|
var iosUrl = "https://apps.apple.com/app/legend-of-mushroom/id6475333787"
|
|
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
|
|
|
removeDist()
|
|
createDist()
|
|
|
|
|
|
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');
|
|
});
|
|
}
|
|
|
|
|
|
async function startScript() {
|
|
removeDist()
|
|
replaceCss()
|
|
replaceAppStoreUrl()
|
|
|
|
const options = {
|
|
// zip包
|
|
zipChannel: ['facebook', 'google', 'tiktok', 'vungle', 'liftoff'],
|
|
// html包
|
|
htmlChannel: ['applovin', 'unity', 'appier', 'ironsource', 'mintegral', 'moloco'],
|
|
outputPrefix: ''
|
|
}
|
|
|
|
await zipChannel(Object.assign(options))
|
|
await htmlChannel(Object.assign(options))
|
|
console.log('脚本执行完毕')
|
|
}
|
|
|
|
startScript() |