Compare commits
3 Commits
script-cic
...
master
Author | SHA1 | Date |
---|---|---|
guofei | 5415e2c007 | |
guofei | b0c871484e | |
guofei | 5695429920 |
12
README.md
12
README.md
|
@ -44,7 +44,10 @@ zip文件的默认打包方式,是根据以下不同渠道操作后,将web-m
|
|||
### 2. 打包
|
||||
将web-mobile文件内容压缩成zip包。注意,zip包的第一层级需要包含index.html。
|
||||
|
||||
|
||||
## vungle
|
||||
|
||||
vungle 和 liftoff 的渠道包需要使用mraid_support.js
|
||||
1. 把networks/mraid_support.js 复制到web-mobile下
|
||||
2. 编辑复制的mraid_support.js, 在前几行填入对应的iosUrl和androidUrl
|
||||
3. 编辑index.html,在body最后加上
|
||||
|
@ -69,10 +72,15 @@ zip文件的默认打包方式,是根据以下不同渠道操作后,将web-m
|
|||
`
|
||||
|
||||
## 3.渠道处理
|
||||
### applovin
|
||||
###
|
||||
下面四个渠道是使用 mraid_support.js
|
||||
applovin
|
||||
unity
|
||||
(zip) liftoff
|
||||
appier
|
||||
ironsource (需要单独加入mraid.js)
|
||||
|
||||
|
||||
(zip) liftoff
|
||||
1. 把networks/mraid_support.js 复制到web-mobile下
|
||||
2. 编辑复制的mraid_support.js, 在前几行填入对应的iosUrl和androidUrl
|
||||
3. 编辑index.html,在body最后加上
|
||||
|
|
|
@ -5,11 +5,6 @@ const do_task = require("./single-html/build");
|
|||
const outputPrefix = '';
|
||||
const htmlChannel = ['applovin', 'unity', 'appier', 'ironsource', 'mintegral', 'moloco'];
|
||||
|
||||
// 延时函数
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
// 创建 dist 目录
|
||||
if (!fs.existsSync('dist')) {
|
||||
fs.mkdirSync('dist');
|
||||
|
@ -78,7 +73,9 @@ async function processHtmlChannels() {
|
|||
|
||||
// 替换包含 window.vConsole = new VConsole 的 <script> 标签
|
||||
const vConsoleScriptRegex = /<script type="text\/javascript">[\s\S]*?window\.vConsole = new VConsole\(\);[\s\S]*?<\/script>/;
|
||||
const cocosScriptTag = `<script src="cocos2d-js-min.ce58b.js" charset="utf-8"></script>\n`;
|
||||
// @TODO cocos的名称需要从web-mobile文件夹中获取找到
|
||||
const cocosFileName = fs.readdirSync('web-mobile').find(file => file.startsWith('cocos2d-js-min') && file.endsWith('.js'));
|
||||
const cocosScriptTag = `<script src="${cocosFileName}" charset="utf-8"></script>\n`;
|
||||
htmlContent = htmlContent.replace(vConsoleScriptRegex, cocosScriptTag);
|
||||
|
||||
// 额外引入 loader-and-starter.js 和 asset-map.js 到 body 中
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// 填入对应的商店地址
|
||||
var iosUrl = "https://play.google.com/store/apps/details?id=com.wwv.global"
|
||||
var androidUrl = "https://apps.apple.com/app/id6621220868"
|
||||
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,7 +3,7 @@
|
|||
"build": "node single-html/build.js",
|
||||
"build:zip": "node zipChannelScript.js",
|
||||
"build:h5": "node htmlChannelScript.js",
|
||||
"build:allChannels": "npm run build:zip && npm run build:h5"
|
||||
"build:allChannels": "node scriptBefore.js && npm run build:zip && npm run build:h5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"clean-css": "^5.3.3",
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
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()
|
|
@ -4,11 +4,6 @@ const archiver = require("archiver");
|
|||
|
||||
const zipChannel = ['facebook', 'google', 'tiktok', 'vungle', 'liftoff'];
|
||||
|
||||
// 延时函数
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
const outputPrefix = '';
|
||||
|
||||
// 创建 dist 目录
|
||||
|
@ -110,11 +105,11 @@ async function processChannels() {
|
|||
zlib: { level: 9 } // 设置压缩级别
|
||||
});
|
||||
|
||||
output.on('close', function() {
|
||||
output.on('close', function () {
|
||||
console.log(`已创建 ${channelName}.zip,大小为 ${archive.pointer()} 字节`);
|
||||
});
|
||||
|
||||
archive.on('error', function(err) {
|
||||
archive.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue