Compare commits
2 Commits
master
...
change-es6
Author | SHA1 | Date |
---|---|---|
guofei | da7cef9cda | |
guofei | e29ebfe7f9 |
|
@ -1,29 +1,22 @@
|
||||||
const fs = require('fs')
|
import * as fs from 'fs'
|
||||||
const path = require('path')
|
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/kr/app/id6467117398"
|
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 androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google"
|
||||||
|
|
||||||
// 版本一(英文版)
|
removeDist()
|
||||||
// 安卓:https://play.google.com/store/apps/details?id=com.mxdzzus.google
|
createDist()
|
||||||
// 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() {
|
function replaceAppStoreUrl() {
|
||||||
|
@ -67,10 +60,21 @@ function replaceCss() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function startScript() {
|
async function startScript() {
|
||||||
removeDist()
|
removeDist()
|
||||||
replaceCss()
|
replaceCss()
|
||||||
replaceAppStoreUrl()
|
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('脚本执行完毕')
|
console.log('脚本执行完毕')
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
|
const __dirname = path.dirname(__filename)
|
||||||
|
|
||||||
|
|
||||||
|
const dist = path.join(__dirname, '../', 'dist')
|
||||||
|
|
||||||
|
export function removeDist() {
|
||||||
|
const isExists = fs.existsSync(dist)
|
||||||
|
if (isExists) {
|
||||||
|
fs.rmdirSync(dist, { recursive: true })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createDist() {
|
||||||
|
const isExists = fs.existsSync(dist)
|
||||||
|
if (!isExists) {
|
||||||
|
fs.mkdirSync(dist)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,14 @@
|
||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
|
||||||
const do_task = require("./single-html/build");
|
|
||||||
|
|
||||||
const outputPrefix = '';
|
import * as fs from 'fs'
|
||||||
const htmlChannel = ['applovin', 'unity', 'appier', 'ironsource', 'mintegral', 'moloco'];
|
import * as path from 'path'
|
||||||
|
import do_task from './single-html/build.js'
|
||||||
|
import { createDist } from './common/utils.js'
|
||||||
|
|
||||||
// 创建 dist 目录
|
|
||||||
if (!fs.existsSync('dist')) {
|
|
||||||
fs.mkdirSync('dist');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理 HTML 渠道
|
// 处理 HTML 渠道
|
||||||
async function processHtmlChannels() {
|
async function processHtmlChannels(options) {
|
||||||
|
const outputPrefix = options.outputPrefix || '';
|
||||||
|
const htmlChannel = options.htmlChannel || ['applovin', 'unity', 'appier', 'ironsource', 'mintegral', 'moloco'];
|
||||||
for (const channelName of htmlChannel) {
|
for (const channelName of htmlChannel) {
|
||||||
// 删除所有可能存在的旧文件
|
// 删除所有可能存在的旧文件
|
||||||
const filesToDelete = ['mraid_support.js', 'mraid.js', 'mintegral.js', 'moloco.js'];
|
const filesToDelete = ['mraid_support.js', 'mraid.js', 'mintegral.js', 'moloco.js'];
|
||||||
|
@ -95,6 +92,8 @@ async function processHtmlChannels() {
|
||||||
console.log(`已将 ${channelName}.js 和相关 script 引入到 index.html 中`);
|
console.log(`已将 ${channelName}.js 和相关 script 引入到 index.html 中`);
|
||||||
|
|
||||||
// 调用 do_task 方法,将 web-mobile 下的所有包打包成一个 HTML
|
// 调用 do_task 方法,将 web-mobile 下的所有包打包成一个 HTML
|
||||||
|
createDist()
|
||||||
|
|
||||||
do_task();
|
do_task();
|
||||||
|
|
||||||
// 如果是 ironsource 渠道,将 <script src="mraid.js"></script> 插入到 body 标签之前
|
// 如果是 ironsource 渠道,将 <script src="mraid.js"></script> 插入到 body 标签之前
|
||||||
|
@ -115,4 +114,4 @@ async function processHtmlChannels() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processHtmlChannels();
|
export default processHtmlChannels;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
{
|
{
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node single-html/build.js",
|
"build": "node single-html/build.js",
|
||||||
"build:zip": "node zipChannelScript.js",
|
"build:cicd": "node cicdScript.js"
|
||||||
"build:h5": "node htmlChannelScript.js",
|
|
||||||
"build:allChannels": "node scriptBefore.js && npm run build:zip && npm run build:h5"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"clean-css": "^5.3.3",
|
"clean-css": "^5.3.3",
|
||||||
|
@ -13,4 +12,4 @@
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
"brotli": "^1.3.3"
|
"brotli": "^1.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
// Provides functions for encoding/decoding data to and from base-122.
|
// Provides functions for encoding/decoding data to and from base-122.
|
||||||
|
|
||||||
let fs = require('fs')
|
import * as fs from 'fs'
|
||||||
, readline = require('readline')
|
import readline from 'readline'
|
||||||
;
|
|
||||||
|
|
||||||
const kString = 0
|
const kString = 0
|
||||||
, kUint8Array = 1
|
, kUint8Array = 1
|
||||||
|
@ -248,10 +247,11 @@ function print8Bits(num) {
|
||||||
return "00000000".substring(num.toString(2).length) + num.toString(2);
|
return "00000000".substring(num.toString(2).length) + num.toString(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
encode: encode,
|
export {
|
||||||
decode: decode,
|
encode,
|
||||||
encodeFromBase64: encodeFromBase64,
|
decode,
|
||||||
encodeFile: encodeFile,
|
encodeFromBase64,
|
||||||
utf8DataToString: utf8DataToString
|
encodeFile,
|
||||||
|
utf8DataToString
|
||||||
};
|
};
|
|
@ -1,9 +1,10 @@
|
||||||
const fs = require("fs")
|
// 全部改成es6写法
|
||||||
const path = require("path")
|
import * as fs from 'fs'
|
||||||
const uglify = require("uglify-js")
|
import * as path from 'path'
|
||||||
const CleanCSS = require("clean-css")
|
import uglify from 'uglify-js'
|
||||||
const brotli = require('brotli');
|
import CleanCSS from 'clean-css'
|
||||||
const base122 = require("./base122")
|
import brotli from 'brotli'
|
||||||
|
import * as base122 from './base122.js'
|
||||||
|
|
||||||
/** 一些配置参数
|
/** 一些配置参数
|
||||||
* - [注意] 路径问题.start脚本与web-mobile同层级,因此相对路径需要带上web-mobile;cocos在调用资源时没有web-mobile,需要在最后去掉
|
* - [注意] 路径问题.start脚本与web-mobile同层级,因此相对路径需要带上web-mobile;cocos在调用资源时没有web-mobile,需要在最后去掉
|
||||||
|
@ -130,4 +131,4 @@ function do_task() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
module.exports = do_task
|
export default do_task
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
const fs = require("fs");
|
import * as fs from 'fs'
|
||||||
const path = require("path");
|
import * as path from 'path'
|
||||||
const archiver = require("archiver");
|
import archiver from 'archiver'
|
||||||
|
import { createDist } from './common/utils.js'
|
||||||
|
|
||||||
const zipChannel = ['facebook', 'google', 'tiktok', 'vungle', 'liftoff'];
|
async function processChannels(options) {
|
||||||
|
const zipChannel = options.zipChannel || ['facebook', 'google', 'tiktok', 'vungle', 'liftoff'];
|
||||||
const outputPrefix = '';
|
const outputPrefix = options.outputPrefix || '';
|
||||||
|
|
||||||
// 创建 dist 目录
|
|
||||||
if (!fs.existsSync('dist')) {
|
|
||||||
fs.mkdirSync('dist');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. 将js复制到web-mobile中
|
|
||||||
async function processChannels() {
|
|
||||||
for (const channelName of zipChannel) {
|
for (const channelName of zipChannel) {
|
||||||
// 遍历 networks 目录下的所有js文件,获取 文件名 然后删除 web-mobile 目录下的同名文件
|
// 遍历 networks 目录下的所有js文件,获取 文件名 然后删除 web-mobile 目录下的同名文件
|
||||||
const files = fs.readdirSync(path.join('networks'));
|
const files = fs.readdirSync(path.join('networks'));
|
||||||
|
@ -99,6 +92,9 @@ async function processChannels() {
|
||||||
fs.writeFileSync(htmlFilePath, htmlContent);
|
fs.writeFileSync(htmlFilePath, htmlContent);
|
||||||
console.log(`已将 ${channelName}.js 和 SDK script 引入到 index.html 中`);
|
console.log(`已将 ${channelName}.js 和 SDK script 引入到 index.html 中`);
|
||||||
|
|
||||||
|
|
||||||
|
createDist()
|
||||||
|
|
||||||
// 打包 web-mobile 目录为 zip 文件
|
// 打包 web-mobile 目录为 zip 文件
|
||||||
const output = fs.createWriteStream(path.join('dist', `${outputPrefix}${channelName}.zip`));
|
const output = fs.createWriteStream(path.join('dist', `${outputPrefix}${channelName}.zip`));
|
||||||
const archive = archiver('zip', {
|
const archive = archiver('zip', {
|
||||||
|
@ -119,4 +115,5 @@ async function processChannels() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannels();
|
|
||||||
|
export default processChannels;
|
Loading…
Reference in New Issue