forked from danXyu/commodisense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteor-boilerplate
executable file
·215 lines (187 loc) · 11.3 KB
/
meteor-boilerplate
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
#!/bin/bash
# Overall check
if [ ! -d ".meteor" ]
then echo 'Please use the meteor-boilerplate console tool out of your project root (./meteor-boilerplate)'
exit
fi
case ${1} in
create:view)
if [ -z ${2} ]; then echo "Define a view name!"; exit; fi
if [ -d "client/views/$2" ]; then echo "Remove the existing view ($2) folder manually!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "There's already a module called $2!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
# Create folder
mkdir -p client/views/${2}
# Create files
touch client/views/${2}/${2}.js
touch client/views/${2}/${2}.less
touch client/views/${2}/${2}.html
# Fill files
echo "<template name=\"${2}\">" >> client/views/${2}/${2}.html
echo " <p>Template ${2}</p>" >> client/views/${2}/${2}.html
echo "</template>" >> client/views/${2}/${2}.html
echo "" >> client/views/${2}/${2}.html
echo "Template['${2}'].helpers({" >> client/views/${2}/${2}.js
echo "});" >> client/views/${2}/${2}.js
echo "" >> client/views/${2}/${2}.js
echo "Template['${2}'].events({" >> client/views/${2}/${2}.js
echo "});" >> client/views/${2}/${2}.js
echo "" >> client/views/${2}/${2}.js
echo "@import '../../stylesheets/variables.less'; " >> client/views/${2}/${2}.less
echo "@import '../../stylesheets/elements.less'; " >> client/views/${2}/${2}.less
echo "" >> client/views/${2}/${2}.less
# Succesful
echo "Successfully created a view called \"${2}\""
;;
create:common)
if [ -z ${2} ]; then echo "Define a common view name!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
if [ -d "client/views/$2" ]; then echo "Remove the existing view ($2) folder manually!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "There's already a module called $2!"; exit; fi
# Create folder
mkdir -p client/views/common
touch client/views/common/${2}.html
# Fill files
echo "<template name=\"${2}\">" >> client/views/common/${2}.html
echo " <p>Template ${2}</p>" >> client/views/common/${2}.html
echo "</template>" >> client/views/common/${2}.html
echo "" >> client/views/common/${2}.html
# Succesful
echo "Successfully created a common view called \"${2}\""
;;
create:layout)
if [ -z ${2} ]; then echo "Define a layout view name!"; exit; fi
if [ -f "client/views/layouts/$2.html" ]; then echo "Remove the existing layout ($2) manually!"; exit; fi
# Create folder
mkdir -p client/views/layouts
touch client/views/layouts/${2}.html
# Fill files
echo "<template name=\"${2}Layout\">" >> client/views/layouts/${2}.html
echo " {{yield}}" >> client/views/layouts/${2}.html
echo "</template>" >> client/views/layouts/${2}.html
echo "" >> client/views/layouts/${2}.html
# Succesful
echo "Successfully created a layout called \"${2}\""
;;
create:route)
if [ -z ${2} ] || [ -z ${3} ]; then echo "The first parameter is the route / template name and the second one the path (e. g. create:route home /)"; exit; fi
h2="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}";
if [ -f "client/routes/${h2}Route.js" ]; then echo "Remove the existing route $2 manually!"; exit; fi
# Create folder
mkdir -p client/routes
# Create file
touch client/routes/${2}Route.js
# Fill files
echo "var ${h2}Controller = RouteController.extend({" >> client/routes/${2}Route.js
echo " template: '${2}'" >> client/routes/${2}Route.js
echo "});" >> client/routes/${2}Route.js
echo "" >> client/routes/${2}Route.js
echo "Router.map(function () {" >> client/routes/${2}Route.js
echo " this.route('${2}', {" >> client/routes/${2}Route.js
echo " path : '${3}'," >> client/routes/${2}Route.js
echo " controller : ${h2}Controller" >> client/routes/${2}Route.js
echo " });" >> client/routes/${2}Route.js
echo "});" >> client/routes/${2}Route.js
echo "" >> client/routes/${2}Route.js
# Succesful
echo "Successfully created route \"${h2}Route\" with the path ${3}"
;;
create:module)
if [ -z ${2} ]; then echo "Define a module name!"; exit; fi
if [ -d "client/modules/$2" ]; then echo "Remove the existing module ($2) folder manually!"; exit; fi
if [ -d "client/views/$2" ]; then echo "There's already a view called $2!"; exit; fi
if [ -f "client/views/common/$2.html" ]; then echo "Remove the existing common view ($2) manually!"; exit; fi
# Create folder
mkdir -p client/modules/${2}
# Create files
touch client/modules/${2}/${2}.js
touch client/modules/${2}/${2}.less
touch client/modules/${2}/${2}.html
# Fill files
echo "<template name=\"${2}\">" >> client/modules/${2}/${2}.html
echo " <p>Template ${2}</p>" >> client/modules/${2}/${2}.html
echo "</template>" >> client/modules/${2}/${2}.html
echo "" >> client/modules/${2}/${2}.html
echo "Template['${2}'].helpers({" >> client/modules/${2}/${2}.js
echo "});" >> client/modules/${2}/${2}.js
echo "" >> client/modules/${2}/${2}.js
echo "Template['${2}'].events({" >> client/modules/${2}/${2}.js
echo "});" >> client/modules/${2}/${2}.js
echo "" >> client/modules/${2}/${2}.js
echo "@import '../../stylesheets/variables.less'; " >> client/modules/${2}/${2}.less
echo "" >> client/modules/${2}/${2}.less
# Succesful
echo "Successfully created a module called \"${2}\""
;;
create:model)
if [ -z ${2} ]; then echo "Define a model name!"; exit; fi
if [ -f "model/$2.js" ]; then echo "Remove the existing model $2 manually!"; exit; fi
if [ -f "server/publications/$2.js" ]; then echo "Remove the existing publication file $2 manually!"; exit; fi
if [ -f "client/subscriptions/$2.js" ]; then echo "Remove the existing subscription file $2 manually!"; exit; fi
h2="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}";
# Create folder
mkdir -p model
mkdir -p server/publications
mkdir -p client/subscriptions
# Create file
touch model/${2}.js
touch server/publications/$2.js
touch client/subscriptions/$2.js
# Fill files
echo "$h2 = new Meteor.Collection2('${2}', { 'schema' : {} });" >> model/${2}.js
echo "" >> model/${2}.js
echo "// Collection2 already does schema checking" >> model/${2}.js
echo "// Add custom permission rules if needed" >> model/${2}.js
echo "$h2.allow({" >> model/${2}.js
echo " insert : function () {" >> model/${2}.js
echo " return true;" >> model/${2}.js
echo " }," >> model/${2}.js
echo " update : function () {" >> model/${2}.js
echo " return true;" >> model/${2}.js
echo " }," >> model/${2}.js
echo " remove : function () {" >> model/${2}.js
echo " return true;" >> model/${2}.js
echo " }" >> model/${2}.js
echo "});" >> model/${2}.js
echo "" >> model/${2}.js
echo "Meteor.publish('${2}', function () {" >> server/publications/${2}.js
echo " return $h2.find();" >> server/publications/${2}.js
echo "});" >> server/publications/${2}.js
echo "" >> server/publications/${2}.js
echo "Meteor.subscribe('${2}');" >> client/subscriptions/${2}.js
echo "" >> client/subscriptions/${2}.js
# Succesful
echo "Successfully created a model called \"${2}\" (with files in model, client/subscriptions and server/publications)"
;;
create:test)
if [ -z ${2} ]; then echo "Define a test name!"; exit; fi
if [ -f "tests/$2.js" ]; then echo "Remove the existing test $2 manually!"; exit; fi
# Create file
touch tests/${2}.js
h2="$(tr '[:lower:]' '[:upper:]' <<< ${2:0:1})${2:1}";
# Fill file
echo "var assert = require('assert');" >> tests/${2}.js
echo "" >> tests/${2}.js
echo "suite('$h2', function () {" >> tests/${2}.js
echo "});" >> tests/${2}.js
# Succesful
echo "Successfully created a test called ${2}.js under tests"
;;
*)
if [ -z ${1} ]; then
echo ""
else
echo "Could not find the command!"
echo ""
fi
echo "List of possible operations: "
echo -e "create:test - Test file under tests"
echo -e "create:view - View folder under client/views with html, js and less files in it"
echo -e "create:layout - Create a layout template which yields your content, used by iron-router"
echo -e "create:common - Html template file under client/views/common"
echo -e "create:route - Route javascript file under client/routes"
echo -e "create:model - Model with files in model/, client/subscriptions and server/publications"
echo -e "create:module - Module, such as a searchbar, form etc."
echo ""
;;
esac