REFACTOR END
This commit is contained in:
135
scripts/quick-fix.sh
Normal file
135
scripts/quick-fix.sh
Normal file
@@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Quick Fix Script for Common Build Issues
|
||||
|
||||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Fix missing translations by copying from default
|
||||
fix_translations() {
|
||||
print_status "Checking for missing translations..."
|
||||
|
||||
# Find all string resource files
|
||||
find app/src/main/res -name "strings.xml" | while read -r file; do
|
||||
if [[ $file != *"values/strings.xml" ]]; then
|
||||
# For each non-default strings.xml, check if all strings from default are present
|
||||
default_strings="app/src/main/res/values/strings.xml"
|
||||
|
||||
if [ -f "$default_strings" ]; then
|
||||
# Extract string names from default
|
||||
grep 'name="' "$default_strings" | sed 's/.*name="\([^"]*\)".*/\1/' | while read -r string_name; do
|
||||
if ! grep -q "name=\"$string_name\"" "$file"; then
|
||||
print_warning "Missing translation for '$string_name' in $file"
|
||||
# Automatically add placeholder translation
|
||||
sed -i "/<\/resources>/i\ <string name=\"$string_name\">[TRANSLATE: $string_name]</string>" "$file"
|
||||
print_status "Added placeholder for '$string_name' in $file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Fix common dependency issues
|
||||
fix_dependencies() {
|
||||
print_status "Checking for common dependency issues..."
|
||||
|
||||
# Check if buildSrc is properly configured
|
||||
if [ ! -f "buildSrc/build.gradle.kts" ]; then
|
||||
print_error "buildSrc not found - cannot fix dependency issues"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Sync Gradle to refresh dependencies
|
||||
print_status "Refreshing Gradle dependencies..."
|
||||
./gradlew --refresh-dependencies --quiet
|
||||
}
|
||||
|
||||
# Clean and rebuild
|
||||
clean_rebuild() {
|
||||
print_status "Performing clean rebuild..."
|
||||
./gradlew clean build --parallel --quiet
|
||||
}
|
||||
|
||||
# Fix lint issues
|
||||
fix_lint() {
|
||||
print_status "Running lint fix..."
|
||||
if command -v ./gradlew &> /dev/null; then
|
||||
./gradlew lintFix --quiet
|
||||
else
|
||||
print_warning "Gradle not found, skipping lint fix"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main menu
|
||||
show_menu() {
|
||||
echo "========================================"
|
||||
echo " HomeboxLens Quick Fix System"
|
||||
echo "========================================"
|
||||
echo "1. Fix missing translations"
|
||||
echo "2. Fix dependencies"
|
||||
echo "3. Clean rebuild"
|
||||
echo "4. Fix lint issues"
|
||||
echo "5. Run all fixes"
|
||||
echo "6. Exit"
|
||||
echo "========================================"
|
||||
}
|
||||
|
||||
main() {
|
||||
while true; do
|
||||
show_menu
|
||||
read -p "Choose option (1-6): " choice
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
fix_translations
|
||||
;;
|
||||
2)
|
||||
fix_dependencies
|
||||
;;
|
||||
3)
|
||||
clean_rebuild
|
||||
;;
|
||||
4)
|
||||
fix_lint
|
||||
;;
|
||||
5)
|
||||
print_status "Running all fixes..."
|
||||
fix_translations
|
||||
fix_dependencies
|
||||
fix_lint
|
||||
clean_rebuild
|
||||
;;
|
||||
6)
|
||||
print_status "Exiting..."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid option. Please choose 1-6."
|
||||
;;
|
||||
esac
|
||||
|
||||
read -p "Press Enter to continue..."
|
||||
done
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
115
scripts/smart-build.sh
Normal file
115
scripts/smart-build.sh
Normal file
@@ -0,0 +1,115 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Smart Gradle Build Wrapper
|
||||
# Reduces semantic noise and provides clear error reporting
|
||||
|
||||
set -e
|
||||
|
||||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Pre-build checks
|
||||
check_prerequisites() {
|
||||
print_status "Checking prerequisites..."
|
||||
|
||||
# Check if Java is available
|
||||
if ! command -v java &> /dev/null; then
|
||||
print_error "Java is not installed or not in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Android SDK
|
||||
if [ -z "$ANDROID_HOME" ]; then
|
||||
print_warning "ANDROID_HOME not set, using default detection"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clean build artifacts
|
||||
clean_build() {
|
||||
print_status "Cleaning previous build artifacts..."
|
||||
./gradlew clean --quiet --console=plain
|
||||
}
|
||||
|
||||
# Run build with reduced verbosity
|
||||
run_build() {
|
||||
print_status "Starting Gradle build..."
|
||||
|
||||
# Capture build output
|
||||
if ./gradlew build --quiet --console=plain --parallel 2>&1 | tee build.log; then
|
||||
print_status "Build completed successfully!"
|
||||
return 0
|
||||
else
|
||||
print_error "Build failed!"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Analyze build results
|
||||
analyze_results() {
|
||||
if [ -f "build.log" ]; then
|
||||
# Extract key error information
|
||||
errors=$(grep -c "ERROR" build.log || true)
|
||||
warnings=$(grep -c "WARNING" build.log || true)
|
||||
|
||||
if [ "$errors" -gt 0 ]; then
|
||||
print_error "Found $errors errors in build log"
|
||||
echo "Top errors:"
|
||||
grep "ERROR" build.log | head -5
|
||||
fi
|
||||
|
||||
if [ "$warnings" -gt 0 ]; then
|
||||
print_warning "Found $warnings warnings in build log"
|
||||
fi
|
||||
|
||||
# Check for specific common issues
|
||||
if grep -q "Unresolved reference" build.log; then
|
||||
print_error "Found unresolved references - check imports and dependencies"
|
||||
fi
|
||||
|
||||
if grep -q "MissingTranslation" build.log; then
|
||||
print_error "Found missing translations - check string resources"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
echo "========================================"
|
||||
echo " HomeboxLens Smart Build System"
|
||||
echo "========================================"
|
||||
|
||||
check_prerequisites
|
||||
clean_build
|
||||
|
||||
if run_build; then
|
||||
analyze_results
|
||||
print_status "Build successful!"
|
||||
exit 0
|
||||
else
|
||||
analyze_results
|
||||
print_error "Build failed. Check build.log for details."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user