add cicd replace logo
parent
5695429920
commit
b0c871484e
|
@ -1,6 +1,6 @@
|
|||
// 填入对应的商店地址
|
||||
var iosUrl = "https://apps.apple.com/kr/app/id6467117398"
|
||||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzkr.google"
|
||||
var iosUrl = "https://apps.apple.com/app/legend-of-mushroom/id6475333787"
|
||||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
||||
|
||||
|
||||
class SoyooLifecyle {
|
||||
|
|
|
@ -3,25 +3,67 @@ const path = require('path')
|
|||
|
||||
|
||||
// 脚本执行之前的操作
|
||||
var iosUrl = "https://apps.apple.com/kr/app/id6467117398"
|
||||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzkr.google"
|
||||
var iosUrl = "https://apps.apple.com/app/legend-of-mushroom/id6475333787"
|
||||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
||||
|
||||
|
||||
// 清空dist目录
|
||||
|
||||
const isExists = fs.existsSync(path.join(__dirname, 'dist'))
|
||||
if (isExists) {
|
||||
function removeDist() {
|
||||
const isExists = fs.existsSync(path.join(__dirname, 'dist'))
|
||||
if (isExists) {
|
||||
fs.rmdirSync(path.join(__dirname, 'dist'), { recursive: true })
|
||||
}
|
||||
if (!isExists) {
|
||||
}
|
||||
if (!isExists) {
|
||||
fs.mkdirSync(path.join(__dirname, 'dist'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 1. 替换mraid_support.js文件中的iosUrl和androidUrl
|
||||
var mraid_support_js = fs.readFileSync(path.join(__dirname, 'networks', 'mraid_support.js'), 'utf8')
|
||||
// 匹配var iosUrl = "", var iosurl "" 结尾的
|
||||
mraid_support_js = mraid_support_js.replace(/var iosUrl = ".*"/g, `var iosUrl = "${iosUrl}"`)
|
||||
// 匹配var androidUrl = "", var androidurl "" 结尾的
|
||||
mraid_support_js = mraid_support_js.replace(/var androidUrl = ".*"/g, `var androidUrl = "${androidUrl}"`)
|
||||
fs.writeFileSync(path.join(__dirname, 'networks', 'mraid_support.js'), mraid_support_js, 'utf8')
|
||||
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()
|
Loading…
Reference in New Issue