-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagento2-builder.sh
More file actions
executable file
·269 lines (233 loc) · 6.79 KB
/
magento2-builder.sh
File metadata and controls
executable file
·269 lines (233 loc) · 6.79 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
#
# This script helps you generate theme/module skeleton
# Define colors
C_ESC="\033["
C_GREEN=$C_ESC"32m"
C_YELLOW=$C_ESC"33m"
C_RED=$C_ESC"91m"
C_RESET=$C_ESC"0m"
# Define default vars
CONFIG_FILE_PATH="app/etc/config.php"
MODULE_PATH="app/code/"
DESIGN_PATH="app/design/frontend/"
PARENT_THEME_PATH="<parent>Magento/blank</parent>"
DEFAULT_VIEW_FILE="vendor/magento/theme-frontend-blank/etc/view.xml"
PREVIEW_FILENAME="preview.jpg"
DEFAULT_MODULE_VERSION="1.0.0"
ROOT_PATH=$(pwd)
isMagento2() {
[ -f "$CONFIG_FILE_PATH" ]
}
askUser() {
echo -e "Enter your ${C_YELLOW}$1${C_RESET} and press [ENTER]: "
read input
eval "$1=$input"
}
createDirectory() {
if [ -d $1 ]; then
printf "${C_YELLOW}Skipping${C_RESET} %s\n" $1
else
mkdir -p $1
printf "${C_GREEN}Created${C_RESET} %s\n" $1
fi
}
setMagento2Path() {
if ! isMagento2; then
echo -e "${C_RED}$ROOT_PATH is not a Magento 2 project${C_RESET}"
echo -e "Please specify a ${C_YELLOW}Magento 2 path${C_RESET} and press [ENTER]"
read ROOT_PATH
ROOT_PATH="$(pwd)/$ROOT_PATH"
if [ ! -d $ROOT_PATH ]; then
setMagento2Path
fi
if [ ! -d $ROOT_PATH ]; then
setMagento2Path
else
cd $ROOT_PATH
fi
fi
}
createThemeFile() {
theme_file_path="$1/theme.xml"
if [ -f $theme_file_path ]; then
echo -e "${C_YELLOW}Updated${C_RESET} $theme_file_path"
else
echo -e "${C_GREEN}Created${C_RESET} $theme_file_path"
fi
cat > $theme_file_path <<- EOM
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>$THEME_TITLE</title>
$PARENT_THEME_PATH
<media>
<preview_image>media/preview.jpg</preview_image>
</media>
</theme>
EOM
}
createModuleFile() {
module_file_path="$1/module.xml"
NAMESPACE=${VENDOR_NAME}_${MODULE_NAME}
if [ -f $module_file_path ]; then
echo -e "${C_YELLOW}Updated${C_RESET} $module_file_path"
else
echo -e "${C_GREEN}Created${C_RESET} $module_file_path"
fi
cat > $module_file_path <<- EOM
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="$NAMESPACE" setup_version="$DEFAULT_MODULE_VERSION">
</module>
</config>
EOM
}
createRegistrationFile() {
registration_file_path="$1/registration.php"
if [ -f $registration_file_path ]; then
echo -e "${C_YELLOW}Updated${C_RESET} $registration_file_path"
else
echo -e "${C_GREEN}Created${C_RESET} $registration_file_path"
fi
cat > $registration_file_path <<- EOM
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/$VENDOR_NAME/$THEME_NAME',
__DIR__
);
EOM
}
createModuleRegistrationFile() {
registration_file_path="$1/registration.php"
NAMESPACE=${VENDOR_NAME}_${MODULE_NAME}
if [ -f $registration_file_path ]; then
echo -e "${C_YELLOW}Updated${C_RESET} $registration_file_path"
else
echo -e "${C_GREEN}Created${C_RESET} $registration_file_path"
fi
cat > $registration_file_path <<- EOM
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'$NAMESPACE',
__DIR__
);
EOM
}
createFakePreviewFile() {
preview_path="$1/media/$PREVIEW_FILENAME"
touch $preview_path
echo -e "${C_GREEN}Created${C_RESET} $preview_path"
}
createThemeStructure() {
# Create vendor directory
VENDOR_PATH="$ROOT_PATH/$DESIGN_PATH$VENDOR_NAME"
echo
echo -e "> Generating a theme skeleton into ${C_GREEN}$VENDOR_PATH${C_RESET}"
createDirectory $VENDOR_PATH
# Create theme directory
THEME_PATH="$VENDOR_PATH/$THEME_NAME"
createDirectory $THEME_PATH
# Create theme subdirectories
for SUB_DIR in "etc" "media" "web"
do
createDirectory "$THEME_PATH/$SUB_DIR"
done
# Create web subdirectories
for SUB_DIR in "css" "js" "fonts" "images"
do
createDirectory "$THEME_PATH/web/$SUB_DIR"
done
echo
echo -e "> Generating declaration theme files into ${C_GREEN}$THEME_PATH${C_RESET}"
# Create theme.xml file
createThemeFile $THEME_PATH
# Create registration.php
createRegistrationFile $THEME_PATH
# Copy view.xml
cp $DEFAULT_VIEW_FILE "$THEME_PATH/etc/"
# Create fake preview.jpg
createFakePreviewFile $THEME_PATH
}
createModuleStructure() {
# Create vendor directory
VENDOR_PATH="$ROOT_PATH/$MODULE_PATH$VENDOR_NAME"
echo
echo -e "> Generating a module skeleton into ${C_GREEN}$VENDOR_PATH${C_RESET}"
createDirectory $VENDOR_PATH
# Create module directory
MODULE_PATH="$VENDOR_PATH/$MODULE_NAME"
createDirectory $MODULE_PATH
# Create etc directory
ETC_PATH="$MODULE_PATH/etc"
createDirectory "$ETC_PATH"
echo
echo -e "> Generating declaration module files into ${C_GREEN}$ETC_PATH${C_RESET}"
# Create module.xml file
createModuleFile $ETC_PATH
# Create registration.php
createModuleRegistrationFile $MODULE_PATH
echo
echo -e "> Executing ${C_GREEN}$ROOT_PATH/bin/magento setup:upgrade${C_RESET}"
eval "$ROOT_PATH/bin/magento setup:upgrade"
}
buildTheme() {
# Prompt
setMagento2Path
askUser "VENDOR_NAME"
askUser "THEME_NAME"
askUser "THEME_TITLE"
# Execute
createThemeStructure
printf "Don't forget to replace the ${C_YELLOW}preview.jpg${C_RESET} in ${C_YELLOW}%s${C_RESET}\n" "$THEME_PATH/web/media"
}
buildModule() {
# Prompt
setMagento2Path
askUser "VENDOR_NAME"
askUser "MODULE_NAME"
# Execute
createModuleStructure
}
echo
echo "Magento 2 Theme/Module Builder (1.0.1)"
echo "======================="
echo
echo "This command helps you generate Magento2 theme/module skeleton"
echo
echo -e "What would you like to build ?"
PS3="Please, select your option and press [ENTER]: "
select option in "theme" "module"
do
case $option in
"theme")
echo
echo "You have selected Magento 2 $option Builder"
echo
buildTheme
;;
"module")
echo "You have selected Magento 2 $option Builder"
echo
buildModule
;;
*) ;;
esac
break
done
echo
exit