From da7cef9cda6ba0ffa0a14536c496c10f3c0ad81b Mon Sep 17 00:00:00 2001 From: guofei Date: Mon, 13 Jan 2025 19:23:26 +0800 Subject: [PATCH] change es6 cicd --- scriptBefore.js => cicdScript.js | 22 ++++++++++------------ common/utils.js | 24 ++++++++++++++++++++++++ htmlChannelScript.js | 10 ++++------ package.json | 4 +--- single-html/base122.js | 13 +++++++------ single-html/build.js | 2 +- zipChannelScript.js | 10 ++++------ 7 files changed, 51 insertions(+), 34 deletions(-) rename scriptBefore.js => cicdScript.js (90%) create mode 100644 common/utils.js diff --git a/scriptBefore.js b/cicdScript.js similarity index 90% rename from scriptBefore.js rename to cicdScript.js index dce9101..5986214 100644 --- a/scriptBefore.js +++ b/cicdScript.js @@ -1,24 +1,22 @@ import * as fs from 'fs' 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/app/legend-of-mushroom/id6475333787" var androidUrl = "https://play.google.com/store/apps/details?id=com.mxdzzus.google" -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) - -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')) - } -} +removeDist() +createDist() function replaceAppStoreUrl() { diff --git a/common/utils.js b/common/utils.js new file mode 100644 index 0000000..740db74 --- /dev/null +++ b/common/utils.js @@ -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) + } +} \ No newline at end of file diff --git a/htmlChannelScript.js b/htmlChannelScript.js index b8c974c..62b5d14 100644 --- a/htmlChannelScript.js +++ b/htmlChannelScript.js @@ -1,14 +1,10 @@ import * as fs from 'fs' import * as path from 'path' -import do_task from './single-html/build' +import do_task from './single-html/build.js' +import { createDist } from './common/utils.js' -// 创建 dist 目录 -if (!fs.existsSync('dist')) { - fs.mkdirSync('dist'); -} - // 处理 HTML 渠道 async function processHtmlChannels(options) { const outputPrefix = options.outputPrefix || ''; @@ -96,6 +92,8 @@ async function processHtmlChannels(options) { console.log(`已将 ${channelName}.js 和相关 script 引入到 index.html 中`); // 调用 do_task 方法,将 web-mobile 下的所有包打包成一个 HTML + createDist() + do_task(); // 如果是 ironsource 渠道,将 插入到 body 标签之前 diff --git a/package.json b/package.json index ca36c7e..aafd061 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,7 @@ "type": "module", "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:cicd": "node cicdScript.js" }, "devDependencies": { "clean-css": "^5.3.3", diff --git a/single-html/base122.js b/single-html/base122.js index eeb866f..c800d9b 100644 --- a/single-html/base122.js +++ b/single-html/base122.js @@ -247,10 +247,11 @@ function print8Bits(num) { return "00000000".substring(num.toString(2).length) + num.toString(2); } -module.exports = { - encode: encode, - decode: decode, - encodeFromBase64: encodeFromBase64, - encodeFile: encodeFile, - utf8DataToString: utf8DataToString + +export { + encode, + decode, + encodeFromBase64, + encodeFile, + utf8DataToString }; \ No newline at end of file diff --git a/single-html/build.js b/single-html/build.js index 0547950..74e7493 100644 --- a/single-html/build.js +++ b/single-html/build.js @@ -4,7 +4,7 @@ import * as path from 'path' import uglify from 'uglify-js' import CleanCSS from 'clean-css' import brotli from 'brotli' -import base122 from './base122' +import * as base122 from './base122.js' /** 一些配置参数 * - [注意] 路径问题.start脚本与web-mobile同层级,因此相对路径需要带上web-mobile;cocos在调用资源时没有web-mobile,需要在最后去掉 diff --git a/zipChannelScript.js b/zipChannelScript.js index e8bb45b..d7ea05e 100644 --- a/zipChannelScript.js +++ b/zipChannelScript.js @@ -1,13 +1,8 @@ import * as fs from 'fs' import * as path from 'path' import archiver from 'archiver' +import { createDist } from './common/utils.js' -// 创建 dist 目录 -if (!fs.existsSync('dist')) { - fs.mkdirSync('dist'); -} - -// 1. 将js复制到web-mobile中 async function processChannels(options) { const zipChannel = options.zipChannel || ['facebook', 'google', 'tiktok', 'vungle', 'liftoff']; const outputPrefix = options.outputPrefix || ''; @@ -97,6 +92,9 @@ async function processChannels(options) { fs.writeFileSync(htmlFilePath, htmlContent); console.log(`已将 ${channelName}.js 和 SDK script 引入到 index.html 中`); + + createDist() + // 打包 web-mobile 目录为 zip 文件 const output = fs.createWriteStream(path.join('dist', `${outputPrefix}${channelName}.zip`)); const archive = archiver('zip', {