generated from rochacbruno/flask-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
apply.sh
executable file
·77 lines (69 loc) · 2.17 KB
/
apply.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
while getopts a:n:u:d: flag
do
case "${flag}" in
a) author=${OPTARG};;
n) name=${OPTARG};;
u) urlname=${OPTARG};;
d) description=${OPTARG};;
esac
done
echo "Author: $author";
echo "Project Name: $name";
echo "Project URL name: $urlname";
echo "Description: $description";
echo "Rendering the Flask template..."
original_author="hiddify"
original_name="hiddifypanel"
original_urlname="HiddifyPanel"
original_description="Awesome hiddifypanel created by hiddify"
TEMPLATE_DIR="./.github/templates/flask"
for filename in $(find ${TEMPLATE_DIR} -name "*.*" -not \( -name "*.git*" -prune \) -not \( -name "apply.sh" -prune \))
do
sed -i "s/$original_author/$author/g" $filename
sed -i "s/$original_name/$name/g" $filename
sed -i "s/$original_urlname/$urlname/g" $filename
sed -i "s/$original_description/$description/g" $filename
echo "Renamed $filename"
done
# Add requirements
if [ ! -f pyproject.toml ]
then
cat ${TEMPLATE_DIR}/requirements.txt >> requirements.txt
cat ${TEMPLATE_DIR}/requirements-test.txt >> requirements-test.txt
else
for item in $(cat ${TEMPLATE_DIR}/requirements.txt)
do
poetry add "${item}"
done
for item in $(cat ${TEMPLATE_DIR}/requirements-test.txt)
do
poetry add --dev "${item}"
done
fi
# Move module files
rm -rf "${name}"
rm -rf tests
cp -R ${TEMPLATE_DIR}/hiddifypanel "${name}"
cp -R ${TEMPLATE_DIR}/tests tests
cp ${TEMPLATE_DIR}/README.md README.md
cp ${TEMPLATE_DIR}/Containerfile Containerfile
cp ${TEMPLATE_DIR}/wsgi.py wsgi.py
cp ${TEMPLATE_DIR}/.env .env
cp ${TEMPLATE_DIR}/settings.toml settings.toml
# install
make clean
if [ ! -f pyproject.toml ]
then
make virtualenv
make install
echo "Applied Flask template"
echo "Ensure you activate your env with 'source .venv/bin/activate'"
echo "then run 'hiddifypanel' or 'python -m hiddifypanel'"
else
poetry install
echo "Applied Flask template"
echo "Ensure you activate your env with 'poetry shell'"
echo "then run 'hiddifypanel' or 'python -m hiddifypanel' or 'poetry run hiddifypanel'"
fi
echo "README.md has instructions on how to use this Flask application."