-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gruntfile.js
523 lines (493 loc) · 17.1 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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/*
*
* Copyright (c) 2014 eXist Solutions
* Licensed under the MIT license.
*/
'use strict';
/* jshint indent: 2 */
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
// require('time-grunt')(grunt);
// Actually load this plugin's task(s).
//grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-zip');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-contrib-less');
// Project configuration.
grunt.initConfig({
xar: grunt.file.readJSON('package.json'),
jshint: {
all: [
'gruntfile.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['build', 'dist']
},
/*
replaces tokens in expath-pkg.tmpl and creates expath-pkg.xml with substituted values
*/
replace: {
pkg: {
src: ['expath-pkg.tmpl'],
dest: 'expath-pkg.xml',
replacements: [
{
from: '@APPVERSION@',
to: '<%= xar.version %>'
},
{
from: '@APPNAME@',
to: '<%= xar.name %>'
},
{
from: '@APPDESCRIPTION@',
to: '<%= xar.description %>'
}
]
},
repo: {
src: ['repo.tmpl'],
dest: 'repo.xml',
replacements: [
{
from: '@APPVERSION@',
to: '<%= xar.version %>'
},
{
from: '@APPNAME@',
to: '<%= xar.name %>'
},
{
from: '@APPDESCRIPTION@',
to: '<%= xar.description %>'
}
]
}
},
/*
Copy copies all relevant files for building a distribution in 'dist' directory
*/
// CSS and JS resources are copied as they get processed by their respective optimization tasks later in the chain.
// png images will not be copied as they will get optimized by imagemin
copy: {
dist: {
files: [
{expand: true,
cwd: './',
src: ['doc/**','modules/**','resources/img/**', 'templates/**', '*.xql', '*.xml', '*.txt', '*.ico', '*.html'],
dest: 'dist/'},
{expand: true,
cwd: './',
flatten: true,
src: ['components/font-awesome/fonts/**'],
dest: 'dist/resources/fonts/',
filter: 'isFile'
},
{expand: true,
cwd: './',
flatten: true,
src: ['components/bxslider-4/dist/images/**'],
dest: 'dist/resources/css/images/',
filter: 'isFile'
}
]
}
},
/*
optimizes images for the web. Currently only .png files are considered. This might be extended later.
*/
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
// Set to true to enable the following options…
expand: true,
// cwd is 'current working directory'
cwd: './resources/img/',
src: ['**/*.png'],
// Could also match cwd line above. i.e. project-directory/img/
dest: 'dist/resources/img/',
ext: '.png'
}
]
}
},
/*
minifies the file 'resources/js/app.js'. Creates a minified version 'app.min.js'. Using a fixed and unconfigurable
name makes substitution in html page easier - see build comments at the end of html files.
*/
uglify: {
index: {
files: {
'resources/js/exist.min.js': [
'resources/js/svgicons.js',
'resources/js/exist-home.js'
]
}
},
press: {
files: {
'resources/js/press.min.js': [
'resources/js/press.js'
]
}
},
timeline: {
files: {
'resources/js/timeline.min.js': [
'resources/js/scrollPagination.js',
'resources/js/timeline.js',
'resources/js/wow.js'
]
}
}
},
/*
concatenates all minified JavaScript files into one. Destination file will be app.min.js
*/
concat: {
options: {
// define a string to put between each file in the concatenated output
stripBanners: true
},
index: {
// the files to concatenate - use explicit filenames here to ensure proper order
// puts app.js at the end.
src: [
'components/jquery/dist/jquery.min.js',
'components/bootstrap/dist/js/bootstrap.min.js',
'components/snap.svg/dist/snap.svg-min.js',
'components/bxslider-4/dist/jquery.bxslider.min.js',
'resources/js/exist.min.js'],
// the location of the resulting JS file
dest: 'dist/resources/js/exist.min.js'
},
press: {
// the files to concatenate - use explicit filenames here to ensure proper order
// puts app.js at the end.
src: [
'components/jquery/dist/jquery.min.js',
'components/bootstrap/dist/js/bootstrap.min.js',
'resources/js/press.min.js'],
// the location of the resulting JS file
dest: 'dist/resources/js/press.min.js'
},
timeline: {
// the files to concatenate - use explicit filenames here to ensure proper order
// puts app.js at the end.
src: [
'components/jquery/dist/jquery.min.js',
'components/bootstrap/dist/js/bootstrap.min.js',
'resources/js/timeline.min.js'],
// the location of the resulting JS file
dest: 'dist/resources/js/timeline.min.js'
},
training: {
// the files to concatenate - use explicit filenames here to ensure proper order
// puts app.js at the end.
src: [
'components/jquery/dist/jquery.min.js',
'components/bootstrap/dist/js/bootstrap.min.js'],
// the location of the resulting JS file
dest: 'dist/resources/js/training.min.js'
}
},
less: {
development: {
options:{
strictImports:true
},
files: {
"resources/css/styles.css": "resources/css/styles.less",
}
},
production: {
options:{
strictImports:true
},
files: {
"resources/css/styles.css": "resources/css/styles.less"
}
},
timeline:{
options:{
strictImports:true
},
files: {
"resources/css/timeline.css": "resources/css/timeline.less"
}
},
training:{
options:{
strictImports:true
},
files: {
"resources/css/training.css": "resources/css/training.less"
}
},
references:{
options:{
strictImports:true
},
files: {
"resources/css/references.css": "resources/css/references.less"
}
}
},
/*
removes unused CSS rules by investigating the imports of html files. Used to strip down e.g. bootstrap to
the actual used amount of rules.
*/
uncss: {
index: {
src: ['./index.html'],
dest: 'resources/css/index.min.css',
options: {
ignore: ['.collapsing',
/.exist-.+\b/,
/.open.+\b/,
'.navbar-collapse.collapse',
'.collapse.in',
/.band-news.+\b/ ,
'.animated',
'slideInDown',
/.bx-.+\b/],
flatten: true
}
},
timeline: {
src: ['timetunnel.html'],
dest: 'resources/css/timeline.min.css',
options: {
ignore: [
/.exist-.+\b/,
'.exist-timeline-content',
'.exist-timeline-img',
'.exist-date',
'.exist-read-more',
/.open.+\b/,
'.navbar-collapse.collapse',
'.collapse.in',
'.fa-quote-left',
'.fa-paper-plane',
'.fa-space-shuttle',
'.fa-bullhorn',
'wow'],
flatten: true
}
},
training: {
src: ['training.html'],
dest: 'resources/css/training.min.css',
options: {
ignore: [
/.exist-.+\b/,
/.open.+\b/,
'.collapsed',
'.collapse.in',
'.navbar-collapse.collapse'],
flatten: true
}
},
references: {
src: ['references.html'],
dest: 'resources/css/references.min.css',
options: {
ignore: [
/.exist-.+\b/,
/.open.+\b/,
'.collapsed',
'.collapse.in',
'.navbar-collapse.collapse'],
flatten: true
}
}
},
/*
minify the already cleaned up CSS files
*/
cssmin: {
index: {
options: {
compatibility: 'ie8',
keepSpecialComments: 0,
report: 'min'
},
files: {
'dist/resources/css/index.min.css': 'resources/css/index.min.css'
}
},
timeline: {
options: {
compatibility: 'ie8',
keepSpecialComments: 0,
report: 'min'
},
files: {
'dist/resources/css/timeline.min.css': 'resources/css/timeline.min.css'
}
},
training: {
options: {
compatibility: 'ie8',
keepSpecialComments: 0,
report: 'min'
},
files: {
'dist/resources/css/training.min.css': 'resources/css/training.min.css'
}
},
references: {
options: {
compatibility: 'ie8',
keepSpecialComments: 0,
report: 'min'
},
files: {
'dist/resources/css/references.min.css': 'resources/css/references.min.css'
}
}
},
/*
Gives statistical information about CSS compression results
*/
compare_size: {
files: [
'resources/css/*.css',
'dist/resources/css/index.min.css',
'dist/resources/css/timeline.min.css',
'dist/resources/css/training.min.css',
'dist/resources/css/references.min.css'
]
},
/*
This task will replace CSS and JS imports in the main html file to point to the optimized versions instead
of linking into 'components'
*/
processhtml: {
index: {
options: {
data: {
minifiedCss: '<link href="resources/css/index.min.css" type="text/css" rel="stylesheet"/>'
}
},
files: {
'dist/index.html': ['./index.html']
}
},
/*
press: {
options: {
data: {
minifiedCss: '<link href="resources/css/app.min.css" type="text/css" rel="stylesheet"/>'
}
},
files: {
'dist/press.html': ['./press.html']
}
},
*/
timeline: {
options: {
data: {
minifiedCss: '<link href="resources/css/timeline.min.css" type="text/css" rel="stylesheet"/>'
}
},
files: {
'dist/timetunnel.html': ['./timetunnel.html']
}
},
references: {
options: {
data: {
minifiedCss: '<link href="resources/css/references.min.css" type="text/css" rel="stylesheet"/>'
}
},
files: {
'dist/references.html': ['./references.html']
}
}
},
/*
this task builds the actual .xar apps for deployment into eXistdb. zip:xar will create an unoptimized version while
zip:production will use the optimized app found in the 'dist' directory.
Note: here component files are cherry-picked - including the whole distribution is certainly more generic but bloats the resulting .xar too much
*/
zip: {
xar: {
src: [
'collection.xconf',
'*.xml',
'*.xql',
'*.html',
'doc/**',
'modules/**',
'resources/**',
'templates/**',
'components/animate.css/*',
'components/bootstrap/dist/**',
'components/font-awesome/css/**',
'components/font-awesome/fonts/**',
'components/jquery/dist/**',
'components/velocity/**',
'components/jquery-waypoints/lib/jquery.waypoints.js',
'components/modernizr/modernizr.js',
'components/snap.svg/**',
'components/bxslider-4/dist/**'
],
dest: 'build/<%=xar.name%>-<%=xar.version%>.zip'
},
production: {
cwd: 'dist/',
src: ['dist/**'],
dest: 'build/<%=xar.name%>-<%=xar.version%>.min.zip'
}
},
/*
watches gruntfile itself and checks for problems
*/
watch: {
files: ['gruntfile.js'],
tasks: ['jshint']
}
});
/*
*/
grunt.registerTask('default', [
'replace',
'less:development',
'zip:xar'
]);
/*
took out imagemim as it's slowing down the task dramatically and is not always reliable.
Better to run it manually when need images are added and to add the optimized ones to resources/img
afterwards.
*/
grunt.registerTask('dist', [
'clean',
'replace',
'copy',
'uglify',
'less:production',
'less:timeline',
'less:training',
'concat',
'uncss',
'cssmin',
'compare_size',
'processhtml',
'zip:production'
]);
};