-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeteor-boilerplate.bat
executable file
·356 lines (299 loc) · 8.56 KB
/
meteor-boilerplate.bat
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
@echo off
for %%* in (.) do set d=%%~n*
if %d% EQU .meteor call :errormeteor
if !%1==! call :listhelp
if %1 EQU create:view (
call :createview %2
GOTO :EOF
)
if %1 EQU create:common (
call :createcommon %2
GOTO :EOF
)
if %1 EQU create:layout (
call :createlayout %2
GOTO :EOF
)
if %1 EQU create:route (
call :createroute %2 %3
GOTO :EOF
)
if %1 EQU create:module (
call :createmodule %2
GOTO :EOF
)
if %1 EQU create:model (
call :createmodel %2
GOTO :EOF
)
if %1 EQU create:test (
call :createtest %2
GOTO :EOF
) else (
call :listhelp
GOTO :EOF
)
exit /b
:errormeteor
echo Please use the meteor-boilerplate console tool out of your project root ^(.\meteor-boilerplate^)
exit /b
:end
:createview
if !%1==! (
echo Define a view name!
exit /b
)
if exist client\views\%1 (
echo Remove the existing view ^(%1^) folder manually!
exit /b
)
if exist client\modules\%1 (
echo There's already a module called %1!
exit /b
)
if exist client\views\common\%1.html (
echo Remove the existing common view ^(%1^) manually!
exit /b
)
:: Create folder
mkdir client\views\%1
:: Create files
copy /y nul client\views\%1\%1.js
copy /y nul client\views\%1\%1.less
copy /y nul client\views\%1\%1.html
:: Fill files
echo ^<template name="%1"^> >> client\views\%1\%1.html
echo ^<p^>Template %1^</p^> >> client\views\%1\%1.html
echo ^</template^> >> client\views\%1\%1.html
echo Template['%1'].helpers({ >> client\views\%1\%1.js
echo }); >> client\views\%1\%1.js
echo Template['%1'].events({ >> client\views\%1\%1.js
echo }); >> client\views\%1\%1.js
echo @import '../../stylesheets/variables.less'; >> client\views\%1\%1.less
echo @import '../../stylesheets/elements.less'; >> client\views\%1\%1.less
:: Succesful
echo Successfully created a view called %1
exit /b
:end
:createcommon
if !%1==! (
echo Define a common view name!
exit /b
)
if exist client\views\common\%1.html (
echo Remove the existing common view ^(%1^) manually^!
exit /b
)
if exist client\views\%1 (
echo Remove the existing view ^(%1^) folder manually^!
exit /b
)
if exist client\modules\%1 (
echo There's already a module called %1!
exit /b
)
:: Create folder
mkdir client\views\common
copy /y nul client\views\common\%1.html
:: Fill files
echo ^<template name="%1"^> >> client\views\common\%1.html
echo ^<p^>Template %1^</p^> >> client\views\common\%1.html
echo ^</template^> >> client\views\common\%1.html
:: Succesful
echo Successfully created a common view called %1
exit /b
:end
:createlayout
if !%1==! (
echo Define a layout view name!
exit /b
)
if exist client\views\layouts\%1.html (
echo Remove the existing layout ^(%2^) manually!
exit /b
)
:: Create folder
mkdir client\views\layouts
copy /y nul client\views\layouts\%1.html
:: Fill files
echo ^<template name="%1Layout"^> >> client\views\layouts\%1.html
echo {{yield}} >> client\views\layouts\%1.html
echo ^</template^> >> client\views\layouts\%1.html
:: Succesful
echo Successfully created a layout called %1
exit /b
:end
:createroute
set error=0
if !%1==! set error=1
if !%2==! set error=1
if %error% EQU 1 (
echo The first parameter is the route / template name and the second one the path ^(e. g. create:route home /^)
exit /b
)
call :capitalize h2 %1
set routeName=%1
if exist client\routes\%routeName%Route.js (
echo Remove the existing route %1 manually!
exit /b
)
:: Create folder
mkdir client\routes
:: Create file
copy /y nul client\routes\%routeName%Route.js
:: Fill files
echo var %h2%Controller = RouteController.extend({ >> client\routes\%routeName%Route.js
echo template: '%routeName%' >> client\routes\%routeName%Route.js
echo }); >> client\routes\%routeName%Route.js
echo. >> client\routes\%routeName%Route.js
echo Router.map(function () { >> client\routes\%routeName%Route.js
echo this.route('%routeName%', { >> client\routes\%routeName%Route.js
echo path : '%2', >> client\routes\%routeName%Route.js
echo controller : %h2%Controller >> client\routes\%routeName%Route.js
echo }); >> client\routes\%routeName%Route.js
echo }); >> client\routes\%routeName%Route.js
:: Succesful
echo Successfully created route %h2%Route with the path %2
exit /b
:end
:createmodule
if !%1==! (
echo Define a module name!
exit /b
)
if exist client\modules\%1 (
echo Remove the existing common view ^(%1^) manually!
exit /b
)
if exist client\views\common\%1.html (
echo Remove the existing common view ^(%1^) manually!
exit /b
)
if exist client\views\%1 (
echo There's already a view called %1!
exit /b
)
mkdir client\modules\%1
:: Create files
copy /y nul client\modules\%1\%1.js
copy /y nul client\modules\%1\%1.less
copy /y nul client\modules\%1\%1.html
:: Fill files
echo ^<template name="%1"^> >> client\modules\%1\%1.html
echo ^<p^>Template %1^</p^> >> client\modules\%1\%1.html
echo ^</template^> >> client\modules\%1\%1.html
echo Template['%1'].helpers({ >> client\modules\%1\%1.js
echo }); >> client\modules\%1\%1.js
echo "" >> client\modules\%1\%1.js
echo Template['%1'].events({ >> client\modules\%1\%1.js
echo }); >> client\modules\%1\%1.js
echo @import '../../stylesheets/variables.less'; >> client\modules\%1\%1.less
:: Succesful
echo Successfully created a module called %1
exit /b
:end
:createmodel
if !%1==! (
echo Define a model name!
exit /b
)
if exist model\%1.js (
echo Remove the existing model %1 manually!
exit /b
)
if exist server\publications\%1.js (
echo Remove the existing publication file %1 manually!
exit /b
)
if exist client\subscriptions\%1.js (
echo Remove the existing subscription file %1 manually!
exit /b
)
call :capitalize h2 %1
:: Create folder
mkdir model
mkdir server\publications
mkdir client\subscriptions
:: Create file
copy /y nul model\%1.js
copy /y nul server\publications\%1.js
copy /y nul client\subscriptions\%1.js
:: Fill files
echo %h2% = new Meteor.Collection2('%1'); >> model\%1.js
echo. >> model\%1.js
echo %h2%.allow({ >> model\%1.js
echo insert : function () { >> model\%1.js
echo return false; >> model\%1.js
echo }, >> model\%1.js
echo update : function () { >> model\%1.js
echo return false; >> model\%1.js
echo }, >> model\%1.js
echo remove : function () { >> model\%1.js
echo return false; >> model\%1.js
echo } >> model\%1.js
echo }); >> model\%1.js
echo. >> model\%1.js
echo // Use Meteor.methods for db operations >> model\%1.js
echo Meteor.methods({ >> model\%1.js
echo }); >> model\%1.js
echo Meteor.publish('%1', function () { >> server\publications\%1.js
echo return %h2%.find(); >> server\publications\%1.js
echo }); >> server\publications\%1.js
echo Meteor.subscribe('%1'); >> client\subscriptions\%1.js
:: Successful
echo Successfully created a model called %1 ^(with files in model, client\subscriptions and server\publications^)
exit /b
:end
:createtest
if !%1==! (
echo Define a test name!
exit /b
)
if exist tests\%1.js (
echo Remove the existing test %1 manually!
exit /b
)
mkdir tests
:: Create file
copy /y nul tests\%1.js
call :capitalize h2 %1
:: Fill file
echo var assert = require('assert'); >> tests\%1.js
echo. >> tests\%1.js
echo suite('%h2%', function () { >> tests\%1.js
echo }); >> tests\%1.js
:: Succesful
echo Successfully created a test called %1.js under tests
exit /b
:end
:listhelp
if !%1==! (
echo.
) else (
echo Could not find the command!
echo.
)
echo List of possible operations:
echo create:test - Test file under tests
echo create:view - View folder under client\views with html, js and less files in it
echo create:layout - Create a layout template which yields your content, used by iron-router
echo create:common - Html template file under client\views\common
echo create:route - Route javascript file under client\routes
echo create:model - Model with files in model\, client\subscriptions and server\publications
echo create:module - Module, such as a searchbar, form etc.
echo.
exit /b
:end
:capitalize
setlocal EnableDelayedExpansion
set temp=%2
set helper=##AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ
set first=!helper:*%temp:~0,1%=!
set first=%first:~0,1%
if "%first%"=="#" set first=%temp:~0,1%
set temp=%first%%temp:~1%
(
endlocal
set %~1=%temp%
)
:end