-
Notifications
You must be signed in to change notification settings - Fork 4
/
publish.sh
executable file
·80 lines (64 loc) · 1.51 KB
/
publish.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
#!/usr/bin/env bash
function usage() {
echo "
Usage: $(basename $0) <name> <description> <author>
"
}
function testCommand() {
if ! command -v $1 &> /dev/null
then
echo "\n\nPlease install $1 command first!"
exit 1
fi
}
testCommand jq
testCommand git
if [ -f package.json.orig ]; then
echo "Can run this program only once! Restore original package.json.orig before continue"
exit 1;
fi
if [[ ! $# -eq 3 ]] ; then
usage
exit 1
fi
# Sanitize JSON
NAME=`echo -n "$1" | jq -Rsa .`
DESCRIPTION=`echo -n "$2" | jq -Rsa .`
AUTHOR=`echo -n "$3" | jq -Rsa .`
GIT_URL=`git remote get-url origin`
REMOTE=`echo -n $GIT_URL | jq -Rsa .`
if [[ "$REMOT2E" == *"ts-express-boilerplate.git"* ]]; then
echo "
Please initialize git repository with a remote url.
git init .
git remote set-url origin <url>
"
exit 1
fi
tmp=$(mktemp)
cp package.json package.json.orig
jq '.author='"$AUTHOR"'|.name='"$NAME"'|.description='"$DESCRIPTION"'|.repository.url='"$REMOTE"'' package.json > "$tmp" && mv "$tmp" package.json
if [ "$?" == "0" ]; then
echo "File package.json was updated!"
# remove circleci
echo "💥 Removing CircleCI original dir"
rm -rf .circleci
echo "💥 Removing Art original dir"
rm -rf art
echo "🖋️ Generating new README.md"
rm -rf README.md
echo "
# $1
$2
by $3
" > README.md
echo "🔥 Republish Completed!"
else
echo "⚠️ Some error occurred. No file was updated"
mv -f package.json.orig package.json
exit 1
fi
if [ -f "$tmp" ]; then
rm -f "$tmp"
fi
exit 0