/
Gruntfile.js
509 lines (461 loc) · 18.6 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
module.exports = function (grunt) {
/** ================================================
* Project configuration
==================================================*/
grunt.initConfig({
/** Load informations from package.json */
pkg: grunt.file.readJSON('package.json'),
/** The current target file for the watch tasks */
currentWatchFile: '',
/** Local directory for the tests */
webServerDir: 'www',
buildDir: 'target',
/** Paths for the different types of ressource */
srcPath: {
js : 'js/**/*.js',
test_js : 'tests/js/**/*.js',
less : 'style/**/*.less',
html : '**/*.html',
tmpl : 'templates/*.tmpl',
tests : 'tests/',
www : '<%= webServerDir %>/**/*',
locales : 'locales/**/*.json'
},
profiles: {
// Default profile if no one is given
default: 'local',
integration: {
sources : '',
target : '../opencast-backend/annotation-tool/src/main/resources/ui/',
config : 'build/profiles/integration/annotation-tool-configuration.js'
},
local: {
sources: '<source src=\"/resources/aav1.mp4\" type=\"video/mp4\" />\n \
<source src=\"/resources/aav1.webm\" type=\"video/webm\" />\n \
<source src=\"/resources/aav1.ogv\" type=\"video/ogg\" /> ',
target : '<%= webServerDir %>',
config : 'build/profiles/local/annotation-tool-configuration.js'
},
build: {
sources: '<source src=\"/resources/Annotations_Video.mp4\" type=\"video/mp4\" />\n \
<source src=\"/resources/Annotations_Video.webm\" type=\"video/webm\" />\n \
<source src=\"/resources/Annotations_Video.theora.ogv\" type=\"video/ogg\" /> ',
target : '<%= buildDir %>',
config : 'build/profiles/local/annotation-tool-configuration.js'
},
demo: {
sources: '<source src=\"/annotation/resources/sinteltrailer.mp4\" type=\"video/mp4\" />\n \
<source src=\"/annotation/resources/sinteltrailer.ogv\" type=\"video/ogg\" /> ',
target : '/var/www/html/annotation/',
config : 'build/profiles/local/annotation-tool-configuration.js'
}
},
currentProfile: { sources: 'test' },
jshint: {
options: {
jshintrc: '.jshintrc'
},
all : ['Gruntfile.js', '<%= srcPath.js %>'],
watch : '<%= currentWatchFile %>'
},
/** Task to watch src files and process them */
watch: {
options: {
nospawn: true
},
// Watch Javascript files
js: {
files: ['<%= srcPath.js %>', '<%= srcPath.test_js %>'],
tasks: ['copy:target']
},
// Watch Templates files
templates: {
files: ['<%= srcPath.tmpl %>'],
tasks: ['handlebars:target']
},
// Watch HTML files
html: {
files: ['<%= srcPath.html %>'],
tasks: ['processhtml:dev']
},
// Watch LESS files
less: {
files: ['<%= srcPath.less %>'],
tasks: ['less', 'copy:less']
},
// Watch the LESS, Javascript, Templates and HTML at the same times
// Use it for single core processor. It could stop working with an important number of files
multiple: {
files: ['<%= srcPath.less %>', '<%= srcPath.js %>', '<%= srcPath.html %>', '<%= srcPath.tmpl %>'],
tasks: ['copy:target']
},
locales: {
files: ['<%= srcPath.locales %>'],
tasks: ['copy:locales']
},
// Watch file on web server for live reload
www: {
options: {
livereload: true,
nospawn: true
},
files: ['<%= srcPath.www %>']
}
},
/** Compile the less files into a CSS file */
less: {
options: {
paths: 'style',
version: 'node_modules/less',
syncImport: true,
compress: true,
sourceMap: { outputSourceFiles: true },
sourceMapBasepath: 'style'
},
files: {
src: 'style/style.less',
dest: '<%= currentProfile.target %>/style/style.css'
}
},
/** Pre-compile the handlebars templates */
handlebars: {
target: {
options: {
namespace: false,
amd: true
},
files: [{
ext: '.js',
flatten : false,
expand : true,
src: '<%= currentWatchFile %>',
dest: '<%= currentProfile.target %>',
filter: 'isFile'
}]
},
all: {
options: {
namespace: false,
amd: true
},
files: [{
ext: '.js',
flatten : false,
expand : true,
src: 'templates/*.tmpl',
dest: '<%= currentProfile.target %>'
}]
},
temp: {
options: {
namespace: false,
amd: true
},
files: [{
ext: '.js',
flatten : false,
expand : true,
src: 'templates/*.tmpl',
dest: 'target'
}]
}
},
/** Copy .. */
copy: {
options: {
processContent: function (content, srcPath) {
if (srcPath === 'js/version.js') {
return grunt.template.process(content, { data: { version: grunt.config.get('pkg').version } });
}
return content;
},
processContentExclude: ['img/**/*', 'resources/**/*']
},
// ... a single file locally
'target': {
files: [{
flatten : false,
expand : true,
src : '<%= currentWatchFile %>',
dest : '<%= currentProfile.target %>',
filter : 'isFile'
}]
},
// ... all the tool files locally
'local-all': {
files: [{
flatten : false,
expand : true,
src : ['js/**/*', 'img/**/*', 'style/**/.svg', 'style/**/*.png', 'style/**/*.css', 'resources/*', 'tests/**/*'],
dest : '<%= currentProfile.target %>'
}]
},
// ... the index locally
'local-index': {
src: 'index.html',
dest: '<%= webServerDir %>/index.html'
},
// ... all the tool files for the current profile
'all': {
files: [{
flatten: false,
expand: true,
src: ['js/**/*', 'img/**/*', 'style/**/*.svg', 'style/**/*.png', 'style/**/*.css', 'resources/*', 'tests/**/*'],
dest: '<%= currentProfile.target %>'
}]
},
// ... all the files for an optimized build
'build': {
files: [{
flatten: false,
expand: true,
src: ['img/**/*', 'style/**/*.svg', 'style/**/*.png', 'style/**/*.css', 'resources/*', 'js/libs/**/*'],
dest: '<%= currentProfile.target %>'
}]
},
// ... all the files for the demo
'demo': {
files: [{
flatten: false,
expand: true,
src: ['js/**/*', 'img/**/*', 'style/**/*.svg', 'style/**/*.png', 'resources/*', 'style/**/*.css', 'tests/**/*'],
dest: '<%= currentProfile.target %>'
}]
},
'integration': {
files: [{
flatten: false,
expand: true,
src: ['js/**/*', 'img/**/*', 'style/**/*.svg', 'style/**/*.png', 'style/**/*.css', 'tests/**/*'],
dest: '<%= currentProfile.target %>'
}]
},
// ... the index locally
'index': {
options: {
processContent: function (content) {
return grunt.template.process(content);
}
},
src: 'index.html',
dest: '<%= currentProfile.target %>/index.html'
},
// ... the less sources for the sourcemaps to reference during development
'less': {
files: [{
src: '<%= srcPath.less %>',
dest: '<%= currentProfile.target %>',
expand: true
}]
},
// ... the configuration
'config': {
src: '<%= currentProfile.config %>',
dest: '<%= currentProfile.target %>/js/annotation-tool-configuration.js'
},
// ... the translations
'locales': {
files: [{
src: '<%= srcPath.locales %>',
dest: '<%= currentProfile.target %>',
expand: true
}]
}
},
blanket_qunit: {
all: {
options: {
urls: [
'<%= srcPath.tests %>loop.html?coverage=true&gruntReport',
'<%= srcPath.tests %>collections.html?coverage=true&gruntReport',
'<%= srcPath.tests %>models.html?coverage=true&gruntReport'
],
threshold: 10,
globalThreshold: 10
}
}
},
jsdoc : {
dist : {
src: ['js/views/*.js', 'js/collections/*.js', 'js/models/*.js', 'js/prototypes/*.js'],
options: {
destination: '<%= currentProfile.target %>/doc',
template: 'node_modules/ink-docstrap/template'
}
}
},
/** Task to run tasks in parrallel */
concurrent: {
dev: {
tasks: ['watch:js', 'watch:html', 'watch:less', 'watch:templates', 'watch:locales', 'watch:www', 'connect:dev'],
options: {
logConcurrentOutput: true,
limit: 7
}
}
},
/** Web server */
connect: {
dev: {
options: {
port: 9001,
base: '<%= webServerDir %>',
keepalive: true,
livereload: true
}
},
build: {
options: {
port: 9001,
base: '<%= buildDir %>',
keepalive: true,
livereload: true
}
}
},
/** Preprocess file with right context */
processhtml: {
options: {
data: {
version: '<%= pkg.version %>',
sources: '<%= currentProfile.sources %>'
},
process: true
},
dev: {
files: {
'<%= currentProfile.target %>/index.html': ['index.html']
}
},
build: {
files: {
'<%= currentProfile.target %>/index.html': ['index.html']
}
}
},
/** Optimisation through requireJS */
requirejs: {
compile: {
options: {
baseUrl : './js',
mainConfigFile : './js/libs/require/config/config-build.js',
name : 'main',
optimizeAllPluginResources : false,
preserveLicenseComments : false,
optimize : 'uglify',
useStrict : true,
findNestedDependencies : true,
out : '<%= currentProfile.target %>/optimized.js'
}
}
},
mkdir: {
demo: {
options: {
create: ['<%= currentProfile.target %>']
}
}
},
gulp: {
i18next: function () {
const gulp = require('gulp');
const i18next = require('i18next-parser');
return gulp.src([
'index.html',
grunt.config.get('srcPath.js'),
grunt.config.get('srcPath.tmpl'),
'!js/libs/**/*',
'!js/handlebarsHelpers.js'
]).pipe(i18next({
locales: ['en', 'de'],
ignoreVariables: true
})).pipe(gulp.dest('locales'));
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
//grunt.loadNpmTasks('grunt-blanket-qunit');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-handlebars');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-processhtml');
grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-gulp');
grunt.loadNpmTasks('assemble-less');
/** ================================================
* Register custom tasks
==================================================*/
// Default task
grunt.registerTask('default', ['jshint:all', 'less', 'copy:local-all', 'copy:local-index']);
grunt.registerTask('baseDEV', ['handlebars:all', 'less', 'copy:all', 'processhtml:dev', 'copy:less', 'copy:config', 'copy:locales', 'concurrent:dev']);
grunt.registerTask('baseDEMO', ['mkdir:demo', 'handlebars:all', 'less', 'copy:demo', 'processhtml:dev', 'copy:config', 'copy:locales']);
//grunt.registerTask('baseBUILD', ['blanket_qunit', 'jsdoc', 'less', 'copy:build', 'processhtml:build', 'copy:config', 'requirejs']);
grunt.registerTask('baseBUILD', [/*'blanket_qunit', */'jsdoc', 'handlebars:temp', 'less', 'copy:build', 'processhtml:build', 'copy:config', 'copy:locales', 'requirejs']);
grunt.registerTask('baseINTEGRATION', ['handlebars:all', 'less', 'copy:integration', 'processhtml:dev', 'copy:config', 'copy:locales']);
grunt.registerTask('baseINTEGRATIONMINIFIED', ['blanket_qunit', 'handlebars:temp', 'less', 'copy:integration', 'processhtml:build', 'copy:config', 'copy:locales', 'requirejs']);
grunt.registerTaskWithProfile = function (name, description, defaultProfile) {
grunt.registerTask(name, description, function () {
var profileName = grunt.option('profile') || defaultProfile,
profileConfig;
if (grunt.option('cv')) {
console.log('With version ' + grunt.option('cv'));
grunt.config.set('pkg.version', grunt.option('cv'));
}
// If no profile name given, use the default one
if (typeof profileName == 'undefined') {
profileName = grunt.config.get('profiles.default');
grunt.option('profile', profileName);
grunt.log.writeln('No profile name given as option, use default one.');
}
// Get the profile configuration
profileConfig = grunt.config.get('profiles.' + profileName);
// Check if the profile exist
if (typeof profileConfig == 'undefined') {
grunt.fail.fatal('The profile "' + profileName + '" does not exist in the Gruntfile.');
}
grunt.log.writeln(name + ' task with profile "' + profileName + '" started! ');
// Configure the tasks with given profiles
grunt.config.set('currentProfile', profileConfig);
// if (name.toUpperCase() === "DEMO") {
// grunt.config.set('currentProfile.target', grunt.config.get('currentProfile.target') + grunt.config.get('pkg.version'));
// }
// Run the tasks
grunt.task.run('base' + name.toUpperCase());
});
};
grunt.registerTaskWithProfile('build', 'Build task', 'build');
grunt.registerTaskWithProfile('demo', 'Generate build for demo', 'demo');
grunt.registerTaskWithProfile('integration', 'Deploy webapp in Opencast backend', 'integration');
grunt.registerTaskWithProfile('integrationminified', 'Deploy webapp in Opencast backend as minified version', 'integration');
grunt.registerTaskWithProfile('dev', 'Development workflow');
/** ================================================
* Listerers
==================================================*/
// on watch events configure jshint:watch to only run on changed file
grunt.event.on('watch', function (action, filepath, target) {
// Set the current file processed for the different tasks
grunt.config.set('currentWatchFile', [filepath]);
// Configure the tasks with given profiles
grunt.config.set('currentProfile', grunt.config.get('profiles.' + grunt.option('profile')));
if (target == 'multiple') {
// If the watch target is multiple,
// we manage the tasks to run following the touched file extension
var ext = filepath.split('.').pop();
switch (ext) {
case 'js':
grunt.task.run('jshint:watch');
grunt.task.run('blanket_qunit');
break;
case 'less':
grunt.task.run('less');
grunt.task.run('copy:less');
break;
}
}
});
};