Allow deleting target when deploying npm
This commit is contained in:
parent
abfd840163
commit
9ec45947d1
22
deploy-npm
22
deploy-npm
|
@ -1,9 +1,17 @@
|
|||
#!/usr/local/bin/bash
|
||||
# $1 = destination
|
||||
# Usage: deploy-npm [--delete-target] target
|
||||
|
||||
# Parse input
|
||||
if [ "$1" == "--delete-target" ]; then
|
||||
delete_target=1
|
||||
dst_dir="$2"
|
||||
else
|
||||
delete-target=0
|
||||
dst_dir="$1"
|
||||
fi
|
||||
|
||||
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($repo_name)"
|
||||
|
@ -11,6 +19,7 @@ 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
|
||||
|
@ -28,9 +37,16 @@ cd "$tmp_dir" || exit
|
|||
npm ci
|
||||
npm run deploy
|
||||
|
||||
if [ $delete_target -eq 1 ]; then
|
||||
echo "[[ Deploy ]] Deleting then recreating '$dst_dir'."
|
||||
rm -rf "$dst_dir"
|
||||
mkdir "$dst_dir"
|
||||
chmod g+w "$dst_dir/"
|
||||
fi
|
||||
|
||||
echo "[[ Deploy ]] Copying files from '$tmp_dir/dist' to '$dst_dir'."
|
||||
chmod -R g+w "dist/"
|
||||
cp -r dist/ "$dst_dir"
|
||||
chmod -R g+w "$dst_dir"
|
||||
|
||||
echo "[[ Deploy ]] Deleting '$tmp_dir'."
|
||||
rm -rf "$tmp_dir"
|
||||
|
|
Loading…
Reference in New Issue