forked from betaflight/betaflight-tx-lua-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update build scripts, update README.md
- Loading branch information
1 parent
6d92e76
commit ac13a82
Showing
5 changed files
with
141 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
all: | ||
bin/build.sh | ||
bin/build.sh min |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,105 @@ | ||
#!/bin/bash | ||
|
||
MINIFY=$1 | ||
ERRCNT=0 | ||
|
||
if [ -d obj ]; then | ||
rm -fR obj/* | ||
else | ||
mkdir obj | ||
fi | ||
|
||
cp -fR src/* obj | ||
if [ -d tmp ]; then | ||
rm -dfR tmp | ||
fi | ||
|
||
mkdir -p tmp/SCRIPTS/BF | ||
echo | ||
luac -v | ||
|
||
MANIFEST=(`find obj/ -name *.lua -type f`); | ||
LAST_FAILURE=0 | ||
if [[ $MINIFY == "min" ]]; then | ||
echo | ||
echo luamin $(npm view luamin version)" "Copyright Mathias Bynens [https://github.com/mathiasbynens/luamin] | ||
fi | ||
|
||
echo | ||
echo "duplicating ..." | ||
## backup minify excludes | ||
EXCLUDE=(`find src/SCRIPTS/BF/* -name *pre.lua -type f`); | ||
for x in ${EXCLUDE[@]}; | ||
do | ||
mkdir -p $(dirname ${x/src/tmp}) | ||
cp -fR $x ${x/src/tmp} | ||
done | ||
cp -fR src/SCRIPTS/BF/X7/exmpl1.lua tmp/SCRIPTS/BF/X7/exmpl1.lua | ||
|
||
MANIFEST=(`find src/* -name *.lua -type f`); | ||
|
||
if [ ${#MANIFEST[@]} -eq 0 ]; then | ||
echo -e "\e[1m\e[39m[\e[31mTEST FAILED\e[39m]\e[21m No scripts could be found!." | ||
echo -e "\e[1m\e[39m[\e[31mTEST FAILED\e[39m] \e[21mNo scripts could be found\e[21m!" | ||
exit 1 | ||
fi | ||
|
||
for f in ${MANIFEST[@]}; | ||
rm -f tmp/tmperr | ||
touch tmp/tmperr | ||
|
||
echo "building ..." | ||
|
||
for file in ${MANIFEST[@]}; | ||
do | ||
SRC_NAME=$f | ||
OBJ_NAME=$(dirname ${f})/$(basename ${f} .lua).luac | ||
echo -e "Compiling file \e[1m${SRC_NAME}\e[21m..." | ||
luac -s -o ${OBJ_NAME} ${SRC_NAME} | ||
SRC_PATH=$(dirname ${file})/ | ||
OBJ_PATH=${SRC_PATH/src/obj} | ||
OBJ_LUA=$(basename ${file}) | ||
OBJ_LUAC=${OBJ_LUA/.lua/.luac} | ||
|
||
echo | ||
echo -ne "\e[1m\e[37m${file}\e[39m\e[1m\e[0m ...\e[0m" | ||
|
||
mkdir -p ${OBJ_PATH} | ||
|
||
if [[ $MINIFY == "min" ]]; then | ||
echo -n " minify ..." | ||
node node_modules/luamin/bin/luamin -f "$file" > "${OBJ_PATH}${OBJ_LUA}" | ||
cp -f "${file/src/tmp}" "${OBJ_PATH}${OBJ_LUA}" >/dev/null >tmp/null 2>tmp/null | ||
else | ||
cp -f "$file" "${OBJ_PATH}${OBJ_LUA}" | ||
fi | ||
|
||
echo -n " compile ..." | ||
luac -s -o "${OBJ_PATH}${OBJ_LUAC}" "$file" >tmp/tmpvar 2>tmp/tmpvar | ||
STDOUT=$(<tmp/tmpvar) | ||
rm -f tmp/tmpvar | ||
|
||
_fail=$? | ||
if [[ $_fail -ne 0 ]]; then | ||
LAST_FAILURE=$_fail | ||
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m]\e[21m Compilation error in file ${SRC_NAME}\e[1m" | ||
if [[ $_fail -ne 0 || $STDOUT ]]; then | ||
((ERRCNT++)) | ||
echo | ||
echo `date +"%Y-%m-%d %T"` "$file $STDOUT"$'\r' >>tmp/tmperr | ||
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m] \e[1m \e[0m\e[37mCompilation error:\e[0m" | ||
echo -e "\e[1m\e[37m${STDOUT}\e[39m\e[1m\e[0m \e[0m" | ||
else | ||
echo -ne " \e[1m\e[39m[\e[32mok\e[39m]\e[1m\e[0m\e[0m" | ||
fi | ||
done | ||
echo | ||
|
||
if [[ $LAST_FAILURE -eq 0 ]]; then | ||
echo -e "\e[1m\e[39m[\e[32mTEST SUCCESSFUL\e[39m]\e[21m All lua files built successfully!" | ||
LAST_FAILURES=$(<tmp/tmperr) | ||
|
||
rm -dfR tmp | ||
|
||
if [[ $LAST_FAILURES == '' ]]; then | ||
echo | ||
echo "copying attachments..." | ||
cp -fvR src/SOUNDS obj/SOUNDS | ||
|
||
echo | ||
echo -e "\e[1m\e[39m[\e[32mSUCCESSFUL\e[39m] \e[21mAll lua files built successfully!\e[21m\e[1m\e[0m\e[0m" | ||
else | ||
echo "$LAST_FAILURES"$'\r' >> ".builderr" | ||
echo | ||
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m] \e[1m \e[0m\e[37mCompilation error(s):\e[0m" | ||
echo -e "\e[1m\e[37m${LAST_FAILURES}\e[39m\e[1m\e[0m \e[0m"$'\r' | ||
fi | ||
exit $LAST_FAILURE | ||
|
||
echo | ||
exit $ERRCNT |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "betaflight-tx-lua-scripts", | ||
"version": "1.3.0", | ||
"scripts": { | ||
"start": "bash bin/build.sh min", | ||
}, | ||
"description": "", | ||
"devDependencies": { | ||
"luamin": "^1.0.4" | ||
} | ||
} |