-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
450 lines (416 loc) · 9.5 KB
/
Gruntfile.js
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
module.exports = function (grunt) {
"use strict";
// initializes all grunt tasks, no need to load every task by itself
require('load-grunt-tasks')(grunt);
// create some nice statistics for time consumption of every task
require('time-grunt')(grunt);
grunt.initConfig({
// reads the package.json and provide e.g. the package name
pkg: grunt.file.readJSON('package.json'),
// reads the deploy parameters username, password
deploy: grunt.file.readJSON('deploy.json'),
// removes all files from the specified folders
clean: {
dist: ['dist/'],
tmp: ['.tmp/']
},
// checks the style of the javascript files
jshint: {
options: {
curly: true,
eqeqeq: true,
unused: true,
bitwise: true,
forin: true,
freeze: true,
undef: true,
strict: true,
globals: {
app: true,
window: true,
document: true,
jQuery: true,
angular: true,
Uint8Array: false,
ArrayBuffer: false
}
},
prod: {
src: ['src/js/**/*.js']
},
dev: {
options: {
globals: {
// console is allowed in dev mode
app: true,
console: true,
window: true,
document: true,
jQuery: true,
angular: true,
Uint8Array: false,
ArrayBuffer: false
}
},
src: ['src/js/**/*.js']
},
gruntfile: {
options: {
strict: true,
globals: {
require: true,
module: true,
Uint8Array: false,
ArrayBuffer: false
}
},
src: ['Gruntfile.js']
}
},
jscs: {
final: {
options: {
disallowArrowFunctions: true,
disallowEmptyBlocks: true,
disallowIdentifierNames: ['temp', 'foo', 'bar'],
disallowMixedSpacesAndTabs: true,
disallowMultiLineTernary: true,
disallowMultipleLineBreaks: true,
disallowMultipleLineStrings: true,
disallowMultipleSpaces: true,
disallowNestedTernaries: true,
disallowNewlineBeforeBlockStatements: true,
disallowOperatorBeforeLineBreak: ["+", "."],
disallowSpaceAfterObjectKeys: true,
disallowSpaceBeforeComma: true,
disallowSpaceBeforeSemicolon: true,
disallowSpacesInCallExpression: true,
disallowTrailingComma: true,
disallowTrailingWhitespace: true,
disallowUnusedParams: true,
disallowYodaConditions: true,
requireBlocksOnNewline: true,
requireCamelCaseOrUpperCaseIdentifiers: true,
requireCommaBeforeLineBreak: true,
requireCurlyBraces: true,
requireKeywordsOnNewLine: ["else"],
requireLineBreakAfterVariableAssignment: true,
requireMatchingFunctionName: true,
requirePaddingNewLinesAfterUseStrict: true,
requireParenthesesAroundIIFE: true,
requireSemicolons: true,
requireSpaceAfterBinaryOperators: true,
requireSpaceAfterComma: true,
requireSpaceAfterLineComment: true,
requireSpaceBeforeBinaryOperators: true,
requireSpaceBeforeBlockStatements: true,
requireSpaceBeforeObjectValues: true,
requireSpaceBetweenArguments: true,
requireSpacesInConditionalExpression: true,
requireSpacesInForStatement: true,
requireSpacesInsideObjectBrackets: "all",
validateParameterSeparator: ", ",
validateIndentation: "\t"
},
files: {
src: ['src/js/**/*.js']
}
}
},
// compiles the sass code to css code
sass: {
dist: {
files: [{
expand: true,
cwd: 'src/sass',
src: ['*.{scss,sass}'],
dest: '.tmp/styles',
ext: '.css'
}]
}
},
// copies the specified files
copy: {
regular: {
files: [{
// fonts
expand: true,
flatten: true,
src: ['bower_components/font-awesome/fonts/*.*', 'bower_components/bootstrap/fonts/*.*'],
dest: 'dist/fonts/'
}, {
// images
expand: true,
flatten: true,
src: ['bower_components/jcrop/css/*.gif', 'src/images/*'],
dest: 'dist/styles/'
}, {
// index.html
expand: true,
cwd: 'src/html/',
src: ['index.html'],
dest: 'dist/'
}]
}
},
// converts language.json into productive form
convertLanguageJson: {
json: {
options: {
prefix: "reimbursement."
},
files: [{
src: 'src/languages/languages.json',
dest: 'dist/languages/languages.json',
destType: 'file'
}]
}
},
// adds some necessary css prefixes like -webkit-
autoprefixer: {
options: {
browsers: '> 2% in CH'
},
css: {
src: 'dist/styles/app.css'
}
},
// minifies the css code
cssmin: {
options: {
keepSpecialComments: 0
},
target: {
files: {
'dist/styles/app.css': 'dist/styles/app.css',
'dist/styles/libraries.css': 'dist/styles/libraries.css'
}
}
},
// uglifies the javascript code
uglify: {
js: {
files: {
'dist/javascript/app.js': 'dist/javascript/app.js',
'dist/javascript/libraries.js': 'dist/javascript/libraries.js'
}
}
},
filerev: {
options: {
algorithm: 'md5',
length: 25
},
dist: {
files: [{
src: [
'dist/languages/*.json',
'dist/javascript/*.js',
'dist/styles/*.css'
]
}]
}
},
// concats all css & js files from the index.html
useminPrepare: {
dev: 'src/html/index.html',
options: {
dest: 'dist',
staging: '.tmp',
flow: {
steps: {
js: ['concat'],
css: ['concat']
},
// bugfix for usemin custom flow:
post: []
}
}
},
// replaces the source files from index.html
usemin: {
html: ['dist/index.html'],
options: {
assetsDirs: ['dist']
}
},
// concats only the app.js with templates.js (from html2js)
concat: {
appWithTemplates: {
files: {
'dist/javascript/app.js': ['.tmp/concat/templates.js', 'dist/javascript/app.js']
}
}
},
// converts all the html files to one single js template file
html2js: {
options: {
base: 'src/html/templates/',
module: 'reimbursement.templates',
quoteChar: '\''
},
dev: {
src: [ 'src/html/templates/**/*.tpl.html' ],
dest: '.tmp/concat/templates.js'
},
prod: {
options: {
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
conservativeCollapse: true,
removeComments: true
}
},
src: [ 'src/html/templates/**/*.tpl.html' ],
dest: '.tmp/concat/templates.js'
}
},
htmlmin: {
indexFile: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeComments: true
// conservative collapse is not necessary in index.html, because it contains no
// elements styles with display: inline-block. if that changes, change this property
/* conservativeCollapse: true */
},
files: {
'dist/index.html': 'dist/index.html'
}
}
},
war: {
target: {
options: {
war_dist_folder: 'dist',
war_name: 'ROOT',
webxml_welcome: 'index.html',
webxml_display_name: 'Reimbursement Front-End'
},
files: [{
expand: true,
cwd: 'dist',
src: ['**'],
dest: ''
}]
}
},
// upload the built war file
http_upload: {
prod: {
options: {
url: 'http://<%=deploy.username%>:<%=deploy.password%>@192.41.136.228/manager/text/deploy?path=&update=true',
method: 'PUT',
rejectUnauthorized: true
},
src: 'dist/ROOT.war',
dest: 'reimbursement-frontend'
},
int: {
options: {
url: 'http://<%=deploy.username%>:<%=deploy.password%>@192.41.136.227/manager/text/deploy?path=&update=true',
method: 'PUT',
rejectUnauthorized: true
},
src: 'dist/ROOT.war',
dest: 'reimbursement-frontend'
}
},
// process, which monitors all source files and recompiles after a change
watch: {
options: {
livereload: true
},
dev: {
files: ['src/**/*.*'],
tasks: ['default']
},
prod: {
files: ['src/**/*.*'],
tasks: ['prod']
}
},
// starts a server and deploys the specified files
connect: {
dist: {
options: {
port: 9005,
base: 'dist',
open: 'http://<%= connect.dist.options.hostname %>:<%= connect.dist.options.port %>',
hostname: 'localhost',
livereload: true
}
}
}
});
// the default grunt task, just call "grunt" and it will be executed
grunt.registerTask('default', [
'jshint:gruntfile',
'jshint:dev',
'jscs',
'clean',
'sass',
'useminPrepare',
'concat:generated',
'html2js:dev',
'concat:appWithTemplates',
'autoprefixer',
'copy',
'convertLanguageJson',
'filerev',
'usemin',
'clean:tmp'
]);
// the productive process, which also minifies. it can be started by calling "grunt prod"
grunt.registerTask('prod', [
'jshint:gruntfile',
'jshint:prod',
'jscs',
'clean',
'sass',
'useminPrepare',
'concat:generated',
'html2js:prod',
'concat:appWithTemplates',
'autoprefixer',
'copy',
'convertLanguageJson',
'uglify',
'cssmin',
'filerev',
'usemin',
'htmlmin',
'clean:tmp'
]);
// starts a server instance with live deployment. it can be started by calling "grunt serve"
grunt.registerTask('serve', [
'default',
'connect',
'watch:dev'
]);
// starts a server instance with live deployment. it always takes the minified and uglified resources.
grunt.registerTask('prod-serve', [
'prod',
'connect',
'watch:prod'
]);
// deploys the application to the production tomcat server
grunt.registerTask('deploy-prod', [
'prod',
'war',
'http_upload:prod'
]);
// deploys the application to the integration tomcat server
grunt.registerTask('deploy-int', [
'prod',
'war',
'http_upload:int'
]);
//produce war file
grunt.registerTask('deploy-local', [
'default',
'war'
]);
};