@honor-minigame/cli
Version:
honor minigame pack cli
75 lines (63 loc) • 2.42 kB
JavaScript
import path from 'path'
import fs from 'fs-extra'
import { sign } from '../package/index.js'
import { SIGN_MODE } from '../common/constant.js'
import { getManifestJson, checkNodeVersion } from '../utils/index.js'
import { updateMaifestJson } from '../utils/engineType.js'
import { injectCocos2xRuntimeFix } from '../utils/cocos2x-runtime-fix.js'
import * as readline from 'readline'
async function readInput(question) {
return new Promise(resolve => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question(question, answer => {
rl.close()
resolve(answer)
})
rl.on('SIGINT', () => {
rl.close()
})
})
}
// 通用模式打包
export async function packAction(param = 'debug', target, isAlliance, isPlayable) {
// 检查node版本
if (!checkNodeVersion()) {
return
}
let options = {}
const rootPath = target ? target : process.cwd()
const signMode = param === SIGN_MODE.RELEASE ? SIGN_MODE.RELEASE : SIGN_MODE.DEBUG
const manifestJsonPath = path.join(rootPath, 'manifest.json')
if (!fs.existsSync(manifestJsonPath)) {
console.warn(`### HONOR PACK ### 缺少manifest.json文件`)
return
}
let customPackageName = ''
if (isPlayable) {
const manifest = fs.readJSONSync(manifestJsonPath)
const defaultPackage = manifest.package || ''
const inputPackage = await readInput(`请输入包名${defaultPackage ? `(默认:${defaultPackage})` : ''}: `)
customPackageName = inputPackage.trim() || defaultPackage
// 修改包名添加 .interactive 后缀
const interactivePackage = customPackageName.endsWith('.interactive')
? customPackageName
: customPackageName + '.interactive'
manifest.package = interactivePackage
fs.outputJSONSync(manifestJsonPath, manifest, { spaces: 2 })
}
options = getManifestJson(manifestJsonPath, signMode, isAlliance)
options = Object.assign(options, {
projectPath: rootPath,
signMode: signMode,
output: path.join(rootPath, 'dist'),
customPackageName
})
updateMaifestJson(rootPath)
// cocos2.x 游戏注入运行时修复(复制 image-load-fix / renderflow-fix 到 adapter/ 并在 boot.js 引入)
injectCocos2xRuntimeFix(rootPath)
console.info('### HONOR PACK ### 开始签名')
sign(options)
}