-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fis.sh
executable file
·214 lines (185 loc) · 5.61 KB
/
fis.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
# consts
CHECK_FIS3_DEPENDENCIES=true
PROJECT_CONFIG_FILE=./project.config.js
FIS_CONFIG_FILE=`node -p "require('$PROJECT_CONFIG_FILE').build.config"`
SOURCE_FOLDER=`node -p "require('$PROJECT_CONFIG_FILE').build.src"`
LOG_FILE=`node -p "require('$PROJECT_CONFIG_FILE').build.log"`
SERVER_TYPE=`node -p "require('$PROJECT_CONFIG_FILE').server.type"`
SERVER_PORT=`node -p "require('$PROJECT_CONFIG_FILE').server.config.port"`
DIST_FOLDER=`node -p "require('$PROJECT_CONFIG_FILE').build.dist"`
TEMP_RESOURCE_FOLDER=$DIST_FOLDER/`node -p "require('$PROJECT_CONFIG_FILE').build.temp"`
PLATFORM=`node -p "process.platform"`
ENV_PATH_SEP=":"
if [ "$PLATFORM" = "win32" ]; then
ENV_PATH_SEP=";"
fi
PWD=`pwd`
# env
export NODE_PATH=$NODE_PATH$ENV_PATH_SEP`npm -g root`
function main() {
clear
echo ""
echo " fis3 debug & distribute script"
echo ""
echo " see http://fis.baidu.com"
echo " by fisker Cheung [email protected]"
echo ""
echo ""
echo "==============================================================================="
echo ""
echo ""
echo " 1. dev (default)"
echo ""
echo " 2. build"
echo ""
echo " 3. build & archive"
echo ""
echo " Q. quit"
echo ""
echo ""
# chose operation
read -t 5 -n1 -p "Please choose an option:" choice
case "$choice" in
2)
build
;;
3)
archive
;;
q|Q)
quit
;;
*)
dev
;;
esac
}
function archive() {
export NODE_ENV="production"
clear
checkFis3Dependencies
release
archive
end
}
function build() {
export NODE_ENV="production"
clear
checkFis3Dependencies
release
end
}
function dev() {
export NODE_ENV="development"
clear
checkFis3Dependencies
debug
pause
}
function installDependencies() {
echo "..............................................................................."
echo "install package dependencies"
yarn > "$LOG_FILE" || error
yarn run install-dependencies > "$LOG_FILE" || error
}
function checkFis3Dependencies() {
if [ "$CHECK_FIS3_DEPENDENCIES" = "true" ]; then
echo "..............................................................................."
echo "check fis3 dependencies"
fis3 inspect $NODE_ENV --root "$SOURCE_FOLDER" --file "$FIS_CONFIG_FILE" --lint --verbose --no-color | node "./scripts/check-fis3-dependencies.js" > "$LOG_FILE" || error
fi
}
function release() {
# remove release file and log file
if [ -d "$DIST_FOLDER" ]; then
rm -r "$DIST_FOLDER"
fi
if [ -f "$LOG_FILE" ]; then
rm "$LOG_FILE"
fi
# release file
echo "..............................................................................."
echo "releasing files"
fis3 release $NODE_ENV --dest "$DIST_FOLDER" --root "$SOURCE_FOLDER" --file "$FIS_CONFIG_FILE" --clean --unique --lint --verbose --no-color > "$LOG_FILE" || error
if [ -d "$TEMP_RESOURCE_FOLDER" ]; then
rm -r "$TEMP_RESOURCE_FOLDER"
fi
echo "..........................................................................done."
echo ""
}
# archive
function archive() {
echo "archive"
ARCHIVE_FOLDER=`node -p "require('$PROJECT_CONFIG_FILE').build.archive"`
ARCHIVE_TYPE=`node -p "require('$PROJECT_CONFIG_FILE').build.archiveType"`
ARCHIVE_FILE=`node -p "require('$PROJECT_CONFIG_FILE').build.archiveFile"`
# make distribute folder ready
if [ ! -d "$ARCHIVE_FOLDER" ]; then
mkdir "$ARCHIVE_FOLDER"
fi
# archive files to distribute folder
echo "..............................................................................."
echo "packing files"
if [ "$ARCHIVE_TYPE" = "tar.gz" ]; then
targz -l 9 -m 9 -c "$DIST_FOLDER" "$ARCHIVE_FOLDER/$ARCHIVE_FILE.tar.gz" || pause
else
winzip zip "$DIST_FOLDER" "$ARCHIVE_FOLDER/$ARCHIVE_FILE" || pause
fi
start "$ARCHIVE_FOLDER"
echo "..........................................................................done."
}
#debug
function debug() {
# stop server
echo "..............................................................................."
echo "stop server"
fis3 server stop || pause
# if errorlevel 1 ( pause )
echo "..........................................................................done."
echo ""
# clean up
echo "..............................................................................."
echo "clean up server folder"
fis3 server clean || pause
# if errorlevel 1 ( pause )
echo "..........................................................................done."
echo ""
# start server
echo "..............................................................................."
echo "start server"
fis3 server start --type $SERVER_TYPE --port $SERVER_PORT || pause
echo "..........................................................................done."
echo ""
# start watch
echo "..............................................................................."
echo "watching files"
fis3 release $NODE_ENV --root "$SOURCE_FOLDER" --file "$FIS_CONFIG_FILE" --clean --verbose --watch
}
function pause() {
echo "press any key to continue."
read -n 1
}
function error() {
echo "..............................................................................."
echo " error occurred"
echo "..............................................................................."
echo ""
cat "$LOG_FILE"
pause
end
}
function end() {
echo "exit in 5 seconds"
sleep 5
exit
}
if [ "$1" = "dev" ]; then
dev
elif [ "$1" = "build" ]; then
buid
elif [ "$1" = "archive" ]; then
archive
else
main
fi