soyoo-cocos/cicdScript.js

81 lines
2.9 KiB
JavaScript
Raw Normal View History

2025-01-13 17:28:49 +08:00
import * as fs from 'fs'
import * as path from 'path'
import zipChannel from './zipChannelScript.js'
2025-01-13 19:23:26 +08:00
import htmlChannel from './htmlChannelScript.js'
2025-01-13 17:28:49 +08:00
import { fileURLToPath } from 'url'
2025-01-13 19:23:26 +08:00
import { removeDist, createDist } from './common/utils.js'
2025-01-13 16:18:28 +08:00
2025-01-13 17:28:49 +08:00
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
2025-01-13 16:18:28 +08:00
2025-01-13 19:23:26 +08:00
// 脚本执行之前的操作
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()
2025-01-13 17:14:39 +08:00
2025-01-13 16:18:28 +08:00
2025-01-13 17:14:39 +08:00
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')
2025-01-13 16:18:28 +08:00
}
2025-01-13 17:14:39 +08:00
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');
});
2025-01-13 16:18:28 +08:00
}
2025-01-13 17:28:49 +08:00
async function startScript() {
2025-01-13 17:14:39 +08:00
removeDist()
replaceCss()
replaceAppStoreUrl()
2025-01-13 17:28:49 +08:00
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))
2025-01-13 17:14:39 +08:00
console.log('脚本执行完毕')
}
startScript()