-
Notifications
You must be signed in to change notification settings - Fork 0
/
gruntFile.js
523 lines (477 loc) · 15.8 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
module.exports = function ( grunt ) {
/**
* Load required Grunt tasks. These are installed based on the versions listed
* in `package.json` when you do `npm install` in this directory.
*/
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-ngmin');
grunt.loadNpmTasks('grunt-html2js');
grunt.loadNpmTasks('grunt-plato');
/**
* Load in our build configuration file.
*/
var userConfig = require( './build.config.js' );
/**
* This is the configuration object Grunt uses to give each plugin its
* instructions.
*/
var taskConfig = {
/**
* We read in our `package.json` file so we can access the package name and
* version. It's already there, so we don't repeat ourselves here.npm
*/
pkg: grunt.file.readJSON("package.json"),
/**
* The banner is the comment that is placed at the top of our compiled
* source files. It is first processed as a Grunt template, where the `<%=`
* pairs are evaluated based on this very configuration object.
*/
meta: {
banner:
'/**\n' +
' * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' *\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> ICDC\n' +
' */\n'
},
/**
* The directories to delete when `grunt clean` is executed.
*/
clean: {
report: ['<%= report_dir %>'],
build: ['<%= build_dir %>'],
static_dist_dir: ['<%= static_dist_dir %>'],
release_dir: ['<%= release_dir %>'],
options: {
force: true
}
},
compress: {
dist: {
options: {
archive: '<%= static_dist_dir %>/<%= pkg.name %>-<%= pkg.version %>.zip'
},
cwd : '<%= release_dir %>',
src: ['**']
}
},
/**
* The `copy` task just copies files from A to B. We use it here to copy
* our project assets (images, fonts, etc.) and javascripts into
* `build_dir`, and then to copy the assets to `compile_dir`.
*/
copy: {
build_app_js: {
files: [
{
src: [ '<%= app_files.js %>' ],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true
}
]
},
build_jsunit: {
files: [
{
src: [ '<%= app_files.jsunit %>' ],
dest: '<%= build_dir %>/tests/unit',
cwd: '.',
expand: true,
flatten: true
}
]
},
build_mock_json: {
files: [
{
src: [ '<%= app_files.mock.json %>' ],
dest: '<%= build_dir %>/',
cwd: '.',
expand: true
}
]
},
dist: {
files: [
{
src: [ '<%= static_dist_dir %>/*.js', '<%= static_dist_dir %>/*.css' ],
dest: '<%= release_dir %>/',
cwd: '.',
expand: true
}
]
},
dist_index: {
files: [
{
src: [ 'index.min.html' ],
dest: '<%= release_dir %>/index.html',
cwd: '.'
}
]
},
dist_img: {
files: [
{
src: [ '<%= app_files.img %>' ],
dest: '<%= release_dir %>/assets',
cwd: '.'
}
]
}
},
/**
* `grunt concat` concatenates multiple source files into a single file.
*/
concat: {
/**
* The `compile_app_js` target is the concatenation of our application source
* code and all specified vendor source code into a single file.
*/
compile_app_js: {
options: {
banner: '<%= meta.banner %>'
},
src: [
'module.prefix',
'<%= app_files.js %>',
'module.suffix'
],
dest: '<%= static_dist_dir %>/<%= pkg.name %>.js'
},
build_app_css: {
src: [
'<%= vendor_files.css %>',
'<%= app_files.css %>'
],
dest: '<%= static_dist_dir %>/<%= pkg.name %>.css'
},
compile_vendor_js: {
options: {
},
src: [
'<%= vendor_files.js %>'
],
dest: '<%= static_dist_dir %>/<%= pkg.name %>-vendor.js'
}
},
/**
* `ng-min` annotates the sources before minifying. That is, it allows us
* to code without the array syntax.
*/
ngmin: {
compile: {
files: [
{
src: [ '<%= app_files.js %>' ],
cwd: '<%= build_dir %>',
dest: '<%= build_dir %>',
expand: true
}
]
}
},
/**
* Minify the sources!
*/
uglify: {
compile: {
options: {
banner: '<%= meta.banner %>',
mangle: false
},
files: {
'<%= static_dist_dir %>/<%= pkg.name %>.min.js': '<%= concat.compile_app_js.dest %>'
}
},
compile_vendor: {
options: {
mangle: false
},
files: {
'<%= static_dist_dir %>/elink-vendor.min.js': '<%= concat.compile_vendor_js.dest %>'
}
}
},
/**
* `jshint` defines the rules of our linter as well as which files we
* should check. This file, all javascript sources, and all our unit tests
* are linted based on the policies listed in `options`. But we can also
* specify exclusionary patterns by prefixing them with an exclamation
* point (!); this is useful when code comes from a third party but is
* nonetheless inside `src/`.
*
* On joue jshint sur les sources du projet pour faciliter la correction et l'identification du pb
*
* http://jshint.com/docs/options/
*/
jshint: {
beforeconcat : {
src: [
'<%= app_files.js %>'
],
test: [
'<%= app_files.jsunit %>'
],
options: {
"asi": true,
"bitwise": false,
"boss" : true,
"browser": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"eqnull" : true,
"esnext": true,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"node": true,
"regexp": true,
"smarttabs": false,
"strict": false,
"sub" : true,
"trailing": true,
"undef": true,
"unused": true,
"white": false,
"-W099": true,
"-W116": true,
"predef": ["angular"]
}
},
afterconcat : {
src: [
'<%= static_dist_dir %>/<%= pkg.name %>.js'
],
options: {
"asi": true,
"bitwise": false,
"boss" : true,
"browser": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"eqnull" : true,
"esnext": true,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"node": true,
"regexp": true,
"smarttabs": false,
"strict": false,
"sub" : true,
"trailing": true,
"undef": true,
"unused": true,
"white": false,
"-W099": true,
"-W116": true,
"predef": ["angular"]
},
globals: {}
}
},
/**
* rapport qualimétrie
*/
plato: {
report: {
options : {
complexity : {
},
jshint: {
"asi": true,
"bitwise": false,
"boss" : true,
"browser": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"eqnull" : true,
"esnext": true,
"immed": true,
"latedef": false,
"newcap": true,
"noarg": true,
"node": true,
"regexp": true,
"smarttabs": false,
"strict": false,
"sub" : true,
"trailing": true,
"undef": true,
"unused": true,
"white": false,
"-W099": true,
"-W116": true,
"predef": ["angular"]
}
},
files: {
'<%= report_dir %>': ['<%= app_files.js %>']
}
}
},
/**
* HTML2JS is a Grunt plugin that takes all of your template files and
* places them into JavaScript files as strings that are added to
* AngularJS's template cache. This means that the templates too become
* part of the initial payload as one JavaScript file. Neat!
*/
html2js: {
/**
* These are the templates from `ngviews`.
*/
app: {
src: [ '<%= app_files.tpl %>' ],
dest: '<%= static_dist_dir %>/templates-views.js'
}
},
/**
* The Karma configurations.
*/
karma: {
options: {
configFile: '<%= build_dir %>/karma-unit.js'
},
watch: {
runnerPort: 9101,
background: true
},
run: {
singleRun: true
}
},
/**
* This task compiles the karma template so that changes to its file array
* don't have to be managed manually.
*/
karmaconfig: {
unit: {
dir: '<%= build_dir %>',
src: [
'<%= vendor_files.js %>',
'<%= test_files.js %>'
]
}
},
};
grunt.initConfig( grunt.util._.extend( taskConfig, userConfig ) );
grunt.file.setBase('.');
/**
* In order to make it safe to just compile or copy *only* what was changed,
* we need to ensure we are starting from a clean, fresh build. So we rename
* the `watch` task to `delta` (that's why the configuration var above is
* `delta`) and then add a new task called `watch` that does a clean build
* before watching for changes.
*/
grunt.renameTask( 'watch', 'delta' );
grunt.registerTask( 'watch', [ 'dev', 'delta' ] );
/**
* Tâche par défaut sur la commande 'grunt"
*/
grunt.registerTask( 'default', [ 'dev' ] );
/**
* Tâches usuelles en mode developpement
* - jshint va aider au debug
* - lancement des tests unitaires
* Travail sur les ressources classiques, non concaténé ou minifiée
*/
grunt.registerTask( 'dev', [
'jshint:beforeconcat',
'tests'
]);
/**
* Rapport qualimetrie
*/
grunt.registerTask( 'report', [
'clean:report',
'plato:report'
]);
/**
* Tests unitaires
*/
grunt.registerTask( 'tests', [
'karmaconfig',
'karma',
]);
/**
* concatenation/minification des ressources js et css
* html2js pour les vues Angular
* Suite à cette tâche, on peut utiliser le fichier index.min.html
*/
grunt.registerTask( 'package', [
'clean:build', 'clean:static_dist_dir',
'copy:build_app_js',
'html2js',
'ngmin',
'concat',
'uglify',
]);
/**
* Zip le contenu du repertoire release-dist et pose le fichier resultat dans le repertoire static-dist
*/
grunt.registerTask( 'make_bin', [
'compress:dist'
]);
/**
* Exporte les fichiers nécessaires à la mise en production
* On ne prend que les fichiers suite à concatenation/minification et le fichier index.min.html,
* renommer en index.html dans le répertoire cible.
* Zip l'ensemble dans le static-dist
*/
grunt.registerTask( 'dist', [
'clean:release_dir',
'package',
'copy:dist', 'copy:dist_index', 'copy:dist_img',
'make_bin'
]);
grunt.registerTask( 'release', [
'dist'
]);
/**
* In order to avoid having to specify manually the files needed for karma to
* run, we use grunt to manage the list for us. The `karma/*` files are
* compiled as grunt templates for use by Karma. Yay!
*/
grunt.registerMultiTask( 'karmaconfig', 'Process karma config templates', function () {
var jsFiles = filterForJS( this.filesSrc );
grunt.file.copy( 'src/test/config/karma-unit.tpl.js', grunt.config( 'build_dir' ) + '/karma-unit.js', {
process: function ( contents, path ) {
return grunt.template.process( contents, {
data: {
scripts: jsFiles
}
});
}
});
});
/**
* A utility function to get all app JavaScript sources.
*/
function filterForJS ( files ) {
return files.filter( function ( file ) {
return file.match( /\.js$/ );
});
}
/**
* A utility function to get all app CSS sources.
*/
function filterForCSS ( files ) {
return files.filter( function ( file ) {
return file.match( /\.css$/ );
});
}
};