-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing-all-hooks.bsh
185 lines (128 loc) · 5.48 KB
/
testing-all-hooks.bsh
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
#! /bin/bash
## test-all-hooks.bsh 2018-08-07
## this "extraordinarly redundant" script creates a logger.info(__filename) for each and every hook, including the error hooks
## also creates all the application-wide hooks, for a total of FOURTH-TWO (42) hooks.
SERVICE_NAME='testservice';
FEATHERS_PORT=3030;
echo -n 'node version: ' ; node --version ; ## 8.11.3 at the time of this writing
if [ $? -ne 0 ]; then
echo 'Node has not yet been installed!';
exit 1;
fi
echo -n 'npm version: ' ; npm --version ; ## 5.10.0 at the time of this writing
if [ $? -ne 0 ]; then
echo 'NPM has not yet been installed!';
exit 1;
fi
echo -n 'feathers version: ' ; feathers --version ; ## 3.7.6 at the time of this writing
if [ $? -ne 0 ]; then
echo 'Feathers has not yet been installed!';
exit 1;
fi
THIS_IPADDR=$(dig +short myip.opendns.com @resolver1.opendns.com. ;);
FileNameWithExtension=${0##*/} ;
FileNameWithoutExtension=${FileNameWithExtension%.*} ;
TimeStamp=`date "+%Y-%m-%d %r"` ;
commonPath="$(readlink -f $0 | xargs dirname)"/common;
rm -Rf ./${FileNameWithoutExtension}/ ; ## just in case one already exists.
mkdir ./${FileNameWithoutExtension}/ && cd ./${FileNameWithoutExtension}/ ;
. ${commonPath}/createApp.bsh;
export SERVICE_NAME;
## feathers generate service; ## all defaults except for the service name - "testtable"
expect <(cat <<'END_OF_GENERATE_SERVICE'
# creates a service: reverse (all the defaults)
# written from: https://docs.feathersjs.com/guides/chat/service.html
set UPARROW \x1B\[A;
set DOWNARROW \x1B\[B;
set timeout -1
spawn feathers generate service;
expect -re ".*What kind of service is it\?.*"
send -- "\r"
## defaults to NeDB
expect -re ".*What is the name of the service\?.*"
send -- "$env(SERVICE_NAME)\r"
expect -re ".*Which path should the service be registered on\?.*"
send -- "\r"
## defaults to /reverse
expect -re ".*What is the database connection string.*"
send -- "\r"
## default
expect -re ".*Which testing framework do you prefer?.*"
send -- "\r"
## defaults to Mocha + assert
expect eof
END_OF_GENERATE_SERVICE
) ## end of feathers generate service
#sed --in-place --file=- ./src/services/${SERVICE_NAME}/${SERVICE_NAME}.class.js <<END_OF_SED_REVERSE_CLASS ;
#s|id, text: \`A new message with ID: \${id}\!\`|id, text: \`ID reversed: \${id.toUpperCase()}\` // ${FileNameWithExtension}|;
#END_OF_SED_REVERSE_CLASS
sed --in-place --file=- ./src/services/${SERVICE_NAME}/${SERVICE_NAME}.class.js <<END_OF_SED_REVERSE_CLASS ;
s| id, text: \`A new message with ID: \${id}\!\`|\
// id, text: \`A new message with ID: \${id}\!\` -- line commented out by ${FileNameWithExtension}\n\
id, text: \`ID reversed: \${id.split('').reverse().join('')}\` // -- line added by ${FileNameWithExtension}|;
END_OF_SED_REVERSE_CLASS
sed --in-place --file=- ./config/default.json << END_OF_SED_CONFIG_DEFAULT ;
s/"host": "localhost",/"host": "${THIS_IPADDR}",/;
END_OF_SED_CONFIG_DEFAULT
# before
# after
# error
# default returns application-wide
# downarrow space return selects testservice
# all
# find
# get
# create
# update
# patch
# remove
set -u;
declare -a hookKinds=( 'before' 'after' 'error');
declare -a hookServices=('app' ${SERVICE_NAME} );
declare -a hookMethods=( 'all' 'find' 'get' 'create' 'update' 'patch' 'remove');
downArrow=$'\x1b\x5b\x42';
hookKindDownArrow=${downArrow};
for hookKind in "${hookKinds[@]}"
do
hookServiceDownArrow=''; ## reset
for hookService in "${hookServices[@]}"
do
hookMethodDownArrow=''; ## reset
for hookMethod in "${hookMethods[@]}"
do
export ServiceName=${hookService}-${hookKind}-${hookMethod};
export hookKindDownArrow;
export hookServiceDownArrow;
export hookMethodDownArrow;
expect <(cat <<'END_OF_GENERATE'
set timeout -1
spawn feathers generate hook ;
expect -re ".*What is the name of the hook?.*"
send -- "$env(ServiceName)\r"
expect -re "What kind of hook should it be?"
send -- "$env(hookKindDownArrow)\r"
expect -re "What service\\\(s\\\) should this hook be for \\\(select none to add it yourself\\\)?"
send -- "$env(hookServiceDownArrow) \r"
expect -re "What methods should the hook be for \\\(select none to add it yourself\\\)?"
send -- "$env(hookMethodDownArrow) \r"
expect eof
END_OF_GENERATE
)
sed --in-place --file=- ./src/hooks/${ServiceName}.js <<END_OF_SED ;
3i\
\\
const logger = require('winston');\\
/ return async context => {/ a\
logger.info(__filename);
END_OF_SED
hookMethodDownArrow="${hookMethodDownArrow}${downArrow}";
done
hookServiceDownArrow="${hookServiceDownArrow}${downArrow}";
done
hookKindDownArrow="${hookKindDownArrow}${downArrow}";
done
cat <<END_OF_SCRIPT;
Now run ' cd ./${FileNameWithoutExtension}/ ; npm start; ' to try it out.
END_OF_SCRIPT
##
##