fix shell script various issues

master
Theunis J. Botha 2021-09-09 18:09:28 +02:00
parent 2e6569f3d8
commit d943a41fc3
4 changed files with 69 additions and 46 deletions

View File

@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/r3-libs/r3-v2/dist" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

View File

@ -17,7 +17,7 @@ r3_completions() {
fi
if [ "${#COMP_WORDS[@]}" == "4" ]; then
COMPREPLY=($(compgen -W "extends normal system static system-base r3-base" "${COMP_WORDS[3]}"))
COMPREPLY=($(compgen -W "extends normal system static system_base r3_base" "${COMP_WORDS[3]}"))
fi
if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "extends" ] ; then

@ -1 +1 @@
Subproject commit 4d262562a6ab070b45ba2860940ae2aec039b66a
Subproject commit ec68e2631d400c9713dfc6d4df66bcc99ca2f80c

107
r3.sh
View File

@ -26,12 +26,12 @@ cleanup() {
if [ "${LAST_ERROR}" = 0 ] ;
then
store_history
usage
fi
if [ "${LAST_ERROR}" = 1 ] ;
then
usage
echo "exited normally"
fi
if [ "${LAST_ERROR}" = 2 ] ;
@ -89,7 +89,7 @@ then
exit 0;
fi
if [ "${TASK}" = 'create' ];
if [ "${TASK}" = 'create' ] || [ "${TASK}" = 'create-from-update-template' ];
then
# echo "updating token.db"
# grep "GENERATED_.*_START" "${TEMPLATE_FOLDER}"*.template "${R3_FOLDER}"*.js "${R3_SYSTEM_FOLDER}"*.js -R | sed "s/^.*GENERATED_/GENERATED_/" | sed "s/_START$//" | sort --unique > "${TEMPLATE_FOLDER}"token.db
@ -134,6 +134,7 @@ then
fi
if [ "${ARG2}" = "system" ]; then
TEMPLATE="system_extends.template"
CLASS_NAME="${ARG1}"
FILE_NAME="r3$(echo "${CLASS_NAME}" | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}').js"
INCLUDE_PATH="../$INCLUDE_PATH"
@ -143,7 +144,8 @@ then
echo "Creating system ${CLASS_NAME} based on template ${TEMPLATE} extending ${EXTEND_CLASS} and saving to ${R3_FOLDER}${FILE_NAME}"
fi
if [ "${ARG2}" = "system-base" ]; then
if [ "${ARG2}" = "system_base" ]; then
TEMPLATE="system_base.template"
FILE_NAME="r3$(echo "${CLASS_NAME}" | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}').js"
INCLUDE_PATH="../$INCLUDE_PATH"
R3_FOLDER=$R3_SYSTEM_FOLDER
@ -168,33 +170,33 @@ then
perl -p -i -e 's/^const Utils.*\n$//' "${R3_FOLDER}${FILE_NAME}"
fi
grep 'GENERATED_' < "${TEMPLATE_FOLDER}"token.db | sed "s/^.*GENERATE/GENERATE/" | while IFS= read -r TOKEN
do
START_TOKEN="${TOKEN}_START"
END_TOKEN="${TOKEN}_END"
TEMPLATE=$(echo "${TOKEN}.template" | sed "s/^GENERATED_//" | awk '{print tolower($0)}')
if grep -q "${START_TOKEN}" "${R3_FOLDER}${FILE_NAME}"; then
if [ -f "${TEMPLATE_FOLDER}${TEMPLATE}" ]; then
echo "Generating template ${TEMPLATE}"
SPACE_COUNT=$(grep "${END_TOKEN}" "${R3_FOLDER}${FILE_NAME}" | perl -pe "s/^.*?(\s)/\1/" | perl -lne 'END {print $c} map ++$c, / /g')
SPACES=''
for ((i=0; i < SPACE_COUNT; i++)) do
SPACES=" $SPACES"
done
# shellcheck disable=SC2002
CONTENTS=$(cat "${TEMPLATE_FOLDER}${TEMPLATE}" | sed -E 's/([+,/,@])/\\\1/g')
perl -i -pe "BEGIN{undef $/;} s/${START_TOKEN}.*\/\/${END_TOKEN}/${START_TOKEN}\n${CONTENTS}\n${SPACES}\/\/${END_TOKEN}/smg" "${R3_FOLDER}${FILE_NAME}"
fi
fi
done
# grep 'GENERATED_' < "${TEMPLATE_FOLDER}"token.db | sed "s/^.*GENERATED/GENERATED/" | while IFS= read -r TOKEN
# do
#
# START_TOKEN="${TOKEN}_START"
# END_TOKEN="${TOKEN}_END"
# TEMPLATE=$(echo "${TOKEN}.template" | sed "s/^GENERATED_//" | awk '{print tolower($0)}')
#
# if grep -q "${START_TOKEN}" "${R3_FOLDER}${FILE_NAME}"; then
#
# if [ -f "${TEMPLATE_FOLDER}${TEMPLATE}" ]; then
#
# echo "Generating template ${TEMPLATE}"
#
# SPACE_COUNT=$(grep "${END_TOKEN}" "${R3_FOLDER}${FILE_NAME}" | perl -pe "s/^.*?(\s)/\1/" | perl -lne 'END {print $c} map ++$c, / /g')
# SPACES=''
#
# for ((i=0; i < SPACE_COUNT; i++)) do
# SPACES=" $SPACES"
# done
#
# # shellcheck disable=SC2002
# CONTENTS=$(cat "${TEMPLATE_FOLDER}${TEMPLATE}" | sed -E 's/([+,/,@])/\\\1/g')
# perl -i -pe "BEGIN{undef $/;} s/${START_TOKEN}.*\/\/${END_TOKEN}/${START_TOKEN}\n${CONTENTS}\n${SPACES}\/\/${END_TOKEN}/smg" "${R3_FOLDER}${FILE_NAME}"
# fi
# fi
#
# done
INCLUDE_PATH=$(echo "${INCLUDE_PATH}" | sed -E 's/([+,/,@])/\\\1/g')
@ -205,7 +207,14 @@ then
echo "Created class ${R3_FOLDER}${FILE_NAME}"
exit 0;
store_history
if [ "${TASK}" = "create" ];
then
r3 update-templates "${FILE_NAME}" new "${ARG2}"
fi
exit 1;
fi
if [ "${TASK}" = 'build-events' ];
@ -219,7 +228,7 @@ then
cd - 2>&1 || exit 3
exit 0
exit 1
fi
@ -264,7 +273,7 @@ then
cd - 2>&1 || exit 3
exit 0
exit 1
fi
if [ "${TASK}" = 'update-templates' ];
@ -293,9 +302,11 @@ then
ORIG_FILE=$FILE
PROCESS_ONLY_FILE="${ARG1}"
check_file_found "${ORIG_FILE}"
if [ -n "${ARG1}" ] && [ "${ARG1}" != "${ORIG_FILE}" ];
if [ -n "${PROCESS_ONLY_FILE}" ] && [ "${PROCESS_ONLY_FILE}" != "${ORIG_FILE}" ];
then
echo "skipping ${ORIG_FILE}"
continue
@ -315,14 +326,24 @@ then
exit 5
fi
$COMMAND
RESULT=$?
if [ "${RESULT}" = 1 ];
if [ -n "${ARG2}" ] && [ "${ARG2}" = "new" ];
then
exit 5
echo "This ${FILE} is new and will be updated now"
else
echo "This ${FILE} is an existing file and will be updated now"
# shellcheck disable=SC2001
COMMAND=$(echo "${COMMAND}" | sed 's/create/create-from-update-template/')
echo "New command is : ${COMMAND}"
$COMMAND
RESULT=$?
if [ "${RESULT}" = 1 ];
then
exit 5
fi
fi
./r3.php "${FILE}" restore
./r3.php "${FILE}" restore "'${COMMAND}'"
RESULT=$?
if [ "${RESULT}" = 1 ];
then
@ -342,7 +363,7 @@ then
cd - 2>&1 || exit 3
exit 0;
exit 1;
fi
if [ "${TASK}" = 'update-options' ];
@ -367,7 +388,7 @@ then
cd - 2>&1 || exit 3
exit 0;
exit 1;
fi
if [ "${TASK}" = 'update-methods' ];
@ -390,7 +411,7 @@ then
cd - 2>&1 || exit 3
exit 0;
exit 1;
fi