2019-06-21 12:03:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
PWD_=$PWD
|
|
|
|
BASE='route_template'
|
|
|
|
NAME=$1
|
|
|
|
NAME_UPPERFIRST=$(echo "$NAME"|sed 's/^./\U&/')
|
|
|
|
|
2019-06-21 12:09:58 +02:00
|
|
|
echo "COMMIT BEFORE"
|
2019-06-21 12:03:27 +02:00
|
|
|
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
|
|
|
|
|
2019-06-21 12:09:58 +02:00
|
|
|
cd $PWD_
|
|
|
|
rsync -av "./$BASE.tmp/" .
|
2019-06-21 14:02:07 +02:00
|
|
|
rm -r "./$BASE.tmp/"
|
|
|
|
echo "$NAME created, check files \"TO IMPLEMENT\" to make it work"
|
2019-06-21 12:03:27 +02:00
|
|
|
exit 0
|