UNPKG

@honor-minigame/cli

Version:

honor minigame pack cli

81 lines (74 loc) 2.56 kB
import path from "path"; import { fileURLToPath } from "url"; import fs from "fs-extra"; import { sign } from "../package/index.js"; import { ENGINE_TYPE, SIGN_MODE } from "../common/constant.js"; import { checkNodeVersion, patchEntryFile } from "../utils/index.js"; import { updateMaifestJson } from "../utils/engineType.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // egret打包 export function egretPackAction(param = "debug", target, isAlliance) { if (!checkNodeVersion()) { return; } let options = {}; const signMode = param === SIGN_MODE.RELEASE ? SIGN_MODE.RELEASE : SIGN_MODE.DEBUG; const rootPath = target ? target : process.cwd(); let manifest = {}; /* ------ index.html转换为index.js ----- */ const configPath = path.join(rootPath, "manifest.json"); if (fs.pathExistsSync(configPath)) { manifest = fs.readJSONSync(configPath); if (manifest.initial) { const list = manifest.initial.concat(manifest.game); const indexPath = path.join(rootPath, "index.js"); fs.writeFileSync(indexPath, ""); /* ------ 重新写入引用 ----- */ list.forEach((item) => { fs.appendFileSync(indexPath, `require("${item}")\n`); }); manifest = { package: "com.egret.demo.minigame", name: "egret demo", versionName: "1.0.1", versionCode: 1, minPlatformVersion: 1070, icon: "/logo.png", type: "game", vConsole: signMode === SIGN_MODE.DEBUG, config: { debug: true, logLevel: "debug", }, orientation: "portrait", }; } if (isAlliance) { manifest.allianceVersion = 1300; } /* ------ 重写manifest.json ----- */ fs.outputJSONSync(configPath, manifest); } /* ------ runtime文件适配 ----- */ const destRuntimePath = path.join(rootPath, "cocos-runtime-egret.min.js"); if (!fs.existsSync(destRuntimePath)) { const runtimePath = path.join( __dirname, "./../common/cocos-runtime-egret.min.js" ); fs.copySync(runtimePath, destRuntimePath); } /* ------ 创建入口 ----- */ patchEntryFile(rootPath); options = Object.assign(manifest, { projectPath: rootPath, signMode: signMode, output: path.join(rootPath, "dist"), }); updateMaifestJson(rootPath, ENGINE_TYPE.EGRET) console.info("### HONOR PACK ### 开始签名"); // 开始签名 sign(options); }