Add versioned deployment for template

This commit is contained in:
Florine W. Dekker 2021-04-15 19:00:29 +02:00
parent e2a25bebf1
commit a5b660694f
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
2 changed files with 42 additions and 1 deletions

View File

@ -6,7 +6,7 @@ repo_name="$(basename -s .git "$repo_dir")"
dst_dir="$1"
tmp_dir="$HOME/tmp/git/$repo_name-$(date +%s)"
echo "[[ Deploy ]] static($repo_name)"
echo "[[ Deploy ]] npm($repo_name)"
echo "[[ Deploy ]] src: '$repo_dir'"
echo "[[ Deploy ]] dst: '$dst_dir'"
echo "[[ Deploy ]] tmp: '$tmp_dir'"

41
deploy-npm-versioned Executable file
View File

@ -0,0 +1,41 @@
#!/usr/local/bin/bash
# $1 = destination
repo_dir="$(pwd)"
repo_name="$(basename -s .git "$repo_dir")"
dst_dir="$1"
tmp_dir="$HOME/tmp/git/$repo_name-$(date +%s)"
echo "[[ Deploy ]] npm-versioned($repo_name)"
echo "[[ Deploy ]] src: '$repo_dir'"
echo "[[ Deploy ]] dst: '$dst_dir'"
echo "[[ Deploy ]] tmp: '$tmp_dir'"
if test -e "$tmp_dir"; then
echo "[[ Deploy ]] Directory '$tmp_dir' already exists, stopping deployment."
exit
fi
echo "[[ Deploy ]] Creating directories '$dst_dir' and '$tmp_dir'."
mkdir -p "$dst_dir" "$tmp_dir"
echo "[[ Deploy ]] Cloning repository at '$repo_dir' into '$tmp_dir'."
git clone "$repo_dir" "$tmp_dir"
echo "[[ Deploy ]] Deploying npm at '$tmp_dir' into '$tmp_dir/dist'."
cd "$tmp_dir" || exit
npm ci
npm run deploy
echo "[[ Deploy ]] Extracting version info."
read -r major minor patch <<< "$(node -pe "require('./package.json').version" | awk '{split($0, a, "[\.\-\+]"); print a[1], a[2], a[3]}')"
dst_dirs="$dst_dir/$major.$minor.$patch $dst_dir/$major.$minor.x $dst_dir/$major.x.x"
echo "[[ Deploy ]] Copying files from '$tmp_dir/dist' to the following directories: $dst_dirs"
echo "$dst_dirs" | xargs -n 1 rm -rf
echo "$dst_dirs" | xargs -n 1 cp -r dist/
echo "$dst_dirs" | xargs -n 1 chmod -R g+w
echo "[[ Deploy ]] Deleting '$tmp_dir'."
rm -rf "$tmp_dir"