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:
Ho Ngoc Hai
2025-12-27 10:26:04 +07:00
parent 29c40ea681
commit 5ff8035013
6 changed files with 81 additions and 89 deletions

View File

@@ -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
View 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