gratitude.durian.xpcool.com/cocos-prototype/build-wechat.bat
2026-08-14 18:01:45 +08:00

127 lines
3.5 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM ============================================
REM 微信小游戏构建脚本
REM
REM 功能:
REM 1. 清理旧构建文件
REM 2. 执行 Cocos Creator 构建
REM 3. 压缩和优化资源
REM 4. 生成版本信息
REM 5. 准备上传包
REM ============================================
setlocal enabledelayedexpansion
REM 配置变量
set PROJECT_NAME=报恩榴莲
set APP_ID=wxb2b7651c561f9d53
set BUILD_DIR=build
set OUTPUT_DIR=%BUILD_DIR%\wechatgame
set VERSION=1.0.0
echo ========================================
echo %PROJECT_NAME% 微信小游戏构建
echo 版本: %VERSION%
echo 时间: %date% %time%
echo ========================================
echo.
REM 步骤1: 检查 Cocos Creator 是否安装
echo [1/6] 检查 Cocos Creator...
where cocos >nul 2>&1
if %errorlevel% neq 0 (
echo ❌ 错误: 未找到 Cocos Creator 命令行工具
echo 请先安装 Cocos Creator 3.8 并添加到系统PATH
pause
exit /b 1
)
echo ✅ Cocos Creator 已安装
echo.
REM 步骤2: 清理旧构建文件
echo [2/6] 清理旧构建文件...
if exist "%OUTPUT_DIR%" (
rmdir /s /q "%OUTPUT_DIR%"
echo 已删除旧的构建目录
)
echo ✅ 清理完成
echo.
REM 步骤3: 执行构建
echo [3/6] 开始构建微信小游戏...
echo 这可能需要几分钟,请耐心等待...
cocos build ^
--platform wechatgame ^
--output "%OUTPUT_DIR%" ^
--debug false ^
--compress true ^
--native-code false
if %errorlevel% neq 0 (
echo ❌ 构建失败,请检查错误信息
pause
exit /b 1
)
echo ✅ 构建成功
echo.
REM 步骤4: 优化资源
echo [4/6] 优化资源文件...
REM 检查是否有图片需要压缩
if exist "%OUTPUT_DIR%\res" (
echo 发现资源目录,开始优化...
REM 如果有 TinyPNG API key可以在这里调用压缩
REM python compress_images.py "%OUTPUT_DIR%\res"
echo 资源优化完成
)
echo ✅ 资源优化完成
echo.
REM 步骤5: 生成版本信息
echo [5/6] 生成版本信息...
(
echo {
echo "name": "%PROJECT_NAME%",
echo "version": "%VERSION%",
echo "appId": "%APP_ID%",
echo "buildTime": "%date% %time%",
echo "platform": "wechatgame",
echo "engine": "Cocos Creator 3.8",
echo "orientation": "portrait"
echo }
) > "%OUTPUT_DIR%\version.json"
echo ✅ 版本信息已保存
echo.
REM 步骤6: 计算包体大小
echo [6/6] 计算包体大小...
powershell -Command "$size = (Get-ChildItem '%OUTPUT_DIR%' -Recurse | Measure-Object -Property Length -Sum).Sum; $mb = [math]::Round($size / 1MB, 2); Write-Host ' 总大小: '$mb' MB'"
REM 检查主包大小微信限制20MB
powershell -Command "$mainPkgSize = (Get-ChildItem '%OUTPUT_DIR%' -Exclude 'subpackages' -Recurse | Measure-Object -Property Length -Sum).Sum; $mb = [math]::Round($mainPkgSize / 1MB, 2); if ($mb -gt 20) { Write-Host ' ⚠️ 警告: 主包大小 '$mb' MB 超过20MB限制!' -ForegroundColor Red } else { Write-Host ' ✅ 主包大小: '$mb' MB (符合规范)' -ForegroundColor Green }"
echo.
echo ========================================
echo 🎉 构建完成!
echo ========================================
echo.
echo 📁 构建目录: %OUTPUT_DIR%
echo 📱 AppID: %APP_ID%
echo 📦 版本: %VERSION%
echo.
echo 下一步操作:
echo 1. 用微信开发者工具打开构建目录
echo 路径: %cd%\%OUTPUT_DIR%
echo.
echo 2. 点击「预览」生成二维码
echo.
echo 3. 用手机微信扫码进行真机测试
echo.
echo 4. 测试通过后,点击「上传」提交到微信后台
echo.
pause