Compare commits
No commits in common. "master" and "yityu-patch-1" have entirely different histories.
master
...
yityu-patc
96
README.md
96
README.md
|
@ -9,19 +9,15 @@ SoyooFacade.ReportLifeCycle(SoyooLifecyle.Complete)
|
|||
SoyooFacade.InstallGame()
|
||||
```
|
||||
|
||||
# zip文件渠道
|
||||
这些渠道的最终产物是一个zip包。
|
||||
zip文件的默认打包方式,是根据以下不同渠道操作后,将web-mobile文件打包成zip。
|
||||
|
||||
## 1. 渠道处理
|
||||
### facebook
|
||||
# zip
|
||||
## facebook
|
||||
把`networks/facebook.js`复制到web-mobile目录下。
|
||||
在w`web-mobile/index.html`的"</head>"的上一行添加代码
|
||||
```
|
||||
<script src="facebook.js" charset="utf-8"></script>
|
||||
```
|
||||
|
||||
### google
|
||||
## google
|
||||
把`networks/google.js`复制到web-mobile目录下。
|
||||
在w`web-mobile/index.html`的"</head>"的上一行添加代码
|
||||
```
|
||||
|
@ -29,100 +25,44 @@ zip文件的默认打包方式,是根据以下不同渠道操作后,将web-m
|
|||
<script src="google.js" charset="utf-8"></script>
|
||||
```
|
||||
|
||||
### tiktok
|
||||
## tiktok
|
||||
把`tiktok/tiktok.js`和`tiktok/config.json`复制到web-mobile目录下。
|
||||
在w`web-mobile/index.html`的"</head>"的上一行添加代码
|
||||
```
|
||||
<script src="tiktok.js" charset="utf-8"></script>
|
||||
```
|
||||
|
||||
在<body>里添加
|
||||
```
|
||||
<script src= "https://sf16-muse-va.ibytedtos.com/obj/union-fe-nc-i18n/playable/sdk/playable-sdk.js"></script>
|
||||
```
|
||||
|
||||
### 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最后加上
|
||||
`js
|
||||
<script src="mraid_support.js" charset="utf-8"></script>
|
||||
`
|
||||
|
||||
# 单HTML渠道
|
||||
## 1. 环境配置
|
||||
## 环境配置
|
||||
需要安装nodejs
|
||||
打开soyoo-cocos后,先执行`npm install`安装依赖
|
||||
|
||||
## 2.预处理html
|
||||
### 预处理html
|
||||
0. 把目标目录web-mobile复制到soyoo-cocos目录下。
|
||||
1. 删掉index.html里的js代码部分
|
||||
2. 在body最后加上
|
||||
`
|
||||
`<script src="loader-and-starter.js" charset="utf-8"></script>
|
||||
<script src="asset-map.js" charset="utf-8"></script>`
|
||||
|
||||
<script src="loader-and-starter.js" charset="utf-8"></script>
|
||||
<script src="asset-map.js" charset="utf-8"></script>
|
||||
|
||||
`
|
||||
|
||||
## 3.渠道处理
|
||||
###
|
||||
下面四个渠道是使用 mraid_support.js
|
||||
applovin
|
||||
unity
|
||||
appier
|
||||
ironsource (需要单独加入mraid.js)
|
||||
|
||||
|
||||
(zip) liftoff
|
||||
1. 把networks/mraid_support.js 复制到web-mobile下
|
||||
2. 编辑复制的mraid_support.js, 在前几行填入对应的iosUrl和androidUrl
|
||||
## 渠道处理
|
||||
### applovin
|
||||
1. 把networks/applovin.js 复制到web-mobile下
|
||||
2. 编辑复制的applovin.js, 在前几行填入对应的iosUrl和androidUrl
|
||||
3. 编辑index.html,在body最后加上
|
||||
`js
|
||||
<script src="mraid_support.js" charset="utf-8"></script>
|
||||
`
|
||||
`<script src="applovin.js" charset="utf-8"></script>`
|
||||
|
||||
### ironsource
|
||||
1. 把networks/mraid_support.js 复制到web-mobile下
|
||||
2. 编辑复制的mraid_support.js, 在前几行填入对应的iosUrl和androidUrl
|
||||
3. 编辑index.html,在body最后加上
|
||||
`js
|
||||
<script src="mraid.js"></script>
|
||||
<script src="mraid_support.js" charset="utf-8"></script>
|
||||
`
|
||||
|
||||
### mintegral
|
||||
### applovin
|
||||
1. 把networks/mintegral.js 复制到web-mobile下
|
||||
2. 编辑index.html,在body最后加上
|
||||
`
|
||||
<script src="mintegral.js" charset="utf-8"></script>
|
||||
`
|
||||
`<script src="mintegral.js" charset="utf-8"></script>`
|
||||
|
||||
### moloco
|
||||
1. 把`networks/moloco.js`复制到web-mobile目录下。
|
||||
2. 编辑index.html,在body最后加上
|
||||
```js
|
||||
```
|
||||
<script src="moloco.js" charset="utf-8"></script>
|
||||
```
|
||||
|
||||
|
||||
## 4.打包
|
||||
## 打包
|
||||
执行命令 `node single-html/build.js`
|
||||
生成目标文件 `dist/index.html`即为目标文件
|
||||
|
||||
|
||||
```css
|
||||
@media (orientation: landscape) {#splash {background-size: 15% !important;}}
|
||||
|
||||
```
|
||||
|
||||
```js
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.15.1/vconsole.min.js"></script>
|
||||
<script>new VConsole()</script>
|
||||
```
|
||||
生成目标文件 `dist/index.html`即为目标文件
|
|
@ -1,118 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const do_task = require("./single-html/build");
|
||||
|
||||
const outputPrefix = '';
|
||||
const htmlChannel = ['applovin', 'unity', 'appier', 'ironsource', 'mintegral', 'moloco'];
|
||||
|
||||
// 创建 dist 目录
|
||||
if (!fs.existsSync('dist')) {
|
||||
fs.mkdirSync('dist');
|
||||
}
|
||||
|
||||
// 处理 HTML 渠道
|
||||
async function processHtmlChannels() {
|
||||
for (const channelName of htmlChannel) {
|
||||
// 删除所有可能存在的旧文件
|
||||
const filesToDelete = ['mraid_support.js', 'mraid.js', 'mintegral.js', 'moloco.js'];
|
||||
filesToDelete.forEach(file => {
|
||||
const filePath = path.join('web-mobile', file);
|
||||
if (fs.existsSync(filePath)) {
|
||||
fs.unlinkSync(filePath);
|
||||
console.log(`已删除: ${filePath}`);
|
||||
}
|
||||
});
|
||||
|
||||
// 从 networks 找到复制到 web-mobile 中
|
||||
const mraidSupportFile = path.join('networks', 'mraid_support.js');
|
||||
const mraidDestinationFile = path.join('web-mobile', 'mraid_support.js');
|
||||
|
||||
if (['applovin', 'unity', 'appier', 'ironsource'].includes(channelName)) {
|
||||
if (fs.existsSync(mraidSupportFile)) {
|
||||
fs.copyFileSync(mraidSupportFile, mraidDestinationFile);
|
||||
console.log(`已复制: ${mraidSupportFile} 到 ${mraidDestinationFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (['mintegral', 'moloco'].includes(channelName)) {
|
||||
const fileName = `${channelName}.js`;
|
||||
const sourceFile = path.join('networks', fileName);
|
||||
const destFile = path.join('web-mobile', fileName);
|
||||
if (fs.existsSync(sourceFile)) {
|
||||
fs.copyFileSync(sourceFile, destFile);
|
||||
console.log(`已复制: ${sourceFile} 到 ${destFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
const htmlFilePath = path.join('web-mobile', 'index.html');
|
||||
let htmlContent = fs.readFileSync(htmlFilePath, 'utf-8');
|
||||
|
||||
// 移除非当前渠道包的 <script> 标签
|
||||
htmlChannel.forEach(channel => {
|
||||
if (channel !== channelName) {
|
||||
const scriptRegex = new RegExp(`<script src="${channel}.js" charset="utf-8"></script>\\n`, 'g');
|
||||
htmlContent = htmlContent.replace(scriptRegex, '');
|
||||
}
|
||||
});
|
||||
|
||||
// 移除 mraid_support.js 和 mraid.js 的 <script> 标签
|
||||
htmlContent = htmlContent.replace(/<script src="mraid_support.js" charset="utf-8"><\/script>\n/g, '');
|
||||
htmlContent = htmlContent.replace(/<script src="mraid.js"><\/script>\n/g, '');
|
||||
|
||||
// 检查并插入新的渠道 script 标签
|
||||
let channelScriptTag;
|
||||
if (['applovin', 'unity', 'appier', 'ironsource'].includes(channelName)) {
|
||||
channelScriptTag = ` <script src="mraid_support.js" charset="utf-8"></script>\n`;
|
||||
} else {
|
||||
channelScriptTag = ` <script src="${channelName}.js" charset="utf-8"></script>\n`;
|
||||
}
|
||||
|
||||
if (!htmlContent.includes(channelScriptTag)) {
|
||||
htmlContent = htmlContent.replace(/<\/head>/, `${channelScriptTag}</head>`);
|
||||
}
|
||||
|
||||
// 替换包含 window.vConsole = new VConsole 的 <script> 标签
|
||||
const vConsoleScriptRegex = /<script type="text\/javascript">[\s\S]*?window\.vConsole = new VConsole\(\);[\s\S]*?<\/script>/;
|
||||
// @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 中
|
||||
const loaderScriptTag = `<script src="loader-and-starter.js" charset="utf-8"></script>\n`;
|
||||
const assetMapScriptTag = `<script src="asset-map.js" charset="utf-8"></script>\n`;
|
||||
const bodyScriptTags = `${cocosScriptTag}${loaderScriptTag}${assetMapScriptTag}`;
|
||||
|
||||
if (!htmlContent.includes(loaderScriptTag) && !htmlContent.includes(assetMapScriptTag)) {
|
||||
htmlContent = htmlContent.replace(cocosScriptTag, bodyScriptTags);
|
||||
}
|
||||
|
||||
// 移除单渠道的 SDK script 标签
|
||||
const sdkScriptTag = `<script src="https://sf16-muse-va.ibytedtos.com/obj/union-fe-nc-i18n/playable/sdk/playable-sdk.js"></script>\n`;
|
||||
htmlContent = htmlContent.replace(sdkScriptTag, '');
|
||||
|
||||
fs.writeFileSync(htmlFilePath, htmlContent);
|
||||
console.log(`已将 ${channelName}.js 和相关 script 引入到 index.html 中`);
|
||||
|
||||
// 调用 do_task 方法,将 web-mobile 下的所有包打包成一个 HTML
|
||||
do_task();
|
||||
|
||||
// 如果是 ironsource 渠道,将 <script src="mraid.js"></script> 插入到 body 标签之前
|
||||
if (channelName === 'ironsource') {
|
||||
htmlContent = fs.readFileSync(path.join('dist', 'index.html'), 'utf-8');
|
||||
htmlContent = htmlContent.replace(/<\/body>/, `<script src="mraid.js"></script></body>`);
|
||||
fs.writeFileSync(path.join('dist', 'index.html'), htmlContent);
|
||||
console.log(`已将 <script src="mraid.js"></script> 写入到 ironsource.html 的 body 标签之前`);
|
||||
}
|
||||
|
||||
// 重命名生成的 index.html 为对应的渠道名称
|
||||
const distIndexPath = path.join('dist', 'index.html');
|
||||
const channelIndexPath = path.join('dist', `${outputPrefix}${channelName}.html`);
|
||||
if (fs.existsSync(distIndexPath)) {
|
||||
fs.renameSync(distIndexPath, channelIndexPath);
|
||||
console.log(`已重命名 index.html 为 ${channelName}.html`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processHtmlChannels();
|
|
@ -1,6 +1,6 @@
|
|||
// 填入对应的商店地址
|
||||
var iosUrl = "https://apps.apple.com/app/legend-of-mushroom/id6475333787"
|
||||
var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
||||
var iosUrl = ""
|
||||
var androidUrl = ""
|
||||
|
||||
|
||||
class SoyooLifecyle {
|
File diff suppressed because it is too large
Load Diff
|
@ -1,16 +1,12 @@
|
|||
{
|
||||
"scripts": {
|
||||
"build": "node single-html/build.js",
|
||||
"build:zip": "node zipChannelScript.js",
|
||||
"build:h5": "node htmlChannelScript.js",
|
||||
"build:allChannels": "node scriptBefore.js && npm run build:zip && npm run build:h5"
|
||||
"build": "node single-html/build.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"clean-css": "^5.3.3",
|
||||
"uglify-js": "^3.19.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"archiver": "^7.0.1",
|
||||
"brotli": "^1.3.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
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()
|
|
@ -129,5 +129,4 @@ function do_task() {
|
|||
console.timeEnd("输出html文件")
|
||||
}
|
||||
|
||||
// 导出
|
||||
module.exports = do_task
|
||||
do_task()
|
|
@ -1,122 +0,0 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const archiver = require("archiver");
|
||||
|
||||
const zipChannel = ['facebook', 'google', 'tiktok', 'vungle', 'liftoff'];
|
||||
|
||||
const outputPrefix = '';
|
||||
|
||||
// 创建 dist 目录
|
||||
if (!fs.existsSync('dist')) {
|
||||
fs.mkdirSync('dist');
|
||||
}
|
||||
|
||||
// 1. 将js复制到web-mobile中
|
||||
async function processChannels() {
|
||||
for (const channelName of zipChannel) {
|
||||
// 遍历 networks 目录下的所有js文件,获取 文件名 然后删除 web-mobile 目录下的同名文件
|
||||
const files = fs.readdirSync(path.join('networks'));
|
||||
for (const file of files) {
|
||||
if (file.endsWith('.js')) {
|
||||
const destinationFile = path.join('web-mobile', file);
|
||||
if (fs.existsSync(destinationFile)) {
|
||||
fs.unlinkSync(destinationFile);
|
||||
console.log(`已删除: ${destinationFile}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// tiktok 处理
|
||||
const tiktokConfig = path.join('web-mobile', `config.json`);
|
||||
if (fs.existsSync(tiktokConfig)) {
|
||||
fs.unlinkSync(tiktokConfig);
|
||||
}
|
||||
const tiktokJs = path.join('web-mobile', `tiktok.js`);
|
||||
if (fs.existsSync(tiktokJs)) {
|
||||
fs.unlinkSync(tiktokJs);
|
||||
}
|
||||
|
||||
// 从 networks 找到复制到 web-mobile 中
|
||||
const sourceFile = path.join('networks', `${channelName}.js`);
|
||||
const destinationFile = path.join('web-mobile', `${channelName}.js`);
|
||||
|
||||
if (channelName === 'tiktok') {
|
||||
fs.copyFileSync(path.join('tiktok/config.json'), path.join('web-mobile', `config.json`));
|
||||
fs.copyFileSync(path.join('tiktok/tiktok.js'), path.join('web-mobile', `tiktok.js`));
|
||||
} else if (channelName === 'vungle' || channelName === 'liftoff') {
|
||||
// 对于 vungle 和 liftoff,使用 mraid_support.js
|
||||
const mraidSupportFile = path.join('networks', 'mraid_support.js');
|
||||
const mraidDestinationFile = path.join('web-mobile', 'mraid_support.js');
|
||||
if (fs.existsSync(mraidSupportFile)) {
|
||||
fs.copyFileSync(mraidSupportFile, mraidDestinationFile);
|
||||
console.log(`已复制: ${mraidSupportFile} 到 ${mraidDestinationFile}`);
|
||||
}
|
||||
} else {
|
||||
if (fs.existsSync(sourceFile)) {
|
||||
fs.copyFileSync(sourceFile, destinationFile);
|
||||
console.log(`已复制: ${sourceFile} 到 ${destinationFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
const htmlFilePath = path.join('web-mobile', 'index.html');
|
||||
let htmlContent = fs.readFileSync(htmlFilePath, 'utf-8');
|
||||
|
||||
// 移除其他渠道包的 <script> 标签
|
||||
zipChannel.forEach(channel => {
|
||||
const scriptRegex = new RegExp(`<script src="${channel}.js" charset="utf-8"></script>\\n`, 'g');
|
||||
htmlContent = htmlContent.replace(scriptRegex, '');
|
||||
});
|
||||
|
||||
// 移除所有渠道的 <meta> 标签
|
||||
const metaTagRegex = /<meta name="ad.size" content="width=480,height=320">\n/g;
|
||||
htmlContent = htmlContent.replace(metaTagRegex, '');
|
||||
|
||||
// 检查并插入新的渠道 script 标签
|
||||
let channelScriptTag;
|
||||
if (channelName === 'vungle' || channelName === 'liftoff') {
|
||||
channelScriptTag = ` <script src="mraid_support.js" charset="utf-8"></script>\n`;
|
||||
} else {
|
||||
channelScriptTag = ` <script src="${channelName}.js" charset="utf-8"></script>\n`;
|
||||
}
|
||||
|
||||
if (!htmlContent.includes(channelScriptTag)) {
|
||||
htmlContent = htmlContent.replace(/<\/head>/, `${channelScriptTag}</head>`);
|
||||
}
|
||||
|
||||
// 如果是 google 渠道,添加 <meta> 标签
|
||||
if (channelName === 'google') {
|
||||
const metaTag = `<meta name="ad.size" content="width=480,height=320">\n`;
|
||||
if (!htmlContent.includes(metaTag)) {
|
||||
htmlContent = htmlContent.replace(/<\/head>/, `${metaTag}</head>`);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查并插入新的 SDK script 标签到 <body> 之前
|
||||
const sdkScriptTag = `<script src="https://sf16-muse-va.ibytedtos.com/obj/union-fe-nc-i18n/playable/sdk/playable-sdk.js"></script>\n`;
|
||||
if (!htmlContent.includes(sdkScriptTag)) {
|
||||
htmlContent = htmlContent.replace(/<\/body>/, `${sdkScriptTag}</body>`);
|
||||
}
|
||||
|
||||
fs.writeFileSync(htmlFilePath, htmlContent);
|
||||
console.log(`已将 ${channelName}.js 和 SDK script 引入到 index.html 中`);
|
||||
|
||||
// 打包 web-mobile 目录为 zip 文件
|
||||
const output = fs.createWriteStream(path.join('dist', `${outputPrefix}${channelName}.zip`));
|
||||
const archive = archiver('zip', {
|
||||
zlib: { level: 9 } // 设置压缩级别
|
||||
});
|
||||
|
||||
output.on('close', function () {
|
||||
console.log(`已创建 ${channelName}.zip,大小为 ${archive.pointer()} 字节`);
|
||||
});
|
||||
|
||||
archive.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
|
||||
archive.pipe(output);
|
||||
archive.directory('web-mobile/', false);
|
||||
await archive.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
processChannels();
|
Loading…
Reference in New Issue