UNPKG

@honor-minigame/cli

Version:

honor minigame pack cli

51 lines (43 loc) 1.64 kB
import { checkNodeVersion } from "../utils/index.js"; import { checkFileExtnameIsExits } from '../utils/fsUtils.js' import { initServer } from '../server/index.js' import minimist from 'minimist'; import fs from 'fs-extra' import path from 'path' import { error } from "../utils/logger.js"; import { execSync } from 'child_process'; import { fileURLToPath } from 'url' const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const projectPath = process.env.PATH_PROJECT || process.cwd() export async function serverAction(param = 'debug', target, isAlliance) { if (!checkNodeVersion()) { return; } const DISTPROJECT = path.resolve(projectPath, './dist') if(!fs.existsSync(DISTPROJECT)){ error(`目录:${projectPath} 不存在 dist 文件夹`) return; } if(!checkFileExtnameIsExits(DISTPROJECT, 'rpk')){ error(`目录:${DISTPROJECT} 不存在 rpk 文件, 运行 minigame pack 命令`) try{ // 正式环境 minigame 命令 全局运行 execSync('minigame pack', { cwd: projectPath, stdio: 'inherit' }) }catch(err){ // 测试环境 const cliEntry = path.join(__dirname, '..', 'index.js'); execSync(`node "${cliEntry}" pack`, { cwd: projectPath, stdio: 'inherit' }) } } const args = minimist(process.argv.slice(2), { string: ['buildType'] }) const cleanedArgs = {} for (const key in args) { const cleanedKey = key.replace(/--/g, '') cleanedArgs[cleanedKey] = args[key] } cleanedArgs['DISTPROJECT'] = DISTPROJECT initServer(cleanedArgs); }