forked from sequentech/voting-booth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·404 lines (381 loc) · 14 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
/**
* This file is part of agora-gui-booth.
* Copyright (C) 2015-2016 Agora Voting SL <[email protected]>
* agora-gui-booth is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* agora-gui-booth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with agora-gui-booth. If not, see <http://www.gnu.org/licenses/>.
**/
/*jslint node: true */
'use strict';
var pkg = require('./package.json');
var AV_CONFIG_VERSION = '3.3.0';
//Using exclusion patterns slows down Grunt significantly
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
//this method is used to create a set of inclusive patterns for all subdirectories
//skipping node_modules, bower_components, dist, and any .dirs
//This enables users to create any directory structure they desire.
var createFolderGlobs = function(fileTypePatterns) {
fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
var ignore = ['node_modules','bower_components','dist','temp'];
var fs = require('fs');
return fs.readdirSync(process.cwd())
.map(function(file){
if (ignore.indexOf(file) !== -1 ||
file.indexOf('.') === 0 ||
!fs.lstatSync(file).isDirectory()) {
return null;
} else {
return fileTypePatterns.map(function(pattern) {
return file + '/**/' + pattern;
});
}
})
.filter(function(patterns){
return patterns;
})
.concat(fileTypePatterns);
};
module.exports = function (grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// custom grunt task to check avConfig.js
grunt.registerTask('check_config', function() {
var fs = require('fs');
var done = this.async();
grunt.log.ok('Checking avConfig.js...');
var conf = fs.readFile('avConfig.js', function(err, data) {
if (err) {
grunt.log.error('No avConfig.js file found');
done(false);
} else {
var match = data.toString().match(/AV_CONFIG_VERSION = [\'\"]([\w\.]*)[\'\"];/);
if (!match) {
grunt.log.error('Invalid avConfig.js version');
} else {
var v = match[1];
if (v === AV_CONFIG_VERSION) {
return done();
} else {
grunt.log.error('Invalid avConfig.js version: ' + v);
}
}
done(false);
}
});
});
// Project configuration.
grunt.initConfig({
variables: {
booth_html_body_include: ''
},
connect: {
main: {
options: {
port: 9001
}
}
},
watch: {
main: {
options: {
livereload: true,
livereloadOnError: false,
spawn: false
},
files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: createFolderGlobs('*.js')
}
},
clean: {
before:{
src:['dist','temp']
},
after: {
src:['temp']
}
},
less: {
production: {
options: {
},
files: [{
expand: true,
src: ['bower_components/avCommon/themes/**/app.less'],
dest: 'temp/',
ext: '.css',
}]
}
},
autoprefixer: {
options: {
browsers: ['ie >= 8', 'ff > 4', 'last 8 versions']
},
main: {
src: 'temp/bower_components/avCommon/themes/**/app.css'
}
},
ngtemplates: {
main: {
options: {
module: pkg.name,
htmlmin:'<%= htmlmin.main.options %>'
},
src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{src: ['img/**'], dest: 'dist/'},
{src: ['img/**'], dest: 'dist/'},
{src: ['temp_data/**'], dest: 'dist/'},
{
expand: true,
cwd:'bower_components/avCommon/themes',
src: ['**/*.png'],
dest: 'dist/themes/',
ext: '.png',
extDot: 'first'
},
{
expand: true,
cwd: 'bower_components/bootstrap/fonts/',
src: ['**'],
dest: 'dist/themes/fonts/'
},
{
expand: true,
cwd: 'bower_components/bootstrap/fonts/',
src: ['**'],
dest: 'dist/themes/fonts/'
},
{
expand: true,
cwd: 'bower_components/font-awesome/fonts/',
src: ['**'],
dest: 'dist/fonts/'
}
//{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
//{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'dist/css/',flatten:true,expand:true},
//{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'dist/'}
]
}
},
dom_munger:{
read: {
options: {
read:[
{selector:'script[class="libnocompat"]',attribute:'src',writeto:'libnocompatjs'},
{selector:'script[class="libcompat"]',attribute:'src',writeto:'libcompatjs'},
{selector:'script[class="lib"]',attribute:'src',writeto:'libjs'},
{selector:'script[class="app"]',attribute:'src',writeto:'appjs'},
{selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
]
},
src: 'index.html'
},
update: {
options: {
remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
append: [
{selector:'body',html:'<%= variables.booth_html_body_include %>'},
{selector:'body',html:'<!--[if lte IE 8]><script src="/booth/libcompat-v3.0.1.min.js"></script><![endif]--><!--[if gte IE 9]><script src="/booth/libnocompat-v3.0.1.min.js"></script><![endif]--><!--[if !IE]><!--><script src="/booth/libnocompat-v3.0.1.min.js"></script><!--<![endif]-->'},
{selector:'body',html:'<!--All the source code of this program under copyright. Take a look at the license details at https://github.com/agoravoting/agora-core-view/blob/master/README.md -->'},
{selector:'body',html:'<script src="/booth/lib-v3.0.1.min.js"></script>'},
{selector:'body',html:'<script src="/booth/avConfig-v3.0.1.js"></script>'},
{selector:'body',html:'<script src="/booth/avThemes-v3.0.1.js"></script>'},
{selector:'body',html:'<script src="/booth/app-v3.0.1.min.js"></script>'},
{selector:'body',html:'<script src="/booth/avPlugins-v3.0.1.js"></script>'},
{selector:'head',html:'<link rel="stylesheet" id="theme" data-base="/booth/" href="/booth/themes/default/app.min.css">'}
]
},
src:'index.html',
dest: 'dist/index.html'
}
},
cssmin: {
main: {
files: [{
expand: true,
cwd:'temp/bower_components/avCommon/themes',
src: ['**/app.css'],
dest: 'dist/themes/',
ext: '.min.css',
extDot: 'first'
}]
},
},
concat: {
main: {
files: {
'temp/libcompat.js': [
'bower_components/avCommon/dist/libcompat-v3.0.1.js',
'<%= dom_munger.data.libcompatjs %>'
],
'temp/libnocompat.js': [
'bower_components/avCommon/dist/libnocompat-v3.0.1.js',
'<%= dom_munger.data.libnocompatjs %>'
],
'temp/lib.js': ['<%= dom_munger.data.libjs %>'],
'temp/app.js': ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
'dist/avConfig-v3.0.1.js': ['avConfig.js'],
'dist/avThemes-v3.0.1.js': ['bower_components/avCommon/dist/avThemes-v3.0.1.js'],
'dist/avPlugins-v3.0.1.js': ['plugins/**/*.js']
}
}
},
"merge-json": {
main: {
files: {
"dist/locales/en.json": ["locales/en.json", "plugins/**/locales/en.json", "bower_components/avCommon/locales/en.json"],
"dist/locales/es.json": ["locales/es.json", "plugins/**/locales/es.json", "bower_components/avCommon/locales/es.json"],
"dist/locales/gl.json": ["locales/gl.json", "plugins/**/locales/gl.json", "bower_components/avCommon/locales/gl.json"],
"dist/locales/ca.json": ["locales/ca.json", "plugins/**/locales/ca.json", "bower_components/avCommon/locales/ca.json"]
}
}
},
ngAnnotate: {
main: {
files: {
'temp/app.js':['temp/app.js'],
'temp/lib.js': ['temp/lib.js'],
'temp/libnocompat.js': ['temp/libnocompat.js'],
'temp/libcompat.js': ['temp/libcompat.js']
}
}
},
uglify: {
main: {
options:{
mangle: false,
compress: {},
beautify: true
},
files: {
'dist/app-v3.0.1.min.js': 'temp/app.js',
'dist/lib-v3.0.1.min.js': 'temp/lib.js',
'dist/libnocompat-v3.0.1.min.js': 'temp/libnocompat.js',
'dist/libcompat-v3.0.1.min.js': 'temp/libcompat.js',
'dist/avWidgets.min.js': 'avWidgets.js',
"dist/locales/moment/en.js": "bower_components/moment/lang/en-gb.js",
"dist/locales/moment/es.js": "bower_components/moment/lang/es.js",
"dist/locales/moment/gl.js": "bower_components/moment/lang/gl.js",
"dist/locales/moment/ca.js": "bower_components/moment/lang/ca.js"
}
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: false,
removeComments: false,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
},
karma: {
options: {
frameworks: ['jasmine'],
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.libnocompatjs %>',
'<%= dom_munger.data.libjs %>',
'avConfig.js',
'avThemes.js',
'avWidgets.js',
'<%= dom_munger.data.appjs %>',
'<%= ngtemplates.main.dest %>',
'bower_components/angular-mocks/angular-mocks.js',
createFolderGlobs('*-spec.js')
],
logLevel:'ERROR',
reporters:['mocha'],
autoWatch: false, //watching is handled by grunt-contrib-watch
singleRun: true
},
all_tests: {
browsers: ['PhantomJS','Chrome','Firefox']
},
during_watch: {
browsers: ['PhantomJS']
},
},
protractor: {
options: {
configFile: "node_modules/protractor/referenceConf.js", // Default config file
keepAlive: true, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
args: {
// Arguments passed to the command
}
},
//your_target: { // Grunt requires at least one target to run so you can simply put 'all: {}' here too.
all: {
options: {
configFile: "e2e.conf.js", // Target-specific config file
args: {} // Target-specific arguments
}
},
},
});
grunt.registerTask('build',['check_config', 'jshint','clean:before','less','autoprefixer','dom_munger','ngtemplates','cssmin','concat','merge-json','ngAnnotate','uglify','copy','htmlmin','clean:after']);
grunt.registerTask('serve', ['dom_munger:read','jshint','connect', 'watch']);
grunt.registerTask('test',['dom_munger:read','karma:all_tests']);
grunt.event.on('watch', function(action, filepath) {
//https://github.com/gruntjs/grunt-contrib-watch/issues/156
var tasksToRun = [];
if ((filepath.lastIndexOf('.json') !== -1 && filepath.lastIndexOf('.json') === filepath.length - 5) ||
(filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3)) {
//lint the changed js file
grunt.config('jshint.main.src', filepath);
tasksToRun.push('jshint');
//find the appropriate unit t est for the changed file
var spec = filepath;
if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
}
//if the spec exists then lets run it
if (grunt.file.exists(spec)) {
var files = [].concat(grunt.config('dom_munger.data.libnocompatjs'));
files.concat(grunt.config('dom_munger.data.libjs'));
files.push('bower_components/angular-mocks/angular-mocks.js');
files.push('avConfig.js');
files.push('avThemes.js');
files.push('avWidgets.js');
files.concat(grunt.config('dom_munger.data.appjs'));
files.concat(grunt.config('ngtemplates.main.dest'));
files.push(spec);
grunt.config('karma.options.files', files);
tasksToRun.push('karma:during_watch');
}
}
//if index.html changed, we need to reread the <script> tags so our next run of karma
//will have the correct environment
if (filepath === 'index.html') {
tasksToRun.push('dom_munger:read');
}
grunt.config('watch.main.tasks',tasksToRun);
});
grunt.loadNpmTasks('grunt-protractor-runner');
};