2022-10-31 10:17:07 +00:00
|
|
|
#/!bin/bash
|
|
|
|
## 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-12 16:30:39 +00:00
|
|
|
#cp -r {.env,app.js,package.json,server,public} dist/
|
2023-01-12 16:42:44 +00:00
|
|
|
cp -r ./* dist/
|
2022-10-31 10:17:07 +00:00
|
|
|
|
|
|
|
#Add version control for pm2
|
|
|
|
cd dist
|
|
|
|
#Add version control for pm2
|
|
|
|
version=$(git describe)
|
|
|
|
file_pkg="package.json"
|
|
|
|
key=" \"version\": \""
|
|
|
|
|
|
|
|
count=$(echo ${version%%-*} | grep -o "\." | wc -l)
|
|
|
|
if (( $count > 1 )); then
|
|
|
|
version=${version%%-*}
|
|
|
|
else
|
|
|
|
version="${version%%-*}.0"
|
|
|
|
fi
|
|
|
|
if [ -f "$file_pkg" ] && [ ! -z "$version" ]; then
|
|
|
|
version=" \"version\": \"$version\","
|
|
|
|
sed -i "s|^.*$key.*|${version//\//\\/}|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
|
|
|
|
|
|
|
|
## POST BUILD
|
|
|
|
|
2023-01-12 16:30:39 +00:00
|
|
|
cd -
|