build-win.bat 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. @echo off
  2. chcp 65001 >nul 2>&1
  3. :: 切换到脚本所在目录
  4. cd /d "%~dp0"
  5. :: 启用 ANSI 转义序列支持 (Windows 10+)
  6. :: 设置 ESC 变量为真正的 ESC 字符 (ASCII 27)
  7. for /f %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
  8. :: ============================================
  9. :: Claude AI Installer Windows 构建脚本
  10. :: Build script for Windows using Tauri
  11. :: 此脚本作为 scripts/build.js 的简单入口
  12. :: ============================================
  13. :: 检查是否请求帮助
  14. if /i "%~1"=="--help" goto :show_help
  15. if /i "%~1"=="-h" goto :show_help
  16. echo.
  17. echo ========================================
  18. echo Claude AI Installer - Windows 构建
  19. echo 使用 Tauri 2.0
  20. echo ========================================
  21. echo.
  22. :: 检查 Rust 是否安装
  23. where rustc >nul 2>&1
  24. if errorlevel 1 (
  25. echo %ESC%[91mx%ESC%[0m 未找到 Rust,请先安装 Rust
  26. echo %ESC%[94mi%ESC%[0m 访问: https://rustup.rs/
  27. pause
  28. exit /b 1
  29. )
  30. :: 显示 Rust 版本
  31. for /f "tokens=*" %%i in ('rustc --version') do echo %ESC%[92m√%ESC%[0m Rust: %%i
  32. :: 检查 Node.js
  33. where node >nul 2>&1
  34. if errorlevel 1 (
  35. echo %ESC%[91mx%ESC%[0m 未找到 Node.js,请先安装 Node.js
  36. pause
  37. exit /b 1
  38. )
  39. :: 显示 Node.js 版本
  40. for /f "tokens=*" %%i in ('node --version') do echo %ESC%[92m√%ESC%[0m Node.js: %%i
  41. :: 设置 Tauri 签名密钥环境变量
  42. if exist ".keys\tauri-signing.key" (
  43. echo %ESC%[92m√%ESC%[0m 找到签名密钥
  44. for /f "usebackq delims=" %%i in (".keys\tauri-signing.key") do set "TAURI_SIGNING_PRIVATE_KEY=%%i"
  45. set "TAURI_SIGNING_PRIVATE_KEY_PASSWORD="
  46. ) else (
  47. echo %ESC%[93m!%ESC%[0m 未找到签名密钥 (.keys\tauri-signing.key)
  48. echo %ESC%[94mi%ESC%[0m 更新功能将不可用,构建将继续...
  49. )
  50. :: 检查 node_modules
  51. if not exist "node_modules" (
  52. echo.
  53. echo %ESC%[93m!%ESC%[0m 未找到 node_modules,正在安装依赖...
  54. call npm install
  55. if errorlevel 1 (
  56. echo %ESC%[91mx%ESC%[0m 安装依赖失败
  57. pause
  58. exit /b 1
  59. )
  60. )
  61. :: 解析参数并转换为 Node.js 脚本参数
  62. set "NODE_ARGS="
  63. :parse_args
  64. if "%~1"=="" goto :run_build
  65. if /i "%~1"=="--debug" set "NODE_ARGS=%NODE_ARGS% --debug" & shift & goto :parse_args
  66. if /i "%~1"=="-d" set "NODE_ARGS=%NODE_ARGS% --debug" & shift & goto :parse_args
  67. if /i "%~1"=="--skip-frontend" set "NODE_ARGS=%NODE_ARGS% --skip-frontend" & shift & goto :parse_args
  68. if /i "%~1"=="-s" set "NODE_ARGS=%NODE_ARGS% --skip-frontend" & shift & goto :parse_args
  69. shift
  70. goto :parse_args
  71. :run_build
  72. echo.
  73. echo %ESC%[96m^> 调用 Node.js 构建脚本...%ESC%[0m
  74. echo %ESC%[94mi%ESC%[0m 执行: node scripts/build.js %NODE_ARGS%
  75. echo.
  76. call node scripts/build.js %NODE_ARGS%
  77. if errorlevel 1 (
  78. echo.
  79. echo %ESC%[91mx%ESC%[0m 构建失败!
  80. echo.
  81. pause
  82. exit /b 1
  83. )
  84. echo.
  85. pause
  86. goto :eof
  87. :: ============================================
  88. :: 显示帮助信息
  89. :: ============================================
  90. :show_help
  91. echo.
  92. echo Claude AI Installer Windows 构建脚本 (Tauri)
  93. echo.
  94. echo 用法:
  95. echo build-win.bat [参数]
  96. echo.
  97. echo 参数:
  98. echo --debug, -d 以调试模式构建
  99. echo --skip-frontend, -s 跳过前端构建
  100. echo --help, -h 显示此帮助信息
  101. echo.
  102. echo 示例:
  103. echo build-win.bat 完整发布构建
  104. echo build-win.bat --debug 调试构建
  105. echo build-win.bat -s 跳过前端,仅构建 Tauri
  106. echo.
  107. echo 输出 (发布模式):
  108. echo src-tauri\target\release\bundle\nsis\*.exe (NSIS 安装程序)
  109. echo src-tauri\target\release\bundle\msi\*.msi (MSI 安装程序)
  110. echo src-tauri\target\release\claude-ai-installer.exe (可执行文件)
  111. echo.
  112. echo 输出 (调试模式):
  113. echo src-tauri\target\debug\claude-ai-installer.exe (调试版可执行文件)
  114. echo.
  115. echo 前置要求:
  116. echo - Rust (https://rustup.rs/)
  117. echo - Node.js (https://nodejs.org/)
  118. echo - Visual Studio Build Tools (Windows 平台)
  119. echo.
  120. echo 注意: 此脚本调用 scripts/build.js 执行实际构建
  121. echo.
  122. goto :eof