gpp/gen_route.sh

58 lines
1014 B
Bash
Executable File

#!/bin/bash
PWD_=$PWD
BASE='route_template'
NAME=$1
NAME_UPPERFIRST=$(echo "$NAME"|sed 's/^./\U&/')
echo "COMMIT BEFORE"
PROJ='gpp'
APP='port'
rm -rf "$BASE.tmp"
cp -r $BASE $BASE.tmp
cd "$BASE.tmp"
# update template with last routes
cp $PWD_/$PROJ/urls.py ./proj/urls.py
cp $PWD_/$APP/views.py ./proj/views.py
# rename template dir names according to
# current projet
mv ./proj $PROJ
mv ./app $APP
# PROJ
SEDCMD="s/# NEW_ROUTE/"
SEDCMD=$SEDCMD"path('$NAME\/',"
SEDCMD=$SEDCMD"include('$APP.urls.$NAME',"
SEDCMD=$SEDCMD"namespace='$NAME')),/"
sed -i "$SEDCMD" ./$PROJ/urls.py
#APP
cd $APP
SEDCMD="s/#NAME#/$NAME/g;"
SEDCMD=$SEDCMD"s/#NAME_UPPERFIRST#/$NAME_UPPERFIRST/g"
## URLS
sed -i "$SEDCMD" ./urls/new.py
mv urls/new.py urls/$NAME.py
## VIEWS
sed -i "$SEDCMD" ./views/new.py
mv views/new.py views/$NAME.py
## TEMPLATES
for FILE in ./templates/new/*
do
sed -i $SEDCMD $FILE;
done
mv ./templates/new ./templates/$NAME
sed -i "$SEDCMD" ./urls/$NAME.py
cd $PWD_
rsync -av "./$BASE.tmp/" .
exit 0