Last active
January 11, 2019 02:24
-
-
Save dpineiden/937d36bdfd9148e6c6a344b58c538a71 to your computer and use it in GitHub Desktop.
Create App for Django with some extras
This file contains hidden or 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
# OPTIONS > | |
# | |
# -n :: app name, obligatory | |
# -t :: create templates folder {0,1} | |
# -s :: create static folder {0,1} | |
# -m :: create media folder {0,1} | |
# -u :: create urls.py file {0,1} | |
# -i :: define project name o main folder | |
# | |
# how to run? | |
# | |
# ./startapp.sh -n NAME -t 1 -s 0 -i mi_web | |
# | |
project_name=$(pwd|awk -F'/' '{print $NF}') | |
install_file="./${project_name}/settings/installed.py" | |
echo "Creando apps en ${project_name}" | |
templates=1 | |
static=1 | |
media=0 | |
urls=1 | |
while getopts ntsmu: option | |
do | |
case "${option}" | |
in | |
n) app=${OPTARG};; | |
t) templates=${OPTARG};; | |
s) static=${OPTARG};; | |
m) media=${OPTARG};; | |
u) urls=${OPTARG};; | |
esac | |
done | |
echo "Creating "$app" folder" | |
mkdir ./apps/$app | |
echo "Creating app inside the folder ./apps/"$app | |
python manage.py startapp $app ./apps/$app | |
if [ $templates -eq 1 ] | |
then | |
echo "Creating templates" | |
mkdir ./apps/$app/templates | |
mkdir ./apps/$app/templates/$app | |
fi | |
if [ $static -eq 1 ] | |
then | |
echo "Creating static folder" | |
mkdir ./apps/$app/static | |
mkdir ./apps/$app/static/$app | |
fi | |
if [ $media -eq 1 ]; | |
then | |
echo "Creating media folder" | |
mkdir ./apps/$app/media | |
fi | |
if [ $urls -eq 1 ]; | |
then | |
echo "Creating urls file" | |
touch ./apps/$app/urls.py | |
fi | |
echo "Agregando app a INSTALLED_APPS -> apps.${app}" | |
sed -i "/]/i\ \"apps."$app"\"," $install_file | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment