-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate
executable file
·116 lines (94 loc) · 2.92 KB
/
template
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
REPO="https://raw.githubusercontent.com/matteolc/react-admin-template/master/"
copy_from_git () {
src_filename=$1;
dst_filename=$1;
[ -e $dst_filename ] && rm $dst_filename;
wget "${REPO}${src_filename}" -O $dst_filename
}
copy_files () {
files=("${!1}")
subpath=$2
[ ! -d app/src$subpath ] && mkdir app/src$subpath
for file in "${files[@]}"
do
copy_from_git "app/src$subpath$file.js"
done
}
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://djm.me/ask
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
install_excel () {
component_files=('ExcelActions' 'ActionsWithExcel' 'ExportToExcel' 'ImportFromExcel' 'DownloadButton' 'ExportToExcelButton')
copy_files component_files[@] /component/
}
install_pdf () {
component_files=('PrintToPdf')
copy_files component_files[@] /component/
}
install_countries () {
root_files=('App.countries')
resource_files=('countries' 'index.countries')
field_files=('FlagField')
copy_files root_files[@] /
copy_files resource_files[@] /resources/
copy_files field_files[@] /field/
mv app/src/App.countries.js app/src/App.js
mv app/src/resources/index.countries.js app/src/resources/index.js
cd app && yarn add react-flags
cp -Rf node_modules/react-flags/vendor/flags public/
cd ..
}
create-react-app app
root_files=('App' 'authClient' 'dataClient' 'Logout' 'types' 'theme' 'downloadFile')
resource_files=('accounts' 'users' 'index')
input_files=('DateTimeInput')
copy_files root_files[@] /
copy_files resource_files[@] /resources/
copy_files input_files[@] /input/
copy_from_git 'app/public/index.html'
copy_from_git 'app/package.json'
cd app && yarn install && cd ..
if ask "Do you want to add support for Excel data import & export?"; then
install_excel
fi
if ask "Do you want to add support for PDF?"; then
install_pdf
fi
if ask "Do you want to add support for countries?"; then
install_countries
fi
cd app
echo "REACT_APP_NAME=Example" > .env
echo "REACT_APP_API_PROTOCOL=http" >> .env
echo "REACT_APP_API_ADDRESS=127.0.0.1" >> .env
echo "REACT_APP_API_PORT=5000" >> .env