-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.sh
executable file
·152 lines (123 loc) · 5.07 KB
/
project.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
150
151
152
#!/usr/bin/env bash
########################################################################################################################
# Instructions
########################################################################################################################
#
# 1. Execute this command ". ./project.sh"
# 2. Type "help" + Enter to show available functions
# 3. That's it, have a good work!
#
########################################################################################################################
# Command colors
########################################################################################################################
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
CYAN='\033[0;36m'
########################################################################################################################
# Help function
########################################################################################################################
function help {
echo_red "---------------------------------------------------------------------------------------------------------"
echo -e ""
echo -e "${CYAN}help${RESTORE} Prints this help"
echo -e ""
echo -e "${CYAN}serve${RESTORE} Builds the front-end into the ${GREEN}build${RESTORE} folder and start a local server to serve this files."
echo -e ""
echo -e "${CYAN}build${RESTORE} Build ${GREEN}Fiddus${RESTORE} place it at ${GREEN}build${RESTORE} folder"
echo -e ""
echo -e "${CYAN}production${RESTORE} Build ${GREEN}Fiddus${RESTORE} and place it at ${GREEN}/var/www/fiddus${RESTORE} path"
echo -e ""
echo -e "${CYAN}test${RESTORE} Perform front-end tests"
echo -e ""
echo -e "${CYAN}check${RESTORE} Check code style with JavaScript Code Style (${GREEN}JSCS${RESTORE}) as well check code errors with ${GREEN}JSHint${RESTORE}"
echo -e ""
echo -e "${CYAN}jshint${RESTORE} Check code errors with ${GREEN}JSHint${RESTORE}"
echo -e ""
echo -e "${CYAN}jscs${RESTORE} Check code style with JavaScript Code Style (${GREEN}JSCS${RESTORE})"
echo -e ""
echo_red "---------------------------------------------------------------------------------------------------------"
}
########################################################################################################################
# Work functions
########################################################################################################################
function serve {
echo_green "Press 'Ctrl' + 'c' to exit"
grunt serve
}
function build {
dorun "grunt build" "Build Fiddus website and add it at ${GREEN}dist${YELLOW} folder"
exitcode=$?
return $exitcode
}
function production {
dorun "grunt production" "Build Fiddus website at ${GREEN}/var/www/fiddus${YELLOW} folder"
exitcode=$?
return $exitcode
}
function test {
dorun "grunt test-client" "Mocha Tests"
exitcode=$?
return $exitcode
}
function check {
dorun "grunt check" "JSHint & SCSC"
exitcode=$?
return $exitcode
}
function jshint {
dorun "grunt jshint" "JSHint - Check code errors"
exitcode=$?
return $exitcode
}
function jscs {
dorun "grunt jscs" "JSCS - Check code styles"
exitcode=$?
return $exitcode
}
########################################################################################################################
# Configuration functions
########################################################################################################################
function echo_red {
echo -e "${RED}$1${RESTORE}";
}
function echo_green {
echo -e "${GREEN}$1${RESTORE}";
}
function echo_yellow {
echo -e "${YELLOW}$1${RESTORE}";
}
function echo_cyan {
echo -e "${CYAN}$1${RESTORE}";
}
function now_milis {
date +%s | cut -b1-13
}
function dorun {
cmd_first="$1"
name="$2"
echo_red "---------------------------------------------------------------------------------------------------------"
echo_green "STARTING ${YELLOW} $name ${GREEN} ..."
echo_cyan "$cmd_first"
t1=$(now_milis)
eval "$cmd_first"
exitcode=$?
t2=$(now_milis)
delta_t=$(expr $t2 - $t1)
if [ $exitcode == 0 ]
then
echo_green "Finished task '${YELLOW}$name${GREEN}' in $delta_t ms"
echo_red "---------------------------------------------------------------------------------------------------------"
else
echo_red "Error running task '${YELLOW}$name${RED}' (status: $exitcode, time: $delta_t ms)"
echo_red "---------------------------------------------------------------------------------------------------------"
return $exitcode
fi
}
########################################################################################################################
# Welcome message
########################################################################################################################
echo_green "Welcome to the Fiddus Development Environment"
echo_green "See available commands below:"
help