much more stuff
parent
8e80adf113
commit
f846f775fb
|
@ -15,6 +15,10 @@ services:
|
|||
- ${R3_CONTEXT}/gulpfile.js:/app/gulpfile.js
|
||||
- ${R3_CONTEXT}/webpack.config.js:/app/webpack.config.js
|
||||
- ${R3_CONTEXT}/build_events.php:/app/build_events.php
|
||||
- ${R3_CONTEXT}/create_class.php:/app/create_class.php
|
||||
- ${R3_CONTEXT}/update_options.php:/app/update_options.php
|
||||
- ${R3_CONTEXT}/update_templates.php:/app/update_templates.php
|
||||
- ${R3_CONTEXT}/.r3_history:/app/.r3_history
|
||||
networks:
|
||||
- r3_network
|
||||
command: "start"
|
||||
|
|
|
@ -7,11 +7,11 @@ r3_completions() {
|
|||
# TASK=${#COMP_WORDS[1]}
|
||||
|
||||
if [ "${#COMP_WORDS[@]}" == "2" ]; then
|
||||
COMPREPLY=($(compgen -W "create" "${COMP_WORDS[1]}"))
|
||||
COMPREPLY=($(compgen -W "create build-events update-options update-templates" "${COMP_WORDS[1]}"))
|
||||
fi
|
||||
|
||||
if [ "${#COMP_WORDS[@]}" == "4" ]; then
|
||||
COMPREPLY=($(compgen -W "extends" "${COMP_WORDS[3]}"))
|
||||
COMPREPLY=($(compgen -W "extends normal" "${COMP_WORDS[3]}"))
|
||||
fi
|
||||
|
||||
if [ "${#COMP_WORDS[@]}" == "5" ]; then
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 35b14a655078b13516ae6125d00f736ef617afad
|
||||
Subproject commit 31b2bc87e38f8f9aeb68884e50aa2a07a895209b
|
178
r3.sh
178
r3.sh
|
@ -4,10 +4,30 @@ usage() {
|
|||
echo "Usage : r3 <task> <container>"
|
||||
}
|
||||
|
||||
store_history() {
|
||||
if [ "${TASK}" = 'create' ];
|
||||
then
|
||||
COMMAND=$(echo "r3 ${TASK} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5}" | sed "s/\s+/ /g" | sed "s/\s*$//")
|
||||
echo "command was : ${COMMAND}"
|
||||
if grep -q "${COMMAND}" "${R3_V2_LIB_PATH}"/.r3_history;
|
||||
then
|
||||
echo "Already found command in history"
|
||||
else
|
||||
echo "Saving command to history"
|
||||
echo "r3 ${TASK} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5}" >> "${R3_V2_LIB_PATH}"/.r3_history
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
|
||||
LAST_ERROR=$?
|
||||
|
||||
if [ "${LAST_ERROR}" = 0 ] ;
|
||||
then
|
||||
store_history
|
||||
fi
|
||||
|
||||
if [ "${LAST_ERROR}" = 1 ] ;
|
||||
then
|
||||
usage
|
||||
|
@ -23,16 +43,14 @@ cleanup() {
|
|||
echo "You do not appear to have a proper lib path - did you clone the project correctly?"
|
||||
fi
|
||||
|
||||
|
||||
cd "${CWD}" 2>&1 || exit
|
||||
}
|
||||
|
||||
R3_INSTALL_PATH=/usr/share/cybafelo/r3/r3-cloud
|
||||
R3_V2_LIB_PATH=r3-libs/r3-v2/
|
||||
R3_V2_SRC_PATH=/r3-libs/r3-v2/src
|
||||
|
||||
R3_FOLDER="${R3_INSTALL_PATH}${R3_V2_SRC_PATH}/r3/"
|
||||
TEMPLATE_FOLDER="${R3_INSTALL_PATH}${R3_V2_SRC_PATH}/templates/"
|
||||
R3_V2_LIB_PATH=${R3_INSTALL_PATH}/r3-libs/r3-v2
|
||||
R3_V2_SRC_PATH=${R3_INSTALL_PATH}/r3-libs/r3-v2/src
|
||||
R3_FOLDER="${R3_V2_SRC_PATH}/r3/"
|
||||
TEMPLATE_FOLDER="${R3_V2_SRC_PATH}/templates/"
|
||||
|
||||
CWD=$(pwd)
|
||||
|
||||
|
@ -50,30 +68,109 @@ cd "${R3_INSTALL_PATH}" 2>&1 || exit 2
|
|||
if [ "${TASK}" = 'create' ];
|
||||
then
|
||||
CLASS_NAME=$ARG1
|
||||
FILE_NAME="r3$(echo "${CLASS_NAME}" | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}').js"
|
||||
TEMPLATE="${ARG2}.template"
|
||||
|
||||
EXTEND_CLASS=''
|
||||
EXTEND_CLASS_FILE_NAME=''
|
||||
|
||||
if [ "${ARG2}" = "extends" ]; then
|
||||
EXTEND_CLASS="${ARG3}"
|
||||
EXTEND_CLASS_FILE_NAME="r3$(echo "${EXTEND_CLASS}" | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}').js"
|
||||
FILE_NAME="r3$(echo "${CLASS_NAME}" | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}').js"
|
||||
echo "creating class ${CLASS_NAME} based on template ${TEMPLATE} extending ${EXTEND_CLASS} and saving to ${FILE_NAME}"
|
||||
fi
|
||||
|
||||
echo "${CLASS_NAME}"
|
||||
echo "${TEMPLATE}"
|
||||
echo "${EXTEND_CLASS}"
|
||||
echo "${FILE_NAME}"
|
||||
if [ "${ARG2}" = "normal" ]; then
|
||||
echo "creating normal class ${CLASS_NAME} based on template ${TEMPLATE} and saving to ${FILE_NAME}"
|
||||
fi
|
||||
|
||||
cp "${TEMPLATE_FOLDER}${TEMPLATE}" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
if [ "${EXTEND_CLASS}" = "Event" ]; then
|
||||
perl -p -i -e 's/^const Event.*\n$//' "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
if [ "${EXTEND_CLASS}" = "Utils" ]; then
|
||||
perl -p -i -e 's/^const Utils.*\n$//' "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
if [ "${CLASS_NAME}" = "Event" ]; then
|
||||
perl -p -i -e 's/^const Event.*\n$//' "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
if [ "${CLASS_NAME}" = "Utils" ]; then
|
||||
perl -p -i -e 's/^const Utils.*\n$//' "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
if [ "${ARG2}" = "extends" ]; then
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}constructor_extends.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CONSTRUCTOR_EXTENDS_TEMPLATE_START.*\/\/CONSTRUCTOR_EXTENDS_TEMPLATE_END/\/\/CONSTRUCTOR_EXTENDS_TEMPLATE_START\n${CONTENTS}\n\t\/\/CONSTRUCTOR_EXTENDS_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
if [ "${ARG2}" = "normal" ]; then
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}constructor.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CONSTRUCTOR_TEMPLATE_START.*\/\/CONSTRUCTOR_TEMPLATE_END/\/\/CONSTRUCTOR_TEMPLATE_START\n${CONTENTS}\n\t\/\/CONSTRUCTOR_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
fi
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}create_instance.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CREATE_INSTANCE_TEMPLATE_START.*\/\/CREATE_INSTANCE_TEMPLATE_END/\/\/CREATE_INSTANCE_TEMPLATE_START\n${CONTENTS}\n\t\/\/CREATE_INSTANCE_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_instance.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_INSTANCE_TEMPLATE_START.*\/\/UPDATE_INSTANCE_TEMPLATE_END/\/\/UPDATE_INSTANCE_TEMPLATE_START\n${CONTENTS}\n\t\/\/UPDATE_INSTANCE_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_from_instance.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_FROM_INSTANCE_TEMPLATE_START.*\/\/UPDATE_FROM_INSTANCE_TEMPLATE_END/\/\/UPDATE_FROM_INSTANCE_TEMPLATE_START\n${CONTENTS}\n\t\/\/UPDATE_FROM_INSTANCE_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_TEMPLATE_START.*\/\/DISPOSE_TEMPLATE_END/\/\/DISPOSE_TEMPLATE_START\n${CONTENTS}\n\t\/\/DISPOSE_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose_instance.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_INSTANCE_TEMPLATE_START.*\/\/DISPOSE_INSTANCE_TEMPLATE_END/\/\/DISPOSE_INSTANCE_TEMPLATE_START\n${CONTENTS}\n\t\/\/DISPOSE_INSTANCE_TEMPLATE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}create_instance_before.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CREATE_INSTANCE_BEFORE_START.*\/\/CREATE_INSTANCE_BEFORE_END/\/\/CREATE_INSTANCE_BEFORE_START\n${CONTENTS}\n\t\t\/\/CREATE_INSTANCE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}create_instance_after.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CREATE_INSTANCE_AFTER_START.*\/\/CREATE_INSTANCE_AFTER_END/\/\/CREATE_INSTANCE_AFTER_START\n${CONTENTS}\n\t\t\/\/CREATE_INSTANCE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_instance_before.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_INSTANCE_BEFORE_START.*\/\/UPDATE_INSTANCE_BEFORE_END/\/\/UPDATE_INSTANCE_BEFORE_START\n${CONTENTS}\n\t\t\/\/UPDATE_INSTANCE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_instance_after.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_INSTANCE_AFTER_START.*\/\/UPDATE_INSTANCE_AFTER_END/\/\/UPDATE_INSTANCE_AFTER_START\n${CONTENTS}\n\t\t\/\/UPDATE_INSTANCE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_from_instance_before.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_FROM_INSTANCE_BEFORE_START.*\/\/UPDATE_FROM_INSTANCE_BEFORE_END/\/\/UPDATE_FROM_INSTANCE_BEFORE_START\n${CONTENTS}\n\t\t\/\/UPDATE_FROM_INSTANCE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}update_from_instance_after.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/UPDATE_FROM_INSTANCE_AFTER_START.*\/\/UPDATE_FROM_INSTANCE_AFTER_END/\/\/UPDATE_FROM_INSTANCE_AFTER_START\n${CONTENTS}\n\t\t\/\/UPDATE_FROM_INSTANCE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose_before.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_BEFORE_START.*\/\/DISPOSE_BEFORE_END/\/\/DISPOSE_BEFORE_START\n${CONTENTS}\n\t\t\/\/DISPOSE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose_after.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_AFTER_START.*\/\/DISPOSE_AFTER_END/\/\/DISPOSE_AFTER_START\n${CONTENTS}\n\t\t\/\/DISPOSE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose_instance_before.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_INSTANCE_BEFORE_START.*\/\/DISPOSE_INSTANCE_BEFORE_END/\/\/DISPOSE_INSTANCE_BEFORE_START\n${CONTENTS}\n\t\t\/\/DISPOSE_INSTANCE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}dispose_instance_after.template" | sed -E 's/([+,/,@])/\\\1/g')
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/DISPOSE_INSTANCE_AFTER_START.*\/\/DISPOSE_INSTANCE_AFTER_END/\/\/DISPOSE_INSTANCE_AFTER_START\n${CONTENTS}\n\t\t\/\/DISPOSE_INSTANCE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
sed -i "s/CLASS_NAME/${CLASS_NAME}/g" "${R3_FOLDER}${FILE_NAME}"
|
||||
sed -i "s/EXTEND_CLASS_FILE_NAME/${EXTEND_CLASS_FILE_NAME}/g" "${R3_FOLDER}${FILE_NAME}"
|
||||
sed -i "s/EXTEND_CLASS/${EXTEND_CLASS}/g" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}create_instance_before.template")
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CREATE_INSTANCE_BEFORE_START.*\/\/CREATE_INSTANCE_BEFORE_END/\/\/CREATE_INSTANCE_BEFORE_START\n${CONTENTS}\n\t\t\/\/CREATE_INSTANCE_BEFORE_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
CONTENTS=$(cat "${TEMPLATE_FOLDER}create_instance_after.template")
|
||||
perl -i -pe "BEGIN{undef $/;} s/\/\/CREATE_INSTANCE_AFTER_START.*\/\/CREATE_INSTANCE_AFTER_END/\/\/CREATE_INSTANCE_AFTER_START\n${CONTENTS}\n\t\t\/\/CREATE_INSTANCE_AFTER_END/smg" "${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
echo "Created class ${R3_FOLDER}${FILE_NAME}"
|
||||
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ "${TASK}" = 'build-events' ];
|
||||
then
|
||||
|
||||
echo "building events"
|
||||
|
||||
cd "${R3_V2_LIB_PATH}" 2>&1 || exit 3
|
||||
|
||||
./build_events.php
|
||||
|
@ -89,5 +186,52 @@ then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
if [ "${TASK}" = 'update-templates' ];
|
||||
then
|
||||
|
||||
echo "updating templates"
|
||||
|
||||
cd "${R3_V2_LIB_PATH}" 2>&1 || exit 3
|
||||
|
||||
COMMANDS=$(grep "r3 create" .r3_history | sed "s/^.*r3/r3/" | sed "s/\s+/ /g" | sort --unique | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/,/g')
|
||||
FILES=$(grep "r3 create" .r3_history | sed "s/^.*r3/r3/" | sed "s/\s+/ /g" | sort --unique | cut -d' ' -f3 | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}' | sed "s/^/r3/" | sed "s/$/.js/")
|
||||
|
||||
IFS=',' read -a commands <<< $COMMANDS
|
||||
|
||||
INDEX=0
|
||||
|
||||
for FILE in ${FILES}; do
|
||||
FILE_PATH="${R3_FOLDER}${FILE}"
|
||||
COMMAND="${commands[$INDEX]}";
|
||||
INDEX=$(($INDEX + 1));
|
||||
if [ -f "${FILE_PATH}" ] ;
|
||||
then
|
||||
./update_templates.php save "${FILE_PATH}"
|
||||
$COMMAND
|
||||
./update_templates.php restore "${FILE_PATH}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
done
|
||||
|
||||
cd - 2>&1 || exit 3
|
||||
|
||||
fi
|
||||
|
||||
if [ "${TASK}" = 'update-options' ] || [ "${TASK}" = 'update-templates' ];
|
||||
then
|
||||
|
||||
echo "updating options"
|
||||
|
||||
cd "${R3_V2_LIB_PATH}" 2>&1 || exit 3
|
||||
|
||||
./update_options.php all
|
||||
|
||||
cd - 2>&1 || exit 3
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
docker-compose $TASK $ARG1 $ARG2 $ARG3 $ARG4 $ARG5
|
Loading…
Reference in New Issue