This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
npm_deploy.sh
executable file
·136 lines (118 loc) · 3.62 KB
/
npm_deploy.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
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
##############################################################################
# Read the version in package.json and make an array of major.minor.patch
##############################################################################
function readVersion() {
VERSION_STRING=`cat package.json | grep "version" | sed -e 's/[ ^I]*"version": "\(.*\)"\(.*\)/\1/g'`
VERSION=`echo ${VERSION_STRING} | tr "." "\n"`
echo $VERSION
}
##############################################################################
# Make a new version :
# * increment the version number into package.jso
# * commit it
# * return the new version
#
# @param type The type of the new version (ie. Major, Minor or patch)
# @param major version
# @param minor version
# @param patch version
##############################################################################
function makeNewVersion() {
if [ -z "$1" ]; then
echo "Type of version is mandatory for the function `makeNewVersion`"
exit 3
fi
# Rename var
major=$2
minor=$3
patch=$4
case $1 in
Major )
major=$((${major##}+1))
minor=0
patch=0
;;
Minor )
minor=$((${minor##}+1))
patch=0
;;
Patch )
patch=$((${patch##}+1))
;;
* )
exit;;
esac
NEW_VERSION="$major.$minor.$patch"
# Replace in package.json
sed -i "s/\"version\": \"\(.*\)\",/\"version\": \"$NEW_VERSION\",/g" ./package.json
echo $NEW_VERSION
}
##############################################################################
# Build the project
##############################################################################
function build() {
# clean the repo
echo "Cleaning project"
rm -rf docs
# Build project
echo "Building project"
npm run build
}
##############################################################################
# Publish the project
#
# @param $1 the string version to publish
##############################################################################
function publish() {
if [ -z "$1" ]; then
echo "Version is mandatory for the function `publish`"
exit 3
fi
# publsih on NPM
echo "NPM publish"
npm publish
# Create a git tag
echo "Create & push tag $1"
git tag $1
git push --tags
}
##############################################################################
# Deploy function
#
# @param type The type of the new version (ie. Major, Minor or patch)
# @param major version
# @param minor version
# @param patch version
##############################################################################
function deploy() {
VERSION=$(makeNewVersion $1 $2 $3 $4)
build
if [[ $1 != 'RAS' ]]
then
git commit -am "Changing version to $VERSION"
fi
publish $VERSION
}
##############################################################################
# MAIN
##############################################################################
# Get the current version
CURRENT_ARRAY_VERSION=$(readVersion)
echo "Current version is $CURRENT_ARRAY_VERSION"
# Ask user if this version is major, minor or a patch
echo "This script will publish a new version on NPM"
echo "Do you want to make a new version : "
select type in "Major" "Minor" "Patch" ; do
case $type in
Major )
deploy 'Major' $CURRENT_ARRAY_VERSION
exit;;
Minor )
deploy 'Minor' $CURRENT_ARRAY_VERSION
exit;;
Patch )
deploy 'Patch' $CURRENT_ARRAY_VERSION
exit;;
esac
done