-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_create.sh
executable file
·149 lines (115 loc) · 2.97 KB
/
php_create.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
#
# Author: Stanislav Zhuk <[email protected]>
#
#{{{ bash settings
set -o errexit
set -o nounset
set -o pipefail
#}}}
# shellcheck disable=SC1090
source "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/output_helpers.sh"
# shellcheck disable=SC2034
script_name="PHP Create"
# shellcheck disable=SC2034
script_version="1.0.3"
script_intro
function usage() {
info "Usage: php-create [package] (version - optional) [folder]
Arguments:
[package]: valid composer package or predefined:
cakephp
codeigniter4
drupal
laravel
symfony
yii2
(version): '10.*', '^10.0', 'v10.1.0', etc.
if version is not provided, the latest version will be used."
}
info "Changing directory to ${PWD}"
echo
cd "${PWD}" || failure "Unable to change the directory."
if [[ "${PWD}" == "${HOME}" ]]; then
failure "Do not run from the HOME dir."
fi
if [[ -d ".git" ]]; then
failure "Do not run inside another git repo."
fi
arguments=("${@}")
if [[ ${#arguments[@]} -le 1 ]] || [[ ${#arguments[@]} -ge 4 ]]; then
failure "Wrong number of arguments."
fi
package=""
version=""
folder=""
if [[ ${#arguments[@]} -eq 2 ]]; then
package="${1}"
version=""
folder="${2}"
if [[ "${folder}" =~ ^[0-9] ]]; then
failure "Folder name cannot start with a number."
fi
elif [[ ${#arguments[@]} -eq 3 ]]; then
package="${1}"
version="${2}"
folder="${3}"
fi
if [[ -d "${folder}" ]]; then
failure "Folder '${folder}' already exists."
fi
# composer help create-project
flags=(
--ignore-platform-reqs
--no-install
--no-plugins
--no-scripts
--profile
)
note=""
if [[ "${package}" == "cakephp" ]]; then
package="cakephp/app"
fi
if [[ "${package}" == "codeigniter4" ]]; then
package="codeigniter4/appstarter"
fi
if [[ "${package}" == "drupal" ]]; then
package="drupal/recommended-project"
note="Run: cd ${folder} && php -d memory_limit=256M web/core/scripts/drupal quick-start demo_umami"
fi
if [[ "${package}" == "laravel" ]]; then
package="laravel/laravel"
fi
if [[ "${package}" == "symfony" ]]; then
package="symfony/skeleton"
note="If this is not a library, run: cd $folder && composer require webapp --ignore-platform-reqs"
fi
if [[ "${package}" == "yii2" ]]; then
package="yiisoft/yii2-app-basic"
fi
composer create-project "${flags[@]}" "${package}" "${folder}" "${version}"
cd "${folder}" || failure "Unable to change the directory."
echo
info "Current git user - $(git config user.name) <$(git config user.email)>"
if confirm "Create a git repository?"; then
echo
printf "Commit message (Init): "
read -r commit
if [[ "${commit}" == "" ]]; then
commit="Init"
fi
echo
git init
git add .
git commit -m "${commit}"
echo
success "Created a git repository."
else
warning "Skipped creating a git repository."
fi
if [[ "${note}" != "" ]]; then
echo
secondary "${note}"
fi
echo
info "Done."