-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommand.sh
executable file
·149 lines (135 loc) · 3.05 KB
/
command.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
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
# Output colors
NORMAL='\033[0m' # No Color
RED='\033[0;31m'
BLUE='\033[0;34m'
DIR=`pwd`
# INTERNAL USAGE
log() {
echo -e "${BLUE}${1}${NORMAL}"
}
# INTERNAL USAGE
error() {
echo -e "${RED}ERROR - ${1}${NORMAL}"
return -1
}
check_exit() {
rc=$?; if [[ $rc != 0 ]]; then
error "Something wrong happened. Check logs :(";
exit $rc;
fi
}
install(){
log "Install STARTED"
npm install
typings
check_exit
log "Install ENDED"
}
# INTERNAL USAGE
clean(){
log "Clean STARTED"
rm -r node_modules
rm -r typings
cd $DIR
log "Clean ENDED"
}
#version(){
# log "Setting version"
# BRANCH=$(git branch | awk '/^\*/{print $2}')
# VTAG=$(git describe --tags --abbrev=0)
# TAG=${VTAG:1}
# NUM_COMMITS=$(git log `git describe --tags --abbrev=0`..HEAD --oneline | wc -l | xargs)
# VER=${TAG%.*}
# VER=$VER.$NUM_COMMITS
# npm version $VER
# cd $DIR
# log "Version: $VER"
#}
build() {
log "Build STARTED"
install
transpile
log "Build ENDED"
}
release(){
log "Release STARTED"
install
transpile
# version
clean
clean_tests
log "Release ENDED"
}
transpile(){
log "Do the transpilation"
typings
check_exit
./node_modules/.bin/tsc
# Return 0 to avoid failing because of warnings not solved
return 0
}
#tsdocs(){
# ./node_modules/.bin/typedoc --out typedoc/ lib/ --module commonjs --target ES5 --exclude "**/bower_components/**/*.ts"
#}
typings(){
$(npm bin)/typings install
}
transpile_pre_commit(){
files=`git status -s -uno|grep -v '^ '|awk '{print $2}'`
transpile
echo "$files" | while read a
do
if [ "${a##*.}" == "ts" ]; then
git add ${a//".ts"/".js"}
git add ${a//".ts"/".js.map"}
fi
done
}
test(){
npm link
cd tests
for D in *; do
if [ -d "${D}" ]; then
cd "${D}"
npm install
npm link route-injector
RI_ENV=test $DIR/node_modules/.bin/mocha --preserve-symlinks *
cd ..
fi
done
cd $DIR
}
clean_tests(){
cd tests
for D in *; do
if [ -d "${D}" ]; then
cd "${D}"
rm -rf node_modules
cd ..
fi
done
cd $DIR
}
help() {
echo -e -n "$BLUE"
echo "-----------------------------------------------------------------------"
echo "- Available commands -"
echo "-----------------------------------------------------------------------"
echo " > install - Resolve npm dependencies"
echo " > build - Install dependencies and transpile code"
echo " > release - Release a new version"
echo " > test - Run tests"
echo " > transpile - Install typings and transpile typecsript to javascript"
echo "-----------------------------------------------------------------------"
echo -e -n "$NORMAL"
}
if [ ! -f command.sh ]; then
error "Script must be run from project root-dir (route-injector)"
exit -1
fi
if [ -z "$*" ]; then
help
else
$*
fi