-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresta
executable file
·183 lines (151 loc) · 4.79 KB
/
presta
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
#!/bin/bash
#
# PrestaShop Development Scripts
# To install, symlink this file to a directory that is in your $PATH
# and make sure it's executable
#
# For example:
# chmod u+x /path/to/this/file
# ln -s /path/to/this/file /usr/local/bin/presta
#
# Copyright (c) 2015 David Gasperoni
#
readonly program="Presta Development"
readonly bold=$(tput bold)
readonly normal=$(tput sgr0)
if [[ -f .rsyncrc ]]; then
RSYNCRC="$PWD/.rsyncrc"
else
RSYNCRC="$(dirname ~/.prestarc-rsync)/.prestarc-rsync"
fi
about() {
cat <<EOF
$program 1.0
Copyright (c) 2015 David Gasperoni
EOF
exit 0
}
usage() {
cat <<EOF
$program
Convenience scripts to help developing PrestaShop modules
Usage: presta [command]
Commands:
${bold}help${normal} Display this help and exit. Also ${bold}--help${normal} or ${bold}-h${normal}.
${bold}version${normal} Output version information and exit. Also ${bold}--version${normal} or ${bold}-v${normal}.
${bold}stage${normal} Copy the working directory to the staging environments defined
in ~/.prestarc file. You can list several paths to different
local installations of PrestaShop.
${bold}build${normal} Build a zip file from the current directory that
will be saved as ./dist/v{version}-{directory name}.zip
Alternatively, you can add ${bold}-n${normal}, ${bold}--nightly${normal} or ${bold}--no-version${normal} as last
argument to avoid adding a version number to the filename.
${bold}validate${normal} Validate the current working directory using PrestaShop's own
validation service. To be able to use PrestaShop Validator you need to
generate a Validation API key at https://validator.prestashop.com/user
and add it to ~/.prestarc configuration file.
This step requires ${bold}json-tidy${normal}, downloadable via ${bold}npm${normal}.
Add ${bold}--save${normal} or ${bold}--save-report${normal} to save the report of validation to
the Desktop instead of outputting it to stdout.
EOF
}
check_directory() {
if [[ -f ~/.prestarc ]]; then
source ~/.prestarc
else
die "First copy .prestarc to your home directory"
fi
if [[ ! -f ~/.prestarc-rsync ]]; then
die "To test you have to copy or symlink ${bold}.prestarc-rsync${normal} to your home directory"
fi
local PROJECTNAME="$(basename $(pwd))"
if [[ ! -f "$PROJECTNAME.php" ]]; then
die "No .php file with the same as folder.\nAre you sure that you are in the right folder?"
fi
}
stage() {
check_directory
echo $(date)
echo "Staging locally on ${bold}$(hostname)${normal} for ${bold}$(whoami)${normal}"
local COUNTER=0
for PSI in ${PRESTA_INSTALLS[@]}; do
rsync -a --delete-excluded --exclude-from=$RSYNCRC $(pwd) $PSI/modules/
COUNTER=$((COUNTER+1))
done
if [ $COUNTER = 0 ]; then
echo "No PrestaShop installations found in .prestarc"
else
echo "Staging complete in ${bold}$COUNTER${normal} PrestaShop installations"
fi
}
build() {
check_directory
local FOLDERNAME=$(dirname $(pwd))
local PROJNAME=$(basename $(pwd))
local PREFIX='latest'
if [[ $1 != '-n' ]]; then
local PREFIX="v$(awk -F"'|\"" '/\$this->version *= */{print $2}' $PROJNAME.php)"
fi
if [[ -f $(pwd)/.composer.json || -f $(pwd)/.composer.lock ]]; then
composer -v -V 2>/dev/null
composer install -n -q
fi
rsync -a --delete-excluded --exclude-from=$RSYNCRC $(pwd) $TMPDIR
cd $TMPDIR
mkdir -p $FOLDERNAME/$PROJNAME/dist/
zip -rq $FOLDERNAME/$PROJNAME/dist/$PREFIX-$PROJNAME.zip $PROJNAME
cd $FOLDERNAME/$PROJNAME
if [[ -n $TMPDIR || -n $PROJNAME ]]; then
rm -rf $TMPDIR/$PROJNAME
fi
}
validate() {
check_directory
local ENDPOINT="https://validator.prestashop.com/api/modules"
local KEY=$PRESTA_VALIDATOR_KEY
local FOLDERNAME=$(dirname $(pwd))
local PROJNAME=$(basename $(pwd))
rsync -a --delete-excluded --exclude-from=$RSYNCRC $(pwd) $TMPDIR
cd $TMPDIR
zip -rq $PROJNAME.zip $PROJNAME
cd $FOLDERNAME/$PROJNAME
if [[ $1 == '-s' ]]; then
curl -s -F key=$KEY -F archive=@$TMPDIR$PROJNAME.zip $ENDPOINT | json-tidy > ~/Desktop/$PROJNAME.json
echo "Report of validation saved to ~/Desktop/$PROJNAME.json"
else
curl -s -F key=$KEY -F archive=@$TMPDIR$PROJNAME.zip $ENDPOINT | json-tidy
fi
if [[ -n $TMPDIR || -n $PROJNAME ]]; then
rm -rf $TMPDIR/$PROJNAME
rm -rf $TMPDIR/$PROJNAME.zip
fi
}
die() {
echo -e "$program: $1" >&2
exit ${2:-1}
}
case $1 in
help|--help|-h)
usage
;;
version|--version|-v)
about
;;
stage)
stage
;;
build)
if [[ $2 == '-n' || $2 == '--nightly' || $2 == '--no-version' ]]; then
build -n
else
build
fi
;;
validate)
if [[ $2 == '--save' || $2 == '--save-report' ]]; then
validate -s
else
validate
fi
;;
esac