mediasoup/build.sh

76 lines
1.9 KiB
Bash
Raw Permalink Normal View History

2022-10-31 10:17:07 +00:00
#/!bin/bash
2023-04-04 22:57:58 +00:00
## FUNCTIONS
function getGitVersion(){
version=$(git describe)
count=$(echo ${version%%-*} | grep -o "\." | wc -l)
if (( $count > 1 )); then
version=${version%%-*}
elif (( $count == 0 ));then
echo -e "Error: Git version \"${version%%-*}\" not respecting Safemobile standard.\n Must be like 4.xx or 4.xx.xx"
version="0.0.0"
else
if [[ "$1" == "dev" ]];then
cleanprefix=${version#*-} # remove everything before `-` including `-`
cleansuffix=${cleanprefix%-*} # remove everything after `-` including `-`
version="${version%%-*}.${cleansuffix}"
else
version="${version%%-*}.0" # one `%` remove everything after last `-`, two `%%` remove everything after all `-`
fi
fi
}
function addVersionPm2(){
file_pkg="package.json"
key=" \"version\": \""
if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then
versionApp=" \"version\": \"$version\","
sed -i "s|^.*$key.*|${versionApp//\//\\/}|g" $file_pkg
text=$(cat $file_pkg | grep -c "$version")
if [ $text -eq 0 ]; then
echo "Version couldn't be set"
else
echo "Version $version successfully applied to App"
fi
fi
}
2022-10-31 10:17:07 +00:00
## PREBUILD PROCESS
# check dist dir to be present and empty
if [ ! -d "dist" ]; then
## MAKE DIR
mkdir "dist"
echo "Directory dist created."
else
## CLEANUP
rm -fr dist/*
fi
2023-01-12 16:30:39 +00:00
if [ -d "node_modules" ]; then
rm -fr node_modules
fi
2022-10-31 10:17:07 +00:00
# Install dependencies
#npm install
## PROJECT NEEDS
echo "Building app... from $(git rev-parse --abbrev-ref HEAD)"
#npm run-script build
2023-01-17 15:51:55 +00:00
cp -r {.env,app.js,package.json,server,public,doc,Dockerfile} dist/
#cp -r ./* dist/
2023-04-04 22:57:58 +00:00
# Generate Git log
dateString=$(date +"%Y%m%d-%H%M%S")
2023-04-04 22:57:58 +00:00
git log --pretty=format:"%ad%x09%an%x09%s" --no-merges -20 > "dist/git-$dateString.log"
# Get Git version control
getGitVersion $1
# Add version control for pm2
2022-10-31 10:17:07 +00:00
cd dist
2023-04-04 22:57:58 +00:00
addVersionPm2
2022-10-31 10:17:07 +00:00
## POST BUILD
2023-01-12 16:30:39 +00:00
cd -