Remove local development README and enhance scripts for cross-platform compatibility
- Deleted `README.md` for local development setup as it was deemed unnecessary. - Updated `setup-neon.sh`, `start-all.sh`, and `create-service.sh` scripts to source an OS helper for improved cross-platform command execution. - Modified commands in `init-project.sh` to reflect the new script structure for starting services.
This commit is contained in:
@@ -5,6 +5,9 @@ set -e
|
||||
echo "🚀 Neon Database Setup Script"
|
||||
echo ""
|
||||
|
||||
# Source OS helper
|
||||
source "$(dirname "$0")/../utils/os-helper.sh"
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
@@ -40,8 +43,7 @@ if [ -n "$dev_url" ]; then
|
||||
# EN: Update .env.local with new URL
|
||||
# VI: Cập nhật .env.local với URL mới
|
||||
if grep -q "DATABASE_URL=" "$ENV_LOCAL"; then
|
||||
sed -i.bak "s|DATABASE_URL=.*|DATABASE_URL=$dev_url|" "$ENV_LOCAL"
|
||||
rm -f "${ENV_LOCAL}.bak"
|
||||
run_sed "s|DATABASE_URL=.*|DATABASE_URL=$dev_url|" "$ENV_LOCAL"
|
||||
else
|
||||
echo "DATABASE_URL=$dev_url" >> "$ENV_LOCAL"
|
||||
fi
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Source OS helper for cross-platform commands
|
||||
source "$(dirname "$0")/../utils/os-helper.sh"
|
||||
|
||||
echo "🚀 Starting all services... / Khởi động tất cả services..."
|
||||
|
||||
# EN: Verify Docker daemon is running
|
||||
@@ -38,7 +41,7 @@ fi
|
||||
# VI: Khởi động infrastructure services (Redis cho caching, Traefik cho routing)
|
||||
echo "📦 Starting infrastructure (Redis, Traefik)... / Khởi động infrastructure (Redis, Traefik)..."
|
||||
cd deployments/local
|
||||
docker-compose up -d
|
||||
run_compose up -d
|
||||
cd ../..
|
||||
|
||||
# EN: Give Redis time to fully start before starting services
|
||||
|
||||
@@ -54,7 +54,7 @@ echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Setup Neon database: ./scripts/db/setup-neon.sh"
|
||||
echo "2. Update .env files with your Neon DATABASE_URL"
|
||||
echo "3. Start infrastructure: cd deployments/local && docker-compose up -d"
|
||||
echo "3. Start all services: ./scripts/dev/start-all.sh"
|
||||
echo "4. Run migrations: ./scripts/db/migrate.sh auth-service dev"
|
||||
echo "5. Seed database: ./scripts/db/seed.sh auth-service"
|
||||
echo "6. Start services: pnpm dev"
|
||||
|
||||
@@ -4,6 +4,9 @@ set -e
|
||||
|
||||
SERVICE_NAME=$1
|
||||
|
||||
# Source OS helper for cross-platform commands
|
||||
source "$(dirname "$0")/os-helper.sh"
|
||||
|
||||
# EN: Validate arguments
|
||||
# VI: Xác thực tham số
|
||||
if [ -z "$SERVICE_NAME" ]; then
|
||||
@@ -30,13 +33,11 @@ cp -r services/_template "$SERVICE_DIR"
|
||||
# EN: Update package.json
|
||||
# VI: Cập nhật package.json
|
||||
cd "$SERVICE_DIR"
|
||||
sed -i.bak "s/@goodgo\/service-template/@goodgo\/$SERVICE_NAME/g" package.json
|
||||
rm package.json.bak
|
||||
run_sed "s/@goodgo\/service-template/@goodgo\/$SERVICE_NAME/g" package.json
|
||||
|
||||
# EN: Update .env.example
|
||||
# VI: Cập nhật .env.example
|
||||
sed -i.bak "s/SERVICE_NAME=service-name/SERVICE_NAME=$SERVICE_NAME/g" .env.example 2>/dev/null || true
|
||||
rm .env.example.bak 2>/dev/null || true
|
||||
run_sed "s/SERVICE_NAME=service-name/SERVICE_NAME=$SERVICE_NAME/g" .env.example
|
||||
|
||||
# EN: Update Dockerfile port if needed
|
||||
# VI: Cập nhật port Dockerfile nếu cần
|
||||
|
||||
67
scripts/utils/os-helper.sh
Executable file
67
scripts/utils/os-helper.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
# EN: OS Detection and Compatibility Helper
|
||||
# VI: Helper phát hiện Hệ điều hành và Tương thích
|
||||
|
||||
OS="$(uname -s)"
|
||||
case "${OS}" in
|
||||
Linux*) OS_TYPE=Linux;;
|
||||
Darwin*) OS_TYPE=Mac;;
|
||||
CYGWIN*) OS_TYPE=Cygwin;;
|
||||
MINGW*) OS_TYPE=MinGw;;
|
||||
*) OS_TYPE="UNKNOWN:${OS}"
|
||||
esac
|
||||
|
||||
# EN: Logging function
|
||||
# VI: Hàm logging
|
||||
log_info() {
|
||||
echo -e "\033[0;32m[INFO]\033[0m $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "\033[1;33m[WARN]\033[0m $1"
|
||||
}
|
||||
|
||||
# EN: Cross-platform SED command
|
||||
# VI: Lệnh SED đa nền tảng
|
||||
# Usage: run_sed "s/find/replace/g" filename
|
||||
run_sed() {
|
||||
if [ "$OS_TYPE" = "Mac" ]; then
|
||||
sed -i '' "$1" "$2"
|
||||
else
|
||||
sed -i "$1" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
# EN: Cross-platform OPEN command (open URL or file)
|
||||
# VI: Lệnh OPEN đa nền tảng (mở URL hoặc file)
|
||||
run_open() {
|
||||
if [ "$OS_TYPE" = "Mac" ]; then
|
||||
open "$1"
|
||||
elif [ "$OS_TYPE" = "Linux" ]; then
|
||||
xdg-open "$1"
|
||||
else
|
||||
echo "Cannot open $1 on $OS_TYPE"
|
||||
fi
|
||||
}
|
||||
|
||||
export OS_TYPE
|
||||
export -f run_sed
|
||||
export -f run_open
|
||||
export -f log_info
|
||||
export -f log_warn
|
||||
|
||||
# EN: Cross-platform Docker Compose command
|
||||
# VI: Lệnh Docker Compose đa nền tảng
|
||||
run_compose() {
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
docker-compose "$@"
|
||||
elif docker compose version &> /dev/null; then
|
||||
docker compose "$@"
|
||||
else
|
||||
echo -e "\033[0;31m[ERROR]\033[0m Docker Compose not found / Không tìm thấy Docker Compose"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
export -f run_compose
|
||||
Reference in New Issue
Block a user