From b2e9dd8b7f1985cd943a7fef369acd4efc8a5060 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Fri, 24 Apr 2026 19:02:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=90=88=E5=B9=B6=20macOS=20?= =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E6=89=93=E5=8C=85=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 macOS .app 打包直接并入 desktop-build-mac,减少重复的桌面构建入口。\n\n同时移除未实现或已废弃的 desktop-package-* 命令和独立打包脚本,降低维护成本。 --- Makefile | 55 ++++++++++++++++++++++----- README.md | 7 +--- scripts/build/package-macos.sh | 68 ---------------------------------- 3 files changed, 46 insertions(+), 84 deletions(-) delete mode 100755 scripts/build/package-macos.sh diff --git a/Makefile b/Makefile index 3e065ad..1ac985b 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ test-mysql-up test-mysql-down test-mysql test-mysql-quick \ frontend-build frontend-dev frontend-test frontend-test-watch frontend-test-coverage frontend-test-e2e frontend-lint frontend-clean \ desktop-build desktop-build-mac desktop-build-win desktop-build-linux \ - desktop-dev desktop-test desktop-package-mac desktop-package-win desktop-package-linux desktop-clean \ + desktop-dev desktop-test desktop-clean \ desktop-prepare-frontend desktop-prepare-embedfs # ============================================ @@ -172,6 +172,50 @@ desktop-build-mac: desktop-prepare-frontend desktop-prepare-embedfs @echo "🍎 Building macOS..." cd backend && CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o ../build/nex-mac-arm64 ./cmd/desktop cd backend && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o ../build/nex-mac-amd64 ./cmd/desktop + @echo "📦 Packaging macOS .app..." + mkdir -p build/Nex.app/Contents/MacOS build/Nex.app/Contents/Resources + cp build/nex-mac-arm64 build/Nex.app/Contents/MacOS/nex + @if [ -f assets/AppIcon.icns ]; then \ + cp assets/AppIcon.icns build/Nex.app/Contents/Resources/; \ + else \ + echo "⚠️ 未找到 assets/AppIcon.icns"; \ + fi + @{ \ + printf '%s\n' '' \ + '' \ + '' \ + '' \ + ' CFBundleDevelopmentRegion' \ + ' zh_CN' \ + ' CFBundleExecutable' \ + ' nex' \ + ' CFBundleIconFile' \ + ' AppIcon' \ + ' CFBundleIdentifier' \ + ' io.nex.gateway' \ + ' CFBundleInfoDictionaryVersion' \ + ' 6.0' \ + ' CFBundleName' \ + ' Nex Gateway' \ + ' CFBundleDisplayName' \ + ' Nex Gateway' \ + ' CFBundlePackageType' \ + ' APPL' \ + ' CFBundleShortVersionString' \ + ' 1.0.0' \ + ' CFBundleVersion' \ + ' 1.0.0' \ + ' LSMinimumSystemVersion' \ + ' 10.13' \ + ' LSUIElement' \ + ' ' \ + ' NSHighResolutionCapable' \ + ' ' \ + '' \ + ''; \ + } > build/Nex.app/Contents/Info.plist + chmod +x build/Nex.app/Contents/MacOS/nex + @echo "✅ macOS app packaged: build/Nex.app" desktop-build-win: desktop-prepare-frontend desktop-prepare-embedfs @echo "🪟 Building Windows..." @@ -188,15 +232,6 @@ desktop-dev: desktop-prepare-frontend desktop-prepare-embedfs desktop-test: cd backend && go test ./cmd/desktop/... -v -desktop-package-mac: - ./scripts/build/package-macos.sh - -desktop-package-win: - @echo "⚠️ Windows packaging not implemented yet" - -desktop-package-linux: - @echo "⚠️ Linux packaging not implemented yet" - desktop-clean: rm -rf build/ embedfs/assets embedfs/frontend-dist diff --git a/README.md b/README.md index 61a7870..01f5fcb 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,6 @@ nex/ │ ├── AppIcon.icns # macOS 应用图标 │ └── icon.ico # Windows 应用图标 │ -├── scripts/ # 构建脚本 -│ └── build/ -│ └── package-macos.sh # macOS .app 打包脚本 -│ └── README.md # 本文件 ``` @@ -105,9 +101,8 @@ JSON: {"level":"info","logger":"handler.proxy","msg":"处理请求","method": **构建桌面应用**: ```bash -# macOS (arm64 + amd64) +# macOS (arm64 + amd64,并打包为 .app) make desktop-build-mac -make desktop-package-mac # 打包为 .app # Windows make desktop-build-win diff --git a/scripts/build/package-macos.sh b/scripts/build/package-macos.sh deleted file mode 100755 index 00a3638..0000000 --- a/scripts/build/package-macos.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -VERSION="1.0.0" -APP_NAME="Nex" -BUNDLE_ID="io.nex.gateway" -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" -BUILD_DIR="${PROJECT_ROOT}/build" -ASSETS_DIR="${PROJECT_ROOT}/assets" - -echo "打包 macOS .app..." - -mkdir -p "${BUILD_DIR}/${APP_NAME}.app/Contents/MacOS" -mkdir -p "${BUILD_DIR}/${APP_NAME}.app/Contents/Resources" - -if [ -f "${BUILD_DIR}/nex-mac-arm64" ]; then - cp "${BUILD_DIR}/nex-mac-arm64" "${BUILD_DIR}/${APP_NAME}.app/Contents/MacOS/nex" -elif [ -f "${BUILD_DIR}/nex-mac-amd64" ]; then - cp "${BUILD_DIR}/nex-mac-amd64" "${BUILD_DIR}/${APP_NAME}.app/Contents/MacOS/nex" -else - echo "错误: 未找到 macOS 二进制文件,请先运行 make desktop-build-mac" - exit 1 -fi - -if [ -f "${ASSETS_DIR}/AppIcon.icns" ]; then - cp "${ASSETS_DIR}/AppIcon.icns" "${BUILD_DIR}/${APP_NAME}.app/Contents/Resources/" -else - echo "警告: 未找到 AppIcon.icns" -fi - -cat > "${BUILD_DIR}/${APP_NAME}.app/Contents/Info.plist" << EOF - - - - - CFBundleDevelopmentRegion - zh_CN - CFBundleExecutable - nex - CFBundleIconFile - AppIcon - CFBundleIdentifier - ${BUNDLE_ID} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${APP_NAME} Gateway - CFBundleDisplayName - ${APP_NAME} Gateway - CFBundlePackageType - APPL - CFBundleShortVersionString - ${VERSION} - CFBundleVersion - ${VERSION} - LSMinimumSystemVersion - 10.13 - LSUIElement - - NSHighResolutionCapable - - - -EOF - -chmod +x "${BUILD_DIR}/${APP_NAME}.app/Contents/MacOS/nex" - -echo "打包完成: ${BUILD_DIR}/${APP_NAME}.app"