-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevtools.sh
executable file
·124 lines (107 loc) · 2.73 KB
/
devtools.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
set -e -u
script_path="$(cd "$(dirname "$0")" && pwd)"
print_usage() {
echo "$0 [options] [command]"
echo
echo "Commands:"
echo " init Setup environment"
echo " bump [Ver] Bump version"
echo
echo "Options:"
echo " -h, --help print this message"
echo
}
# change_json [file] [key] [value]
change_json() {
tmpjson="$(mktemp)"
cat "$1" > "$tmpjson"
jq "$2 |= \"$3\"" "$tmpjson" > "$1"
rm "$tmpjson"
}
init_command() {
echo "Setup GitHooks" >&2
git config core.hooksPath .githooks
if ! which volta 2> /dev/null 1>&2; then
echo "Please install Volta at first" >&2
echo "https://volta.sh/" >&2
exit 1
fi
echo "Install Node.js" >&2
volta install node@lts
echo "Install dependencies" >&2
volta install pnpm
pnpm install
}
bump_command() {
# Check jq
if ! which jq 2> /dev/null 1>&2; then
echo "Please install jq at first" >&2
echo "https://jqlang.github.io/jq/" >&2
exit 1
fi
# Check arguments
if [ $# -ne 1 ]; then
echo "Usage: $0 bump [Ver]" >&2
exit 1
fi
# Change package.json
echo "Bump version in package.json to $1" >&2
#pnpm version "$1" --no-git-tag-version --no-commit-hooks
change_json "$script_path/package.json" ".version" "$1"
# Change manifest.json
echo "Bump version in manifest.json to $1" >&2
for manifest in "$script_path/public/manifest_chrome.json" "$script_path/public/manifest_firefox.json"; do
change_json "$manifest" ".version" "$1"
done
echo "Format files" >&2
pnpm prettier --write "$script_path/package.json" "$script_path/public/manifest_chrome.json" "$script_path/public/manifest_firefox.json"
return 0
}
main() {
_short="" _long="" _noopts="" _cmd="" _cmdargs=""
while true; do
case "${1-""}" in
"-h" | "--help")
print_usage
shift 1
exit 0
;;
"")
break
;;
*)
_noopts="${_noopts-""}${1} "
shift 1
;;
esac
done
eval set -- "${_noopts-""}"
_cmd="${1-""}"
if [ $# -ge 1 ]; then
shift 1
fi
case "${_cmd-""}" in
"init")
init_command "$@"
;;
"bump")
bump_command "$@"
;;
"help")
print_usage
exit 0
;;
"")
echo "No command specified" >&2
print_usage >&2
exit 1
;;
*)
echo "Unknown command: ${_cmd}" >&2
print_usage >&2
exit 1
;;
esac
}
main "$@"