-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·84 lines (66 loc) · 2.67 KB
/
build.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
#!/bin/bash
###############################################################################
# PATH VARIABLES
###############################################################################
readonly SOURCE_PATH="source/modules"
readonly THIRD_PARTY_PATH="source/third-party"
readonly BUILD_PATH="build"
###############################################################################
# CLEAR THE BUILD FOLDER (safely...)
###############################################################################
# IMPORTANT SECURITY VARIABLE!
# Only empty the build folder if it has less than X files in it
# Reason: If for any reason the script got files from a wrong directory with
# many files it will not delete it!
readonly MAX_NUM_BUILD_FILES=200
readonly MAX_NUM_BUILD_FOLDERS=25
# create build path if it does not exist so far
mkdir -p $BUILD_PATH
# Get full content of the build folder
build_files=`find $BUILD_PATH`
# Count number of files and folders in build folder
num_files=0
num_folders=0
for file in $build_files; do
if [ -d "${file}" ] ; then
let "num_folders++"
elif [ -f "${file}" ] ; then
let "num_files++"
fi
done
echo "Found" $num_files "files and" $num_folders "directories in the build folder."
# Abort if too many files / folders in the build path
if (( $num_files > $MAX_NUM_BUILD_FILES )) ||
(( $num_folders > $MAX_NUM_BUILD_FOLDERS )) ; then
echo "ERROR: There are too many files or folders in the build folder!"
echo "The path to the build folder is probably not correct."
exit 0
fi
# If the script made it all the way to here, it is probably safe to empty the
# build folder => Do it!!!
if (( $num_files > 0 )) && (( $num_folders > 0 )) ; then
build_file_list=($build_files)
# delete build path
rm ${build_file_list[0]} -r
# recreate build path
mkdir -p $BUILD_PATH
fi
###############################################################################
# POPULATE THE BUILD FOLDER
###############################################################################
# Get own module files:
# ## *.js: compile ECMA6 -> ECMA5 with babel
js_files=$(find $SOURCE_PATH -name "*.js")
babel $js_files -d $BUILD_PATH
## *.css: simply copy
css_files=$(find $SOURCE_PATH -name "*.css")
cp $css_files $BUILD_PATH --parents -r
# Third-party libs (js and css files): Copy everything
third_party_files=$(find $THIRD_PARTY_PATH)
cp $third_party_files $BUILD_PATH --parents -r
# restructure the build folder
# current structure: build/source/modules/... build/source/third-party/...
# desired structure: build/modules/... build/third-party/...
# => go into build folder and move everything one level of hierarchy down
mv $BUILD_PATH/source/* $BUILD_PATH
rm $BUILD_PATH/source -R