forked from eXistSolutions/sarit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgruntfile.js
332 lines (302 loc) · 10 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
/*
*
* 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: {
pkg1: {
src: ['expath-pkg.tmpl'],
dest: 'expath-pkg.xml',
replacements: [
{
from: '@APPVERSION@',
to: '<%= xar.version %>'
},
{
from: '@APPNAME@',
to: '<%= xar.name %>'
},
{
from: '@APPDESCRIPTION@',
to: '<%= xar.description %>'
},
{
from: '@APPURL@',
to: '<%= xar.url %>'
}
]
},
pkg2: {
src: ['repo.tmpl'],
dest: 'repo.xml',
replacements: [
{
from: '@APPLICENSE@',
to: '<%= xar.license %>'
},
{
from: '@APPNAME@',
to: '<%= xar.name %>'
},
{
from: '@APPDESCRIPTION@',
to: '<%= xar.description %>'
},
{
from: '@APPAUTHOR@',
to: '<%= xar.author %>'
},
{
from: '@APPURL@',
to: '<%= xar.url %>'
}
]
}
},
/*
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: ['data/**', 'modules/**','resources/img/**', 'templates/**', 'content/**', '*.xconf','*.xql', '*.xml', '*.txt', '*.ico', '*.html','*.xhtml'],
dest: 'dist/'},
{expand: true,
cwd: './',
flatten: true,
src: ['components/font-awesome/fonts/**'],
dest: 'dist/resources/fonts/',
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: {
dist: {
files: {
'resources/js/app.min.js': [
'resources/js/app.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
},
dist: {
// 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/Macaroon/jquery.fs.macaroon.min.js',
'components/snap.svg/dist/snap.svg-min.js',
'resources/js/app.min.js'],
// the location of the resulting JS file
dest: 'dist/resources/js/app.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"
}
}
},
/*
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: {
options: {
ignore: [/.open.+\b/,'.collapsing', '.navbar-collapse', '.collapse.in'],
flatten: true
},
dist: {
src: ['./browse.html','./template.html'],
dest: 'resources/css/tidy.css'
}
},
/*
minify the already cleaned up CSS files
*/
cssmin: {
dist: {
options: {
compatibility: 'ie8',
keepSpecialComments: 0,
report: 'min'
},
files: {
'dist/resources/css/app.min.css': '<%= uncss.dist.dest %>'
}
}
},
/*
Gives statistical information about CSS compression results
*/
compare_size: {
files: [
'resources/css/*.css',
'dist/resources/css/app.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: {
dist: {
options: {
data: {
minifiedCss: '<link href="resources/css/app.min.css" type="text/css" rel="stylesheet"/>'
}
},
files: {
'dist/template.html': ['./template.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',
'*.xhtml',
'data/**',
'modules/**',
'resources/**',
'docs/**',
'templates/**',
'content/**',
'components/animate.css/*',
'components/bootstrap/dist/**',
'components/Macaroon/*',
'components/font-awesome/css/**',
'components/font-awesome/fonts/**',
'components/jquery/dist/**',
'components/snap.svg/dist/**'
],
dest: 'build/<%=xar.name%>-<%=xar.version%>.xar'
},
production: {
cwd: 'dist/',
src: ['dist/**'],
dest: 'build/<%=xar.name%>-<%=xar.version%>.min.xar'
}
},
/*
watches gruntfile itself and checks for problems
*/
watch: {
files: ['gruntfile.js'],
tasks: ['jshint']
}
});
/*
*/
grunt.registerTask('default', [
'replace',
'less:development',
'zip:xar'
]);
grunt.registerTask('dist', [
'clean',
'replace',
'copy',
'imagemin',
'uglify',
'less:production',
'concat',
'uncss',
'cssmin',
'compare_size',
'processhtml',
'zip:production'
]);
};