feat: Add polyglot support to dev and build scripts for Node.js and .NET services.
This commit is contained in:
@@ -1,11 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
# Build All Services (Polyglot: Node.js & .NET)
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
source "$(dirname "$0")/../utils/os-helper.sh"
|
||||
|
||||
echo "🔨 Building all services and apps..."
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# 1. Build Node.js / TypeScript Projects (pnpm workspace)
|
||||
# -----------------------------------------------------------------------------
|
||||
echo "📦 Building Node.js packages..."
|
||||
# EN: Build all packages using pnpm workspace
|
||||
# VI: Build tất cả các package sử dụng pnpm workspace
|
||||
pnpm build
|
||||
if command -v pnpm &> /dev/null; then
|
||||
pnpm build
|
||||
else
|
||||
echo "⚠️ pnpm not found. Skipping Node.js build."
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# 2. Build .NET Services
|
||||
# -----------------------------------------------------------------------------
|
||||
echo "📦 Building .NET services..."
|
||||
|
||||
if command -v dotnet &> /dev/null; then
|
||||
# Find all directories in services/ that contain a .sln or .csproj file
|
||||
# and do NOT contain a package.json (or we can build both if mixed)
|
||||
|
||||
count=0
|
||||
|
||||
# EN: Iterate over direct subdirectories of services/
|
||||
# VI: Duyệt qua các thư mục con trực tiếp của services/
|
||||
for service_dir in services/*; do
|
||||
if [ -d "$service_dir" ]; then
|
||||
# Check for .NET solution or project files
|
||||
if compgen -G "$service_dir/*.sln" > /dev/null || compgen -G "$service_dir/*.csproj" > /dev/null || compgen -G "$service_dir/src/*.sln" > /dev/null; then
|
||||
service_name=$(basename "$service_dir")
|
||||
|
||||
# Optimization: specific check to avoid building node apps again if they were mixed (unlikely here but safety first)
|
||||
# In this repo, .NET services don't have package.json usually.
|
||||
|
||||
echo " 👉 Building .NET service: $service_name"
|
||||
# Use dotnet build on the directory (it finds sln/csproj auto) or specific path
|
||||
if compgen -G "$service_dir/*.sln" > /dev/null; then
|
||||
dotnet build "$service_dir" -v m
|
||||
elif [ -d "$service_dir/src" ]; then
|
||||
# Common pattern: service/src/Service.sln
|
||||
dotnet build "$service_dir/src" -v m
|
||||
else
|
||||
dotnet build "$service_dir" -v m
|
||||
fi
|
||||
|
||||
count=$((count + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
echo " (No .NET services found to build)"
|
||||
else
|
||||
echo " ✅ Built $count .NET services."
|
||||
fi
|
||||
|
||||
else
|
||||
echo "⚠️ dotnet SDK not found. Skipping .NET build."
|
||||
fi
|
||||
|
||||
echo "✅ Build completed!"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# =============================================================================
|
||||
# Build Single Service (Polyglot)
|
||||
# =============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
SERVICE=$1
|
||||
@@ -8,21 +12,62 @@ SERVICE=$1
|
||||
# VI: Xác thực tham số
|
||||
if [ -z "$SERVICE" ]; then
|
||||
echo "Usage: $0 <service-name>"
|
||||
echo "Example: $0 auth-service"
|
||||
echo "Example:"
|
||||
echo " $0 auth-service (Node.js)"
|
||||
echo " $0 mission-service-net (.NET)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# EN: Check if service exists
|
||||
# VI: Kiểm tra xem service có tồn tại không
|
||||
if [ ! -d "services/$SERVICE" ]; then
|
||||
echo "❌ Service $SERVICE not found"
|
||||
SERVICE_PATH="services/$SERVICE"
|
||||
if [ ! -d "$SERVICE_PATH" ]; then
|
||||
echo "❌ Service $SERVICE not found in services/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🔨 Building $SERVICE..."
|
||||
|
||||
# EN: Build specific service using pnpm filter
|
||||
# VI: Build service cụ thể sử dụng pnpm filter
|
||||
pnpm --filter "@goodgo/$SERVICE" build
|
||||
# -----------------------------------------------------------------------------
|
||||
# Detect Project Type & Build
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
echo "✅ Build completed!"
|
||||
BUILT=false
|
||||
|
||||
# 1. Check for Node.js (package.json)
|
||||
if [ -f "$SERVICE_PATH/package.json" ]; then
|
||||
echo " 📦 Detected Node.js project"
|
||||
# EN: Build specific service using pnpm filter
|
||||
# VI: Build service cụ thể sử dụng pnpm filter
|
||||
if pnpm --filter "@goodgo/$SERVICE" build; then
|
||||
BUILT=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. Check for .NET (Solution or CSPROJ)
|
||||
if [ -f "$SERVICE_PATH"/*.sln ] || compgen -G "$SERVICE_PATH/*.sln" > /dev/null || \
|
||||
[ -f "$SERVICE_PATH"/*.csproj ] || compgen -G "$SERVICE_PATH/src/*.sln" > /dev/null; then
|
||||
|
||||
# If not already built (or if it's a mixed project, we might want to build both,
|
||||
# but usually it's one or the other. Let's assume .NET if found).
|
||||
# If we already built Node, we still try .NET just in case?
|
||||
# Let's say yes for completeness, though rare.
|
||||
|
||||
echo " 📦 Detected .NET project"
|
||||
|
||||
TARGET_BUILD="$SERVICE_PATH"
|
||||
if [ -d "$SERVICE_PATH/src" ] && compgen -G "$SERVICE_PATH/src/*.sln" > /dev/null; then
|
||||
TARGET_BUILD="$SERVICE_PATH/src"
|
||||
fi
|
||||
|
||||
if dotnet build "$TARGET_BUILD"; then
|
||||
BUILT=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$BUILT" = true ]; then
|
||||
echo "✅ Build completed for $SERVICE!"
|
||||
else
|
||||
echo "❌ Could not determine how to build $SERVICE (no package.json or .sln/.csproj found)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user