天气组件、倒计时组件微调。引入浏览器组件。
This commit is contained in:
lincube
2026-03-04 03:41:59 +08:00
parent e8276c4d1e
commit 3d22c04a04
31 changed files with 3258 additions and 576 deletions

View File

@@ -1,220 +1,159 @@
#!/bin/bash
# LanMontainDesktop Build Script for Linux/macOS
# Usage: ./build.sh [options]
# Example: ./build.sh --project LanMontainDesktop.csproj --rid linux-x64 --version 1.0.0
# Build script for LanMontainDesktop
# Cross-platform build support: Linux, macOS
set -e
# Default values
PROJECT="LanMontainDesktop/LanMontainDesktop.csproj"
CONFIGURATION="Release"
Script_Dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Root_Dir="$(dirname "$Script_Dir")"
# Detect OS
OS=""
ARCH=""
RID=""
VERSION=""
PUBLISH_DIR=""
SKIP_RESTORE=false
VERBOSE=false
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Functions
print_error() {
echo -e "${RED}❌ Error: $1${NC}" >&2
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
RID="linux-x64"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
RID="osx-arm64"
else
RID="osx-x64"
fi
else
echo "Unsupported OS: $OSTYPE"
exit 1
fi
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_info() {
echo -e "${BLUE} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
show_help() {
print_usage() {
cat << EOF
LanMontainDesktop Build Script for Linux/macOS
LanMontainDesktop Build Script
Usage: $0 [options]
Usage: $0 [command] [options]
Commands:
build Build the project
publish Publish as self-contained
clean Clean build output
Options:
-p, --project PATH Project file path (default: LanMontainDesktop/LanMontainDesktop.csproj)
-c, --config CONFIG Configuration: Release/Debug (default: Release)
-r, --rid RID Runtime Identifier: linux-x64, osx-x64, osx-arm64 (required)
-v, --version VERSION Version number (default: read from csproj)
-o, --output DIR Output directory for publish
--skip-restore Skip dotnet restore
--verbose Verbose output
-h, --help Show this help message
--config CONFIG Build configuration (Debug/Release, default: Release)
--rid RID Runtime identifier (e.g., linux-x64, osx-arm64)
--os OS Operating system (linux, macos)
Examples:
./build.sh --rid linux-x64 --version 1.0.0
./build.sh --rid osx-x64 --output ./publish
./build.sh --project LanMontainDesktop/LanMontainDesktop.csproj --rid osx-arm64
$0 build
$0 publish --config Release --rid linux-x64
$0 clean
EOF
}
# Parse arguments
build_project() {
local config="$1"
echo "Building $OS ($RID) - $config configuration..."
cd "$Root_Dir"
dotnet restore
dotnet build -c "$config" --no-restore -v minimal
echo "✅ Build completed"
}
publish_project() {
local config="$1"
local output_dir="$Root_Dir/publish/$RID"
echo "Publishing $OS ($RID)..."
cd "$Root_Dir"
dotnet restore
dotnet publish LanMontainDesktop/LanMontainDesktop.csproj \
-c "$config" \
-o "$output_dir" \
--self-contained \
-r "$RID" \
-p:PublishSingleFile=true \
-p:DebugType=none \
-v minimal
echo "✅ Published to: $output_dir"
echo " Size: $(du -sh "$output_dir" | cut -f1)"
}
clean_project() {
echo "Cleaning build output..."
cd "$Root_Dir"
rm -rf ./publish
rm -rf ./bin
rm -rf ./obj
find . -name "bin" -type d -exec rm -rf {} + 2>/dev/null || true
find . -name "obj" -type d -exec rm -rf {} + 2>/dev/null || true
echo "✅ Clean completed"
}
# Main
detect_os
config="Release"
command="build"
while [[ $# -gt 0 ]]; do
case $1 in
-p|--project)
PROJECT="$2"
build|publish|clean)
command="$1"
shift
;;
--config)
config="$2"
shift 2
;;
-c|--config)
CONFIGURATION="$2"
shift 2
;;
-r|--rid)
--rid)
RID="$2"
shift 2
;;
-v|--version)
VERSION="$2"
--os)
OS="$2"
if [[ "$OS" == "linux" ]]; then
RID="linux-x64"
elif [[ "$OS" == "macos" ]]; then
RID="osx-x64"
fi
shift 2
;;
-o|--output)
PUBLISH_DIR="$2"
shift 2
;;
--skip-restore)
SKIP_RESTORE=true
shift
;;
--verbose)
VERBOSE=true
shift
;;
-h|--help)
show_help
print_usage
exit 0
;;
*)
print_error "Unknown option: $1"
show_help
echo "Unknown option: $1"
print_usage
exit 1
;;
esac
done
# Validation
if [ -z "$RID" ]; then
print_error "Runtime Identifier (--rid) is required"
show_help
exit 1
fi
if [ ! -f "$PROJECT" ]; then
print_error "Project file not found: $PROJECT"
exit 1
fi
# Detect OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
DETECTED_RID="linux-x64"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
# Try to detect architecture
if [ "$(uname -m)" == "arm64" ]; then
DETECTED_RID="osx-arm64"
else
DETECTED_RID="osx-x64"
fi
else
print_error "Unsupported OS: $OSTYPE"
exit 1
fi
print_info "Detected OS: $OS ($DETECTED_RID)"
print_info "Target RID: $RID"
# Read version from csproj if not provided
if [ -z "$VERSION" ]; then
VERSION=$(grep -oP '<Version>\K[^<]*' "$PROJECT" | head -1)
if [ -z "$VERSION" ]; then
VERSION="1.0.0"
print_warning "No version found in csproj, using default: $VERSION"
fi
fi
print_info "Version: $VERSION"
print_info "Configuration: $CONFIGURATION"
# Set output directory
if [ -z "$PUBLISH_DIR" ]; then
PUBLISH_DIR="./publish/$RID"
fi
print_info "Output directory: $PUBLISH_DIR"
# Restore dependencies
if [ "$SKIP_RESTORE" = false ]; then
print_info "Restoring dependencies..."
if [ "$VERBOSE" = true ]; then
dotnet restore --verbosity detailed
else
dotnet restore
fi
print_success "Dependencies restored"
fi
# Build
print_info "Building..."
if [ "$VERBOSE" = true ]; then
dotnet build "$PROJECT" \
-c "$CONFIGURATION" \
--no-restore \
--verbosity detailed
else
dotnet build "$PROJECT" -c "$CONFIGURATION" --no-restore
fi
print_success "Build completed"
# Publish
print_info "Publishing..."
PUBLISH_ARGS=(
"$PROJECT"
"-c" "$CONFIGURATION"
"-o" "$PUBLISH_DIR"
"-r" "$RID"
"--self-contained"
)
# Add platform-specific publish options
if [ "$VERBOSE" = true ]; then
PUBLISH_ARGS+=("--verbosity" "detailed")
fi
dotnet publish "${PUBLISH_ARGS[@]}" \
-p:PublishSingleFile=true \
-p:PublishTrimmed=false \
-p:DebugType=embedded \
-p:DebugSymbols=false
print_success "Published to: $PUBLISH_DIR"
# Show result
if [ -d "$PUBLISH_DIR" ]; then
SIZE=$(du -sh "$PUBLISH_DIR" | cut -f1)
FILE_COUNT=$(find "$PUBLISH_DIR" -type f | wc -l)
print_success "Build complete! Output size: $SIZE ($FILE_COUNT files)"
if [ "$VERBOSE" = true ]; then
print_info "Output contents:"
ls -lh "$PUBLISH_DIR"
fi
else
print_error "Publish directory not found"
exit 1
fi
print_success "Done!"
case $command in
build)
build_project "$config"
;;
publish)
publish_project "$config"
;;
clean)
clean_project
;;
*)
print_usage
exit 1
;;
esac