UNPKG

2.84 kBapplication/x-shView Raw
1#!/bin/bash
2BOLD=$(tput bold)
3RESET=$(tput sgr0)
4RED=$(tput setaf 1)
5GREEN=$(tput setaf 2)
6
7echo "============================================================"
8echo "${BOLD}${PWD##*/}${RESET}"
9echo "============================================================"
10
11#============================================================
12# serve with hot reload at localhost:4020
13#============================================================
14npm_run_dev() {
15 while true; do
16 printf "\n"
17 read -p "${BOLD}${GREEN}npm run dev? (Y/n) ${RESET}" yn
18 case ${yn} in
19 [Yy]* ) cd docs && npm run dev && cd -; break;;
20 [Nn]* ) return 0;;
21 * ) echo "Please answer yes or no.";;
22 esac
23 done
24}
25
26#============================================================
27# build for production with minification
28#============================================================
29npm_run_build() {
30 while true; do
31 printf "\n"
32 read -p "${BOLD}${GREEN}npm run build? (Y/n) ${RESET}" yn
33 case ${yn} in
34 [Yy]* ) cd docs && npm run build && cd -; break;;
35 [Nn]* ) return 0;;
36 * ) echo "Please answer yes or no.";;
37 esac
38 done
39}
40
41#============================================================
42# git commit
43#============================================================
44git_commit() {
45 while true; do
46 printf "\n"
47 read -p "${BOLD}${GREEN}git commit? (Y/n) ${RESET}" yn
48 case ${yn} in
49 [Yy]* )
50 IFS= read -r -p "${BOLD}Enter commit message: ${RESET}" commitmsg
51
52 # if commitmsg empty
53 if [ -z "$commitmsg" ]
54 then
55 echo "${BOLD}${RED}Commit message is empty.${RESET}"
56 commitmsg="Add files via upload"
57 fi
58
59 printf "\n"
60 git add .
61 git commit -m "$commitmsg"
62 break;;
63
64 [Nn]* ) return 0;;
65 * ) echo "Please answer yes or no.";;
66 esac
67 done
68}
69
70#============================================================
71# git push
72#============================================================
73git_push() {
74 while true; do
75 printf "\n"
76 read -p "${BOLD}${GREEN}git push? (Y/n) ${RESET}" yn
77 case ${yn} in
78 [Yy]* ) git push; break;;
79 [Nn]* ) return 0;;
80 * ) echo "Please answer yes or no.";;
81 esac
82 done
83}
84
85#============================================================
86# npm publish
87#============================================================
88npm_publish() {
89 while true; do
90 printf "\n"
91 read -p "${BOLD}${GREEN}npm publish? (Y/n) ${RESET}" yn
92 case ${yn} in
93 [Yy]* ) npm publish; break;;
94 [Nn]* ) return 0;;
95 * ) echo "Please answer yes or no.";;
96 esac
97 done
98}
99
100#============================================================
101# main
102#============================================================
103main() {
104 npm_run_dev
105 npm_run_build
106 git_commit
107 git_push
108 npm_publish
109}
110
111main