UNPKG

@honor-minigame/cli

Version:

honor minigame pack cli

65 lines (56 loc) 1.92 kB
import path from 'path' import chalk from 'chalk' import { fileURLToPath } from 'url' import { execSync } from 'child_process' import * as readline from 'readline' import { _transfer } from '../weixin/index.js' import * as paths from '../packager/lib/paths.js' import { info } from '../utils/logger.js' import { build } from '../packager/index.js' import { fsExt } from '../utils/fsUtils.js' 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 transferAction(param = 'debug', target, isAlliance, isPlayable) { const qgGamePath = await _transfer(target) // 切换到转换后的目录下 process.chdir(qgGamePath) paths.updateProject(qgGamePath) // 获取默认包名 let customPackageName = '' if (isPlayable) { const manifestPath = path.join(qgGamePath, 'src', 'manifest.json') const manifest = fsExt.parse(manifestPath) const defaultPackage = manifest?.package || '' const inputPackage = await readInput(`请输入包名${defaultPackage ? `(默认:${defaultPackage})` : ''}: `) customPackageName = inputPackage.trim() || defaultPackage } try { info(chalk.blueBright(`\n###开始自动进行build打包,rpk包体将打包到${paths.DIST}目录下`)) const q = false build({ dist: paths.DIST, isRelease: param === 'release', amd: true, playable: isPlayable, customPackageName, complete: () => { info(chalk.blueBright('\n \n###build打包完成')) } }) } catch (error) { console.error(`build 任务执行失败:${error.message}`) } }