-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_dist_to_gh-pages.sh
executable file
·51 lines (42 loc) · 1.46 KB
/
push_dist_to_gh-pages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# https://gist.github.com/cobyism/4730490#gistcomment-1374989 current
# https://gist.github.com/cobyism/4730490#gistcomment-1394421 better but you don't have set up that way currently
branch="gh-pages"
output="dist"
if [ $(git status --porcelain | wc -l) -eq "0" ]; then
echo -e " 🟢 Git repo is clean.\n"
else
echo " 🔴 Git repo dirty. Quit"
exit 1
fi
function subtree_push() {
git subtree push --prefix $output origin $branch
}
function subtree_split() {
git push origin $(git subtree split --prefix $output master):gh-pages --force
}
function is_in_remote() {
local git_command="git ls-remote --heads origin ${branch}"
local existed_in_remote=$($git_command)
if [[ ${existed_in_remote} ]]; then
echo "\nremote branch $branch exists"
echo "\n$git_command\n"
echo -e "\n$existed_in_remote\n"
echo -e "\nupdate $branch against a rebased master branch\n"
subtree_split
else
echo -e "\nthere's no remote branch $branch\n"
subtree_push
fi
}
echo -e "\nbuilding $output...\n" &&
npm run build &&
echo -e "\ntracking $output by removing it in gitingore\n"
sed -i -- 's/dist//g' ./.gitignore &&
git add . &&
echo -e "\ncommitting $output in order to push dist subtree for $branch...\n"
git commit -m "update $output subtree for $branch" &&
is_in_remote
echo -e "\nremoving $output commit, reseting to previous commit\n"
git reset --hard HEAD~1
echo -e "\nComplete!"