Assist_Design/scripts/type-check-incremental.sh
T. Narantuya ed6fae677d Enhance memory management and refactor components for improved performance
- Updated package.json scripts to optimize memory usage during type-checking and building processes.
- Refactored BFF application scripts to include memory management options for build, dev, and test commands.
- Introduced new type-check scripts for better memory handling in the BFF application.
- Reorganized imports and components in the portal application for better structure and maintainability.
- Replaced large component files with dedicated view components to streamline rendering and improve load times.
2025-09-18 12:34:26 +09:00

166 lines
4.7 KiB
Bash
Executable File

#!/bin/bash
# Incremental File-by-File TypeScript Checking
# This script checks TypeScript files in smaller batches to avoid memory issues
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔧 Incremental TypeScript Type Checking${NC}"
echo "=============================================="
# Function to check TypeScript files in batches
check_files_batch() {
local project_path=$1
local batch_size=${2:-10}
echo -e "${BLUE}🔍 Checking files in batches of $batch_size: $project_path${NC}"
cd "$project_path"
# Set conservative memory limit
export NODE_OPTIONS="--max-old-space-size=2048"
# Find all TypeScript files
local ts_files=($(find src -name "*.ts" -not -path "*/node_modules/*" -not -name "*.spec.ts" -not -name "*.test.ts" | head -50))
local total_files=${#ts_files[@]}
if [ $total_files -eq 0 ]; then
echo -e "${YELLOW}⚠️ No TypeScript files found${NC}"
return 0
fi
echo -e "${BLUE}Found $total_files TypeScript files${NC}"
# Process files in batches
local batch_count=0
local failed_files=()
for ((i=0; i<$total_files; i+=$batch_size)); do
batch_count=$((batch_count + 1))
local batch_files=("${ts_files[@]:$i:$batch_size}")
local batch_file_count=${#batch_files[@]}
echo -e "${YELLOW}Batch $batch_count: Checking $batch_file_count files...${NC}"
# Create temporary tsconfig for this batch
cat > tsconfig.batch.json << EOF
{
"extends": "./tsconfig.ultra-light.json",
"include": [$(printf '"%s",' "${batch_files[@]}" | sed 's/,$//')]
}
EOF
# Check this batch
if npx tsc --noEmit -p tsconfig.batch.json 2>/dev/null; then
echo -e "${GREEN}✅ Batch $batch_count passed${NC}"
else
echo -e "${RED}❌ Batch $batch_count failed${NC}"
failed_files+=("${batch_files[@]}")
fi
# Clean up
rm -f tsconfig.batch.json
# Small delay to let memory settle
sleep 1
done
# Report results
if [ ${#failed_files[@]} -eq 0 ]; then
echo -e "${GREEN}✅ All batches passed successfully!${NC}"
return 0
else
echo -e "${RED}${#failed_files[@]} files had issues:${NC}"
printf '%s\n' "${failed_files[@]}"
return 1
fi
}
# Function to check only syntax (fastest)
check_syntax_only() {
local project_path=$1
echo -e "${BLUE}🔍 Syntax-only check: $project_path${NC}"
cd "$project_path"
export NODE_OPTIONS="--max-old-space-size=1024"
# Use TypeScript's syntax-only mode
if npx tsc --noEmit --skipLibCheck --skipDefaultLibCheck --noResolve --isolatedModules src/**/*.ts 2>/dev/null; then
echo -e "${GREEN}✅ Syntax check passed${NC}"
return 0
else
echo -e "${RED}❌ Syntax errors found${NC}"
return 1
fi
}
# Function to check specific files only
check_specific_files() {
local project_path=$1
shift
local files=("$@")
echo -e "${BLUE}🔍 Checking specific files: $project_path${NC}"
cd "$project_path"
export NODE_OPTIONS="--max-old-space-size=1024"
for file in "${files[@]}"; do
if [ -f "$file" ]; then
echo -e "${YELLOW}Checking: $file${NC}"
if npx tsc --noEmit --skipLibCheck "$file" 2>/dev/null; then
echo -e "${GREEN}$file passed${NC}"
else
echo -e "${RED}$file failed${NC}"
fi
fi
done
}
# Main execution
main() {
local command=${1:-"batch"}
local target=${2:-"apps/bff"}
local batch_size=${3:-5}
case $command in
"syntax")
check_syntax_only "$target"
;;
"batch")
check_files_batch "$target" "$batch_size"
;;
"files")
shift 2
check_specific_files "$target" "$@"
;;
"help"|*)
echo "Usage: $0 [command] [target] [options...]"
echo ""
echo "Commands:"
echo " batch - Check files in small batches (default)"
echo " syntax - Check syntax only (fastest)"
echo " files - Check specific files"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " $0 batch apps/bff 5 # Check BFF in batches of 5"
echo " $0 syntax apps/bff # Syntax check only"
echo " $0 files apps/bff src/main.ts # Check specific file"
;;
esac
}
# Run main function with all arguments
main "$@"