mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2026-03-07 22:33:39 +00:00
feat: Enhance configuration management and build scripts
- Updated `go.mod` to include new dependencies for color output. - Refactored `main.go` to improve `StorageConfig` structure and add new methods for configuration management. - Implemented a progress spinner and error handling for file operations. - Enhanced build scripts (`build_all.bat` and `build_all.sh`) for better output and error handling, including versioning and cleanup processes. - Removed obsolete binary files for various platforms. - Updated VSCode settings for spell checking. This commit improves the overall functionality and user experience of the Cursor ID Modifier tool.
This commit is contained in:
@@ -1,28 +1,116 @@
|
||||
@echo off
|
||||
echo Creating bin directory...
|
||||
if not exist "..\bin" mkdir "..\bin"
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
echo Building for all platforms...
|
||||
:: 设置版本信息
|
||||
set VERSION=1.0.0
|
||||
|
||||
echo Building for Windows AMD64...
|
||||
set GOOS=windows
|
||||
set GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier.exe ../main.go
|
||||
:: 设置颜色代码
|
||||
set "GREEN=[32m"
|
||||
set "RED=[31m"
|
||||
set "YELLOW=[33m"
|
||||
set "RESET=[0m"
|
||||
|
||||
echo Building for macOS AMD64...
|
||||
set GOOS=darwin
|
||||
set GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier_mac ../main.go
|
||||
:: 设置编译优化标志
|
||||
set "LDFLAGS=-s -w"
|
||||
set "BUILDMODE=pie"
|
||||
set "GCFLAGS=-N -l"
|
||||
|
||||
echo Building for macOS ARM64...
|
||||
set GOOS=darwin
|
||||
set GOARCH=arm64
|
||||
go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go
|
||||
:: 检查是否安装了必要的交叉编译工具
|
||||
where gcc >nul 2>nul
|
||||
if %errorlevel% neq 0 (
|
||||
echo %RED%错误: 未找到 gcc,这可能会影响 Mac 系统的交叉编译%RESET%
|
||||
echo %YELLOW%请安装 MinGW-w64 或其他 gcc 工具链%RESET%
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Building for Linux AMD64...
|
||||
set GOOS=linux
|
||||
set GOARCH=amd64
|
||||
go build -o ../bin/cursor_id_modifier_linux ../main.go
|
||||
:: 设置 CGO
|
||||
set CGO_ENABLED=0
|
||||
|
||||
echo All builds completed!
|
||||
pause
|
||||
:: 显示编译信息
|
||||
echo %YELLOW%开始构建 version %VERSION%%RESET%
|
||||
echo %YELLOW%使用优化标志: LDFLAGS=%LDFLAGS%, BUILDMODE=%BUILDMODE%%RESET%
|
||||
echo %YELLOW%CGO_ENABLED=%CGO_ENABLED%%RESET%
|
||||
|
||||
:: 仅在必要时清理旧文件
|
||||
if "%1"=="clean" (
|
||||
echo 清理旧构建文件...
|
||||
if exist "..\bin" rd /s /q "..\bin"
|
||||
)
|
||||
|
||||
:: 创建输出目录
|
||||
if not exist "..\bin" mkdir "..\bin" 2>nul
|
||||
|
||||
:: 定义目标平台数组
|
||||
set platforms[0].os=windows
|
||||
set platforms[0].arch=amd64
|
||||
set platforms[0].ext=.exe
|
||||
|
||||
set platforms[1].os=darwin
|
||||
set platforms[1].arch=amd64
|
||||
set platforms[1].ext=
|
||||
|
||||
set platforms[2].os=darwin
|
||||
set platforms[2].arch=arm64
|
||||
set platforms[2].ext=
|
||||
|
||||
set platforms[3].os=linux
|
||||
set platforms[3].arch=amd64
|
||||
set platforms[3].ext=
|
||||
|
||||
:: 设置开始时间
|
||||
set start_time=%time%
|
||||
|
||||
:: 编译所有目标
|
||||
echo 开始编译所有平台...
|
||||
|
||||
for /L %%i in (0,1,3) do (
|
||||
set "os=!platforms[%%i].os!"
|
||||
set "arch=!platforms[%%i].arch!"
|
||||
set "ext=!platforms[%%i].ext!"
|
||||
|
||||
echo.
|
||||
echo Building for !os! !arch!...
|
||||
|
||||
set GOOS=!os!
|
||||
set GOARCH=!arch!
|
||||
|
||||
:: 为 darwin 系统设置特殊编译参数和文件名
|
||||
if "!os!"=="darwin" (
|
||||
set "extra_flags=-tags ios"
|
||||
if "!arch!"=="amd64" (
|
||||
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_mac_intel!ext!"
|
||||
) else (
|
||||
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_mac_m1!ext!"
|
||||
)
|
||||
) else (
|
||||
set "extra_flags="
|
||||
set "outfile=..\bin\cursor_id_modifier_v%VERSION%_!os!_!arch!!ext!"
|
||||
)
|
||||
|
||||
go build -trimpath !extra_flags! -buildmode=%BUILDMODE% -ldflags="%LDFLAGS%" -gcflags="%GCFLAGS%" -o "!outfile!" ..\main.go
|
||||
|
||||
if !errorlevel! equ 0 (
|
||||
echo %GREEN%Build successful: !outfile!%RESET%
|
||||
) else (
|
||||
echo %RED%Build failed for !os! !arch!%RESET%
|
||||
echo %YELLOW%如果是 Mac 系统编译失败,请确保:%RESET%
|
||||
echo %YELLOW%1. 已安装 MinGW-w64%RESET%
|
||||
echo %YELLOW%2. 已设置 GOARCH 和 GOOS%RESET%
|
||||
echo %YELLOW%3. CGO_ENABLED=0%RESET%
|
||||
)
|
||||
)
|
||||
|
||||
:: 计算总耗时
|
||||
set end_time=%time%
|
||||
set options="tokens=1-4 delims=:.,"
|
||||
for /f %options% %%a in ("%start_time%") do set start_s=%%a&set start_m=%%b&set start_h=%%c
|
||||
for /f %options% %%a in ("%end_time%") do set end_s=%%a&set end_m=%%b&set end_h=%%c
|
||||
set /a duration = (end_h - start_h) * 3600 + (end_m - start_m) * 60 + (end_s - start_s)
|
||||
|
||||
echo.
|
||||
echo %GREEN%所有构建完成! 总耗时: %duration% 秒%RESET%
|
||||
if exist "..\bin" dir /b "..\bin"
|
||||
|
||||
pause
|
||||
endlocal
|
||||
@@ -1,22 +1,101 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 创建bin目录(如果不存在)
|
||||
mkdir -p ../bin
|
||||
# 设置颜色代码
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Windows
|
||||
echo "Building for Windows..."
|
||||
GOOS=windows GOARCH=amd64 go build -o ../bin/cursor_id_modifier.exe ../main.go
|
||||
# 版本信息
|
||||
VERSION="1.0.0"
|
||||
|
||||
# macOS (Intel)
|
||||
echo "Building for macOS (Intel)..."
|
||||
GOOS=darwin GOARCH=amd64 go build -o ../bin/cursor_id_modifier_mac ../main.go
|
||||
# 错误处理函数
|
||||
handle_error() {
|
||||
echo -e "${RED}Error: $1${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# macOS (Apple Silicon)
|
||||
echo "Building for macOS (ARM64)..."
|
||||
GOOS=darwin GOARCH=arm64 go build -o ../bin/cursor_id_modifier_mac_arm64 ../main.go
|
||||
# 清理函数
|
||||
cleanup() {
|
||||
echo "Cleaning old builds..."
|
||||
rm -rf ../bin
|
||||
}
|
||||
|
||||
# Linux
|
||||
echo "Building for Linux..."
|
||||
GOOS=linux GOARCH=amd64 go build -o ../bin/cursor_id_modifier_linux ../main.go
|
||||
# 创建输出目录
|
||||
create_output_dir() {
|
||||
echo "Creating bin directory..."
|
||||
mkdir -p ../bin || handle_error "Failed to create bin directory"
|
||||
}
|
||||
|
||||
echo "All builds completed!"
|
||||
# 构建函数
|
||||
build() {
|
||||
local os=$1
|
||||
local arch=$2
|
||||
local suffix=$3
|
||||
|
||||
echo -e "\nBuilding for $os ($arch)..."
|
||||
|
||||
output_name="../bin/cursor_id_modifier_v${VERSION}_${os}_${arch}${suffix}"
|
||||
|
||||
GOOS=$os GOARCH=$arch go build -o "$output_name" ../main.go
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}✓ Successfully built: ${output_name}${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Failed to build for $os $arch${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
# 显示构建信息
|
||||
echo "Starting build process for version ${VERSION}"
|
||||
|
||||
# 清理旧文件
|
||||
cleanup
|
||||
|
||||
# 创建输出目录
|
||||
create_output_dir
|
||||
|
||||
# 定义构建目标
|
||||
declare -A targets=(
|
||||
["windows_amd64"]=".exe"
|
||||
["darwin_amd64"]=""
|
||||
["darwin_arm64"]=""
|
||||
["linux_amd64"]=""
|
||||
)
|
||||
|
||||
# 构建计数器
|
||||
local success_count=0
|
||||
local fail_count=0
|
||||
|
||||
# 遍历所有目标进行构建
|
||||
for target in "${!targets[@]}"; do
|
||||
os=${target%_*}
|
||||
arch=${target#*_}
|
||||
suffix=${targets[$target]}
|
||||
|
||||
if build "$os" "$arch" "$suffix"; then
|
||||
((success_count++))
|
||||
else
|
||||
((fail_count++))
|
||||
fi
|
||||
done
|
||||
|
||||
# 显示构建结果
|
||||
echo -e "\nBuild Summary:"
|
||||
echo -e "${GREEN}Successful builds: $success_count${NC}"
|
||||
if [ $fail_count -gt 0 ]; then
|
||||
echo -e "${RED}Failed builds: $fail_count${NC}"
|
||||
fi
|
||||
|
||||
# 显示生成的文件列表
|
||||
echo -e "\nGenerated files:"
|
||||
ls -1 ../bin
|
||||
}
|
||||
|
||||
# 捕获错误信号
|
||||
trap 'echo -e "\n${RED}Build process interrupted${NC}"; exit 1' INT TERM
|
||||
|
||||
# 执行主函数
|
||||
main
|
||||
Reference in New Issue
Block a user