|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Define colors using ANSI escape codes |
| 4 | +RED='\033[0;31m' |
| 5 | +GREEN='\033[0;32m' |
| 6 | +MAGENTA='\033[0;35m' |
| 7 | +YELLOW='\033[0;33m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +update_version_fields() { |
| 11 | + local file="$1" |
| 12 | + local version="$2" |
| 13 | + local release_date="$(date +"%Y-%m-%d")" |
| 14 | + |
| 15 | + echo "-------------------------------------------------------------" |
| 16 | + echo -e "${GREEN}[INF] - Starting the script for ($file)!${NC}" |
| 17 | + |
| 18 | + # Get the original content of the JSON file |
| 19 | + original_content=$(<"$file") |
| 20 | + |
| 21 | + # Update the fields in the JSON file |
| 22 | + echo -e "${GREEN}[INF] - Updating the version in the file ...${NC}" |
| 23 | + sed -i "s/\"version\": \".*\"/\"version\": \"$version\"/" "$file" |
| 24 | + sed -i "s/\"releaseDate\": \".*\"/\"releaseDate\": \"$release_date\"/" "$file" |
| 25 | + |
| 26 | + # Get the updated content of the JSON file |
| 27 | + updated_content=$(<"$file") |
| 28 | + |
| 29 | + # Display only the differences between the original and updated content |
| 30 | + if [ "$original_content" != "$updated_content" ] |
| 31 | + then |
| 32 | + echo -e "${GREEN}[INF] - The following are the changes made to the file:${NC}" |
| 33 | + diff --color --palette=':ad=\033[0;35:de=\033[0;31:ln=\033[0' <(echo "$original_content") <(echo "$updated_content") |
| 34 | + else |
| 35 | + echo -e "${YELLOW}[WRN] - Nothing to do, the file is up to date!${NC}" |
| 36 | + fi |
| 37 | + |
| 38 | + echo -e "${GREEN}[INF] - Done.${NC}" |
| 39 | + echo -e "-------------------------------------------------------------\n" |
| 40 | +} |
| 41 | + |
| 42 | +# BEGINING |
| 43 | +#---------------------------------- |
| 44 | +if [ $# -ne 1 ] |
| 45 | +then |
| 46 | + echo -e "${RED}[ERR] - Usage: $0 <version>${NC}" |
| 47 | + exit 1 |
| 48 | +fi |
| 49 | + |
| 50 | +VERSION="$1" |
| 51 | +BASE_FOLDER=. |
| 52 | + |
| 53 | +if find "$PWD" -maxdepth 1 -type f -name "*.sh" | read; then |
| 54 | + echo -e "${YELLOW}[WRN] - Adjusting the files path!${NC}" |
| 55 | + BASE_FOLDER=.. |
| 56 | +fi |
| 57 | + |
| 58 | +SERVER_FILE_PATH=$BASE_FOLDER/src/server/package.json |
| 59 | +WEB_FILE_PATH=$BASE_FOLDER/src/clients/web/package.json |
| 60 | +MOBILE_FILE_PATH=$BASE_FOLDER/src/clients/mobile/package.json |
| 61 | + |
| 62 | +# Check if JSON file exists |
| 63 | +if [[ ! -f "$SERVER_FILE_PATH" || ! -f "$WEB_FILE_PATH" || ! -f "$MOBILE_FILE_PATH" ]] |
| 64 | +then |
| 65 | + echo -e "${RED}[ERR] - All of the following files are required \n[\n "$SERVER_FILE_PATH",\n "$WEB_FILE_PATH",\n "$MOBILE_FILE_PATH"\n]${NC}" |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +update_version_fields $SERVER_FILE_PATH $VERSION |
| 70 | +update_version_fields $WEB_FILE_PATH $VERSION |
| 71 | +update_version_fields $MOBILE_FILE_PATH $VERSION |
0 commit comments