-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
605 lines (469 loc) · 16 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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/* Paths */
// Source
// source editing assets (/themes/assets/) : css/less
//# theme_path_src
// source default theme
//# theme_default_path_src
//prod
// prod asset path : /public/themes/
//# theme_path
// prod default theme
//# theme_default_path
// dev
// dev asset path : /public/dev-themes/
//# theme_path_dev
// dev default theme
//# theme_default_dev
/*
fonts sont gérés directement dans /public/assets/fonts (dev et prod) PAS DE THEMING pour FONTS
img est géré directement dans /public/themes/img (dev et prod)
css/js/less est géré dans /themes/assets/ (dev)
grunt s’occupe de tout copier/minimiser/optimisé dans /public/dev-themes (dev) et /public/themes (prod)
Dans /themes/assets/ je m’occupe uniquement des LESS, et CSS/JS
*/
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
/* setup variables */
assets = grunt.file.readJSON('app/config/development/app-assets-grunt.json');
themes_data = grunt.file.readJSON('app/config/development/app-themes.json');
var themes = [];
for (key in themes_data) {
themes.push(key);
}
/**
* compile LESS and minify twitter bootstrap themes
*/
var less_packages = assets.less_packages;
/**
* minify CSS files in default theme
*/
var css_to_minify = assets.css_to_minify;
/**
* minify JS files in default theme
*/
var jsfiles_to_minify = assets.jsfiles_to_minify;
/**
* Concat/minify JS files in default theme
*/
var js_to_concat = assets.js_to_concat;
/**
* Concat/minify CSS files in default theme
*/
var css_to_concat = assets.css_to_concat;
/* End Setup */
/* Paths */
var theme_path = assets.path_compilation;
var theme_path_dev = assets.path_dev;
var theme_path_src = assets.path_source;
var theme_default_path = theme_path+'default/';
var theme_default_dev = theme_path_dev+'default/';
var theme_default_path_src = theme_path_src+'default/assets/';
// create objects for pass data to grunt
var less_tasks = new Object;
var css_minify_data = new Object;
var js_uglify_data = new Object;
var copy_assets_data = new Object;
var watch_data = new Object;
var config_file_data = new Object;
var compile_less_all_datatask = [];
var minify_all_datatask = [];
var minify_datatask = [];
var uglify_datatask = [];
var copy_assets_all_datatask = [];
var all_datatask = [];
var conc_datatask = [];
var conc_css_datatask = [];
var conc_js_datatask = [];
// options for less dist
var less_options_dist = {
cleancss: true,
compress: true,
relativeUrls: true
};
// options for less dev
var less_options_dev = {
sourceMap: true,
dumpLineNumbers: 'comments',
relativeUrls: true
};
var tasks_memo='Grunt Memo Tasks\n\n\n';
/* write main tasks memo */
tasks_memo += 'Global Tasks\n';
tasks_memo += '\t• grunt all \t\t: Does all tasks\n';
tasks_memo += '\t• grunt min_less \t: Compile all less data\n';
tasks_memo += '\t• grunt min_assets \t: Minify all Assets data\n';
tasks_memo += '\t• grunt min_js \t\t: Minify all JS data\n';
tasks_memo += '\t• grunt min_css \t: Minify all CSS data\n';
tasks_memo += '\t• grunt conc_js \t: Concate all JS data\n';
tasks_memo += '\t• grunt conc_css \t: Concate all CSS data\n';
// tasks_memo += '\t• grunt copy_assets : Copy all assets (img/fonts) to public themes\n\n\n';
/**
*
* copy with watch data setup for copy assets on every themes
*
*/
tasks_memo += 'Copy assets Tasks\n\n';
for (var i = themes.length - 1; i >= 0; i--) {
tasks_memo += '\n\tCopy Task on Theme '+themes[i]+'\n';
// copy css to dev : /public/dev-themes/
copy_assets_data['css_dev_'+themes[i]] = {
files: [
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/css/',
src: ['**/*.css'],
dest: theme_path_dev+themes[i]+'/css/',
filter: 'isFile',
flatten: false
},
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/css/',
src: ['**/*.css'],
dest: theme_path+themes[i]+'/css/',
filter: 'isFile',
flatten: false
}
]
}
// copy js to dev : /public/dev-themes/
copy_assets_data['js_dev_'+themes[i]] = {
files: [
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/js/',
src: ['**/*.js'],
dest: theme_path_dev+themes[i]+'/js/',
filter: 'isFile',
flatten: false
},
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/js/',
src: ['**/*.js'],
dest: theme_path+themes[i]+'/js/',
filter: 'isFile',
flatten: false
}
]
}
// copy FONT dev (/public/dev-themes/) to prod (/themes/assets/)
copy_assets_data['fonts_'+themes[i]] = {
files: [{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/fonts/',
src: ['**/*.{eot,ttf,svg,woff,otf,html}'],
dest: theme_path+themes[i]+'/fonts/',
filter: 'isFile',
flatten: false
}]
}
// copy css to dev : /public/dev-themes/
copy_assets_data['img_'+themes[i]] = {
files: [
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/img/',
src: ['**/*.{img,jpg,svg,png,jpeg,gif}'],
dest: theme_path_dev+themes[i]+'/img/',
filter: 'isFile',
flatten: false
},
{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/img/',
src: ['**/*.{img,jpg,svg,png,jpeg,gif}'],
dest: theme_path+themes[i]+'/img/',
filter: 'isFile',
flatten: false
},
]
}
tasks_memo += '\t\t'+'copy css to dev :';
tasks_memo += '\t'+'grunt copy:css_dev_'+themes[i]+'\n';
tasks_memo += '\t\t'+'copy js to dev :';
tasks_memo += '\t'+'grunt copy:js_dev_'+themes[i]+'\n';
tasks_memo += '\t\t'+'copy FONT dev to prod :';
tasks_memo += '\t'+'grunt copy:fonts_'+themes[i]+'\n';
tasks_memo += '\t\t'+'copy IMG dev to prod :';
tasks_memo += '\t'+'grunt copy:img_'+themes[i]+'\n';
/**
* Watch setup
*/
// watch copy setup
// watch CSS from /themes/assets/ to public dev
var watchFiles = theme_path_src+themes[i]+'/assets/css/**/*.css';
var watchTasks = ["copy:css_dev_"+themes[i]];
watch_data['copy_assets_css_'+themes[i]] = {
files : watchFiles,
tasks : watchTasks
};
// watch JS from /themes/assets/ to public dev
var watchFiles = theme_path_src+themes[i]+'/assets/js/**/*.js';
var watchTasks = ["copy:js_dev_"+themes[i]];
watch_data['copy_assets_js_'+themes[i]] = {
files : watchFiles,
tasks : watchTasks
};
// watch FONT from dev to prod
var watchFiles = theme_path_src+themes[i]+'/assets/fonts/*';
var watchTasks = ["copy:fonts_"+themes[i]];
watch_data['copy_assets_fonts_'+themes[i]] = {
files : watchFiles,
tasks : watchTasks
};
// watch IMG from dev to prod
var watchFiles = theme_path_src+themes[i]+'/assets/img/*';
var watchTasks = ["copy:img_"+themes[i]];
watch_data['copy_assets_img_'+themes[i]] = {
files : watchFiles,
tasks : watchTasks
};
// console.log(theme_path_src+themes[i]+'/assets/fonts/*');
all_datatask.push("copy:css_dev_"+themes[i]);
all_datatask.push("copy:js_dev_"+themes[i]);
all_datatask.push("copy:fonts_"+themes[i]);
all_datatask.push("copy:img_"+themes[i]);
copy_assets_all_datatask.push("copy:css_dev_"+themes[i]);
copy_assets_all_datatask.push("copy:js_dev_"+themes[i]);
copy_assets_all_datatask.push("copy:fonts_"+themes[i]);
copy_assets_all_datatask.push("copy:img_"+themes[i]);
} // endloop themes
tasks_memo += '\n';
/**
*
* less with watch data setup for themes on dev/dist configs
*
*/
tasks_memo += 'Less Tasks\n\n';
for (var i = themes.length - 1; i >= 0; i--) {
tasks_memo += '\n\tLess Task on Theme '+themes[i]+'\n';
for (var j = less_packages.length - 1; j >= 0; j--) {
var pkg = less_packages[j];
var lessfile = theme_path_src+themes[i]+'/assets/less/custom/'+pkg+'.less';
// console.log(lessfile);
if (grunt.file.isFile(lessfile)) {
// tasks_memo += '\t\t'+less_packages[j]+'\n';
// var pkgName = pkg.substring(pkg.lastIndexOf("/")+1,pkg.lastIndexOf(""));
// var pkgPath = pkgName.substring(0,pkgName.lastIndexOf(pkgName));
/**
* Less setup
*/
// dist setup (prod)
var minPath = theme_path+themes[i]+'/css/'+pkg+'.min.css';
var lessPath = lessfile;
var less_files = new Object;
less_files[minPath] = lessPath;
less_tasks['dist_'+themes[i]+'_'+pkg] = {
options: less_options_dist,
files: less_files
};
tasks_memo += '\n\t\t'+'Package '+pkg+' : \n';
tasks_memo += '\t\t\t'+'grunt less:dist_'+themes[i]+'_'+pkg+'\n';
// dev setup
var minPath = theme_path_dev+themes[i]+'/css/'+pkg+'.css';
var lessPath = lessfile;
var less_files = new Object;
less_files[minPath] = lessPath;
less_tasks['dev_'+themes[i]+'_'+pkg] = {
options: less_options_dev,
files: less_files
};
tasks_memo += '\t\t\t' + 'grunt less:dev_'+themes[i]+'_'+pkg+'\n';
/* End less setup */
/**
* Watch setup
*/
// watch dist setup
var watchFiles = lessfile;
var watchTasks = ['less:dist_'+themes[i]+'_'+pkg];
watch_data['less_dist_'+themes[i]+'_'+pkg] = {
files : watchFiles,
tasks : watchTasks
};
// watch dev setup
var watchFiles = lessfile;
var watchTasks = ['less:dev_'+themes[i]+'_'+pkg];
watch_data['less_dev_'+themes[i]+'_'+pkg] = {
files : watchFiles,
tasks : watchTasks
};
/* end watch setup */
/* register default task */
compile_less_all_datatask.push("less:dist_"+themes[i]+"_"+pkg);
all_datatask.push("less:dist_"+themes[i]+"_"+pkg);
compile_less_all_datatask.push("less:dev_"+themes[i]+"_"+pkg);
all_datatask.push("less:dev_"+themes[i]+"_"+pkg);
}
} /* end less packages loop */
tasks_memo += '\n';
};
/* end loop initConfig data */
// console.log(compile_less_all_datatask);
/**
*
*
* cssmin/uglify tasks with watch
*
*
*/
tasks_memo += '\n\nCSS minify Tasks\n';
for (var i = themes.length - 1; i >= 0; i--) {
// Minify : css_to_minify array
for (var j = css_to_minify.length - 1; j >= 0; j--) {
var cssfile = theme_path_src+themes[i]+'/assets/css/'+css_to_minify[j]+'.css';
if (grunt.file.isFile(cssfile)) {
// create minify task
css_minify_data['cssmin_'+themes[i]+'_'+css_to_minify[j]] = {
expand: true,
cwd: theme_path_src+themes[i]+'/assets/css/',
src: [css_to_minify[j]+'.css'],
dest: theme_path+themes[i]+'/css/',
ext: '.min.css'
};
// watch files for minify task
var watchFile = cssfile;
var watchTask = ['cssmin:cssmin_'+themes[i]+'_'+css_to_minify[j]];
watch_data['watch_cssmin_'+themes[i]+'_'+css_to_minify[j]] = {
files : watchFile,
tasks : watchTask
};
tasks_memo += '\t\t'+'grunt cssmin:cssmin_'+themes[i]+'_'+css_to_minify[j]+'\n';
minify_all_datatask.push("cssmin:cssmin_"+themes[i]+'_'+css_to_minify[j]);
minify_datatask.push("cssmin:cssmin_"+themes[i]+'_'+css_to_minify[j]);
all_datatask.push("cssmin:cssmin_"+themes[i]+'_'+css_to_minify[j]);
}
}
}
tasks_memo += '\n\nJS Uglify Tasks\n';
for (var i = themes.length - 1; i >= 0; i--) {
// uglify : jsfiles_to_minify array
for (var j = jsfiles_to_minify.length - 1; j >= 0; j--) {
var jsfile = theme_path_src+themes[i]+'/assets/js/'+jsfiles_to_minify[j]+'.js';
if (grunt.file.isFile(jsfile)) {
// create uglify task
js_uglify_data['uglify_'+themes[i]+'_'+jsfiles_to_minify[j]] = {
files: [{
expand: true,
cwd: theme_path_src+themes[i]+'/assets/js/',
src: jsfiles_to_minify[j]+'.js',
dest: theme_path+themes[i]+'/js/',
ext: '.min.js'
}]
};
tasks_memo += '\t\t'+'grunt uglify:uglify_'+themes[i]+'_'+jsfiles_to_minify[j]+'\n';
// watch files for uglify task
var watchFile = jsfile;
var watchTask = ['uglify:uglify_'+themes[i]+'_'+jsfiles_to_minify[j]];
watch_data['watch_uglify_'+themes[i]+'_'+jsfiles_to_minify[j]] = {
files : watchFile,
tasks : watchTask
};
minify_all_datatask.push("uglify:uglify_"+themes[i]+'_'+jsfiles_to_minify[j]);
uglify_datatask.push("uglify:uglify_"+themes[i]+'_'+jsfiles_to_minify[j]);
all_datatask.push("uglify:uglify_"+themes[i]+'_'+jsfiles_to_minify[j]);
}
}
}
/**
*
* CONCAT ASSETS
*
*/
// concat JS
// debug efx
tasks_memo += '\n\nConcat JS Tasks\n';
for (var i = themes.length - 1; i >= 0; i--) {
var uglify_concat = new Object;
var uglify_files = [];
for (key in js_to_concat) {
var dirjspath = theme_path_src+themes[i]+'/assets/js/'+key;
if (grunt.file.isDir(dirjspath)) {
var data = js_to_concat[key];
tasks_memo += '\t\t'+'grunt uglify:concatjs_'+themes[i]+key+' :\n';
for (var j = 0; j < data.length - 1; j++) {
uglify_files.push(dirjspath+'/'+data[j]+'.js');
// console.log(theme_path_src+themes[i]+'/js/'+key+'/'+data[j]+'.js');
// console.log('theme[i] = ' + themes[i]);
tasks_memo += '\t\t\t+ ' + dirjspath+'/'+data[j]+'.js'+'\n';
}
tasks_memo += '\n';
// console.log('dest : '+theme_path+themes[i]+'js/'+key+'.min.js');
uglify_concat[theme_path+themes[i]+'/js/'+key+'/'+key+'.min.js'] = uglify_files;
js_uglify_data['concatjs_'+themes[i]+'_'+key] = {
options: {
mangle: true
},
files: uglify_concat
}
all_datatask.push("uglify:concatjs_"+themes[i]+'_'+key);
conc_datatask.push("uglify:concatjs_"+themes[i]+'_'+key);
conc_js_datatask.push("uglify:concatjs_"+themes[i]+'_'+key);
}
}
}
// Concat CSS
tasks_memo += '\n\nConcat CSS Tasks\n';
var minify_concat = new Object;
var minify_files = [];
for (var i = themes.length - 1; i >= 0; i--) {
for (key in css_to_concat) {
var dircsspath = theme_path_src+themes[i]+'/assets/css/'+key;
if (grunt.file.isDir(dircsspath)) {
var data = css_to_concat[key];
tasks_memo += '\t\t'+'grunt cssmin:concatcss_'+key+' :\n';
for (var j = 0; j < data.length - 1; j++) {
minify_files.push(dircsspath+'/'+data[j]+'.css');
// console.log(dircsspath+'/'+data[j]+'.css');
tasks_memo += '\t\t\t+ ' + dircsspath+'/'+data[j]+'.css'+'\n';
}
tasks_memo += '\n';
// minify_concat[key+'.min.css'] = minify_files;
minify_concat[theme_path+themes[i]+'/css/'+key+'/'+key+'.min.css'] = minify_files;
css_minify_data['concatcss_'+themes[i]+'_'+key] = {
options: {},
files: minify_concat
}
all_datatask.push("cssmin:concatcss_"+themes[i]+'_'+key);
conc_datatask.push("cssmin:concatcss_"+themes[i]+'_'+key);
conc_css_datatask.push("cssmin:concatcss_"+themes[i]+'_'+key);
}
}
}
// setup initConfig with less, cssmin, uglify tasks and watch
grunt.initConfig({
"file-creator": config_file_data,
less: less_tasks,
cssmin: css_minify_data,
uglify: js_uglify_data,
copy: copy_assets_data,
watch: watch_data
});
/*
*
*
* setup default tasks
*
*
*/
// grunt.registerTask('default', writeMemo);
// Done all
grunt.registerTask('all', all_datatask);
// compile and minify all LESS
grunt.registerTask('min_less', compile_less_all_datatask);
// Minify and uglify all assets
grunt.registerTask('min_assets', minify_all_datatask);
// Uglify All JS
grunt.registerTask('min_js', uglify_datatask);
// Minify all CSS
grunt.registerTask('min_css', minify_datatask);
// Concate all CSS/JS Stuff
grunt.registerTask('conc', conc_datatask);
// Concate all JS Stuff
grunt.registerTask('conc_js', conc_js_datatask);
// Concate all CSS Stuff
grunt.registerTask('conc_css', conc_css_datatask);
// Copy assets
grunt.registerTask('copy_assets', copy_assets_all_datatask);
grunt.file.write('app-grunt-tasks-memo.txt', tasks_memo);
}