forked from standrewsdigital/digital-pattern-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
522 lines (475 loc) · 17.1 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
// Gruntfile.js
//
// This file configures all of the Grunt tasks used. It contains the following
// sections:
//
// 1. Load task libraries
// 2. Config
// * Assemble
// * Clean
// * Compass
// * Concat
// * Copy
// * Git info
// * JSHint
// * Uglify
// * Watch
// 3. Task aliases - the tasks section combines the tasks defined in config into
// commands that are documented (see README.md)
'use strict';
module.exports = function(grunt) {
// == 1. Load task libraries
grunt.loadNpmTasks('grunt-assemble');
grunt.loadNpmTasks('grunt-gitinfo');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// == 2. Config
// * Assemble
// * Clean
// * Compass
// * Concat
// * Copy
// * Git info
// * JSHint
// * Uglify
// * Watch
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Assemble - Generate documentation about DPL
// See http://assemble.io/docs/ for more details
assemble: {
// General options
options: {
pkg: '<%= pkg %>',
now: '<%= grunt.template.today("isoDateTime") %>',
assets: 'docs/assets',
layoutdir: 'src/_layouts',
partials: ['src/patterns/*/*.hbs', 'src/_partials/*.hbs'],
ext: '.html',
data: [
'src/_meta/*.json',
'src/patterns/*/*.json',
'src/examples/_data/*.json'
],
helpers: [
'handlebars-helper-asset',
'handlebars-helper-rel'
],
site: {
root: "docs",
},
},
// ASSEMBLE SECTIONS
// Patterns - uses /src/_layouts/pattern.hbs
patterns: {
options: {
layout: 'pattern.hbs'
},
files: [{
expand: true,
cwd: 'src/patterns/',
src: [
'index.hbs',
'*/*.doc.hbs'
],
dest: 'docs/patterns',
ext: '.html',
rename: function(src,dest){
var prefix = 'docs/patterns/',
pattern = /\/[a-zA-Z0-9_-]+.html$/,
suffix = '/index.html';
return prefix + dest.replace(pattern, suffix);
}
}]
},
// Example pages - uses /src/_layouts/example.hbs
examples: {
options: {
layout: 'example.hbs'
},
files: [{
expand: true,
cwd: 'src/examples/',
src: ['**/*.hbs'],
dest: 'docs/examples',
ext: '.html'
}]
},
// General guidance pages - uses /src/_layouts/doc.hbs
docs: {
options: {
layout: 'doc.hbs'
},
files: [{
expand: true,
cwd: 'src/docs',
src: [
'*.md',
'*.html',
'**/*.hbs'
],
ext: '.html',
dest: 'docs'
}]
},
// Meta doc(s)
core_meta: {
options: {
git: {
branch: '<%= gitinfo.local.branch.current.name %>',
commit: '<%= gitinfo.local.branch.current.SHA %>'
},
ext: '.json',
},
files: [{
expand: true,
cwd: 'src/_meta',
src: ['build.tmpl'],
dest: 'core'
}]
}
}, // END of assemble
// clean - remove generated folders
clean: {
images: {
src: ["core/images"]
},
fonts: {
src: ["core/fonts"]
},
js: {
src: ["core/scripts"]
},
styles: {
src: ["core/styles"]
},
core: {
src: ["core"]
},
docs: {
src: ["docs"]
},
docs_assets: {
src: ["docs/assets"]
},
docs_core: {
src: ["docs/assets/core"]
}
}, // END of clean
// compass - compile compass/sass code to CSS
compass: {
dist: {
options: {
banner: '/*! <%= pkg.name %> v<%= pkg.version %> ' +
'- <%= grunt.template.today("yyyy-mm-dd") %> */\n',
specify: [
//'src/styles/datatables.scss',
'src/styles/doc.scss',
'src/styles/print.scss',
'src/styles/screen.scss',
'src/styles/header-only.scss'
],
sassDir: 'src/styles',
importPath: 'src/patterns',
cssDir: 'core/styles',
environment: 'production',
force: true,
trace: true,
relativeAssets: true
}
}
}, // END of compass
// concat - combine JavaScript files scripts into single file.
concat: {
core: {
src: [
// Update src/docs/using.md if any of these change
'src/scripts/vendor/a11y-modal.js',
'src/scripts/vendor/hammer.js',
'src/scripts/vendor/jquery.min.js',
'src/scripts/vendor/jquery.bigtarget.js',
//'src/scripts/vendor/jquery.dataTables.min.js',
'src/scripts/vendor/jquery.fitvids.js',
//'src/scripts/vendor/jquery.fittext.js',
'src/scripts/vendor/jquery.replacetext.js',
//'src/scripts/vendor/jquery.theatre.min.js',
'src/scripts/vendor/respond.js',
'src/scripts/vendor/highlight/highlight.pack.js',
'src/scripts/jquery-ui.js',
'src/scripts/vendor/lazysizes.min.js',
'src/scripts/vendor/picturefill.min.js',
'src/scripts/vendor/gumshoe.polyfills.min.js',
// Bootstrap JavaScript
// Note these scripts should align with the CSS
'src/scripts/vendor/bootstrap/affix.js',
'src/scripts/vendor/bootstrap/alert.js',
'src/scripts/vendor/bootstrap/button.js',
'src/scripts/vendor/bootstrap/collapse.js',
'src/scripts/vendor/bootstrap/dropdown.js',
'src/scripts/vendor/bootstrap/tab.js',
'src/scripts/vendor/bootstrap/transition.js',
//'src/scripts/vendor/bootstrap/scrollspy.js',
'src/scripts/vendor/bootstrap/modal.js',
'src/scripts/vendor/bootstrap/tooltip.js',
'src/scripts/vendor/bootstrap/popover.js',
'src/scripts/vendor/enquire.js',
// DPL-specific scripts
'src/scripts/base.js',
'src/scripts/unbreakableSpaces.js',
'src/patterns/*/*.js', // This includes all JS in patterns.
//'src/scripts/datatables.js',
'src/scripts/application.js'
],
dest: 'core/scripts/core.js'
},
headerOnly: {
src: [
'src/patterns/header/header.js'
],
dest: 'core/scripts/header-only.js'
},
corebase: {
src: [
'src/scripts/base.js',
'src/patterns/*/*.js'
],
dest: 'core/scripts/core-base.js'
},
nojquery: {
src: [
// Update src/docs/using.md if any of these change
'src/scripts/vendor/a11y-modal.js',
'src/scripts/vendor/hammer.js',
'src/scripts/vendor/jquery.bigtarget.js',
'src/scripts/vendor/jquery.fitvids.js',
//'src/scripts/vendor/jquery.fittext.js',
'src/scripts/vendor/jquery.replacetext.js',
//'src/scripts/vendor/jquery.theatre.min.js',
'src/scripts/vendor/respond.js',
'src/scripts/vendor/highlight/highlight.pack.js',
'src/scripts/jquery-ui.js',
'src/scripts/vendor/lazysizes.min.js',
'src/scripts/vendor/picturefill.min.js',
'src/scripts/vendor/gumshoe.polyfills.min.js',
// Bootstrap JavaScript
// Note these scripts should align with the CSS
'src/scripts/vendor/bootstrap/affix.js',
'src/scripts/vendor/bootstrap/alert.js',
'src/scripts/vendor/bootstrap/button.js',
'src/scripts/vendor/bootstrap/collapse.js',
'src/scripts/vendor/bootstrap/dropdown.js',
'src/scripts/vendor/bootstrap/tab.js',
'src/scripts/vendor/bootstrap/transition.js',
//'src/scripts/vendor/bootstrap/scrollspy.js',
'src/scripts/vendor/bootstrap/modal.js',
'src/scripts/vendor/bootstrap/tooltip.js',
'src/scripts/vendor/bootstrap/popover.js',
'src/scripts/vendor/enquire.js',
// DPL-specific scripts
'src/scripts/base.js',
'src/scripts/unbreakableSpaces.js',
'src/patterns/*/*.js', // This includes all JS in patterns.
//'src/scripts/datatables.js',
'src/scripts/application.js'
],
dest: 'core/scripts/core-nojquery.js'
},
doc: {
src: [
'src/scripts/doc.js',
// Autocomplete scripts for Funnelback search
'src/scripts/vendor/typeahead.bundle-0.11.1.min.js',
'src/scripts/vendor/handlebars-4.0.5.min.js',
'src/scripts/vendor/funnelback.autocompletion-2.6.0.js'
],
dest: 'core/scripts/doc.js'
}
}, // END of concat
// copy - copy core assets
copy: {
core_images: {
files: [{
expand: true,
cwd: 'src/images-core/',
src: ['**/*'],
dest: 'core/images'
}]
},
core_fonts: {
files: [{
expand: true,
cwd: 'src/fonts/',
src: ['**/*'],
dest: 'core/fonts'
}]
},
docs_core: {
files: [{
expand: true,
cwd: 'core',
src: ['**/*'],
dest: 'docs/assets/core'
}]
},
docs_images: {
files: [{
expand: true,
cwd: 'src/images-docs',
src: ['**/*'],
dest: 'docs/assets/docs/images'
}]
},
docs_datatables: {
files: [{
expand: true,
cwd: 'src/scripts/',
src: ['datatables.js'],
dest: 'core/scripts/'
},
{
expand: true,
cwd: 'src/scripts/vendor/',
src: ['jquery.dataTables.min.js'],
dest: 'core/scripts/'
}]
},
docs_lightbox: {
files: [{
expand: true,
cwd: 'src/scripts/vendor/',
src: ['lightbox.min.js'],
dest: 'core/scripts/'
},
{
expand: true,
cwd: 'src/scripts/',
src: ['gallery.js'],
dest: 'core/scripts/'
}]
}
}, // END of copy
// gitinfo – loads info from git into object for grunt to access.
gitinfo: {},
// jshint - check JS files for good style
jshint: {
defaults: ['src/scripts/base.js','src/patterns/*/*.js']
}, // END of jshint
// uglify - create compressed versions of JS files
uglify: {
options: {
banner: '/*! <%= pkg.name %> v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
core: {
files: {
'core/scripts/core-base.min.js':
['core/scripts/core-base.js'],
'core/scripts/core-nojquery.min.js':
['core/scripts/core-nojquery.js'],
'core/scripts/core.min.js':
['core/scripts/core.js'],
'core/scripts/doc.min.js':
['core/scripts/doc.js'],
'core/scripts/header-only.min.js':
['core/scripts/header-only.js']
}
}
}, // END of uglify
// watch - monitor files for changes and then run the approp task.
watch: {
options: {
livereload: true,
interrupt: true
},
grunt: {
files: ['Gruntfile.js'],
tasks: ['default']
},
js: {
files: ['src/**/*.js'],
tasks: [
'clean:js',
'jshint',
'concat',
'uglify',
'clean:docs_assets',
'copy:docs_core',
'copy:docs_images'
],
},
images: {
files: ['src/images/**/*'],
tasks: [
'clean:images',
'copy:images',
'clean:docs_assets',
'copy:docs_core',
'copy:docs_images'
]
},
fonts: {
files: ['src/fonts/**/*'],
tasks: [
'clean:fonts',
'copy:fonts',
'clean:docs_assets',
'copy:docs_core',
'copy:docs_images'
]
},
styles: {
files: ['src/**/*.scss'],
tasks: [
'clean:styles',
'compass',
'clean:docs_core',
'copy:docs_core'
]
},
docs: {
files: [
'src/**/*.html',
'src/**/*.hbs',
'src/**/*.json',
'src/**/*.md',
'package.json',
],
tasks: ['docs']
}
}, // END of watch
});
// == 3. Task aliases
// default – builds the core assets, compiles documentation
grunt.registerTask('default', [
'core',
'docs'
]);
// core – builds the core assets from source
grunt.registerTask('core', [
'clean:core',
'compass',
'jshint',
'concat',
'uglify',
'gitinfo',
'assemble:core_meta',
'copy:core_images',
'copy:core_fonts',
'copy:docs_datatables',
'copy:docs_lightbox'
]);
// docs – builds the documentation, makes use of build too.
grunt.registerTask('docs', [
'clean:docs',
'assemble:patterns',
'assemble:examples',
'assemble:docs',
'copy:docs_core',
'copy:docs_images'
]);
};