forked from cfpb/design-manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·346 lines (323 loc) · 8.67 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
module.exports = function(grunt) {
'use strict';
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var path = require('path');
var config = {
/**
* Pull in the package.json file so we can read its metadata.
*/
pkg: grunt.file.readJSON('package.json'),
/**
* Set some src and dist location variables.
*/
loc: {
src: 'src',
modules: 'node_modules',
dist: '.'
},
/**
* Browserify: https://github.com/jmreidy/grunt-browserify/
*
* Grunt task for node-browserify.
*/
browserify: {
main: {
src: ['<%= loc.src %>/static/js/app.js'],
dest: '<%= loc.dist %>/static/js/main.js'
}
},
/**
* Concat: https://github.com/gruntjs/grunt-contrib-concat
*/
concat: {
topdocIcons: {
src: [
'src/topdoc-templates/includes/filter-components-without-markup.jade',
'src/topdoc-templates/icons/src.jade'
],
dest: 'src/topdoc-templates/icons/index.jade'
}
},
/**
* Less: https://github.com/gruntjs/grunt-contrib-less
*
* Compile Less files to CSS.
*/
less: {
main: {
options: {
// The module paths are needed to find the CF components' files.
// Feel free to add additional paths to the array passed to `concat`.
paths: grunt.file.expand('node_modules/cf-*/src/').concat([])
},
files: {
'<%= loc.dist %>/static/css/main.css': ['<%= loc.src %>/static/css/main.less']
}
}
},
/**
* Autoprefixer: https://github.com/nDmitry/grunt-autoprefixer
*
* Parse CSS and add vendor-prefixed CSS properties using the Can I Use database.
*/
autoprefixer: {
options: {
// Options we might want to enable in the future.
diff: false,
map: false
},
main: {
// Prefix `static/css/main.css` and overwrite.
expand: true,
src: ['<%= loc.dist %>/static/css/main.css']
},
},
/**
* Uglify: https://github.com/gruntjs/grunt-contrib-uglify
*
* Minify JS files.
* Make sure to add any other JS libraries/files you'll be using.
* You can exclude files with the ! pattern.
*/
uglify: {
options: {
preserveComments: 'some',
sourceMap: true
},
// headScripts: {
// src: 'vendor/html5shiv/html5shiv-printshiv.js',
// dest: 'static/js/html5shiv-printshiv.js'
// },
js: {
src: ['<%= loc.dist %>/static/js/main.js'],
dest: '<%= loc.dist %>/static/js/main.min.js'
}
},
/**
* Banner: https://github.com/mattstyles/grunt-banner
*
* Here's a banner with some template variables.
* We'll be inserting it at the top of minified assets.
*/
banner:
'/*!\n' +
' * <%= pkg.name %> - v<%= pkg.version %>\n' +
' * <%= pkg.homepage %>\n' +
' * Licensed <%= pkg.license %> by <%= pkg.author.name %> <<%= pkg.author.email %>>\n' +
' */',
usebanner: {
css: {
options: {
position: 'top',
banner: '<%= banner %>',
linebreak: true
},
files: {
src: ['<%= loc.dist %>/static/css/*.min.css']
}
},
js: {
options: {
position: 'top',
banner: '<%= banner %>',
linebreak: true
},
files: {
src: ['<%= loc.dist %>/static/js/*.min.js']
}
}
},
/**
* CSS Min: https://github.com/gruntjs/grunt-contrib-cssmin
*
* Compress CSS files.
*/
cssmin: {
main: {
options: {
processImport: false
},
files: {
'<%= loc.dist %>/static/css/main.min.css': ['<%= loc.dist %>/static/css/main.css'],
}
},
'ie-alternate': {
options: {
processImport: false
},
files: {
'<%= loc.dist %>/static/css/main.ie.min.css': ['<%= loc.dist %>/static/css/main.ie.css'],
}
}
},
/**
* Legacssy: https://github.com/robinpokorny/grunt-legacssy
*
* Fix your CSS for legacy browsers.
*/
legacssy: {
'ie-alternate': {
options: {
// Flatten all media queries with a min-width over 960 or lower.
// All media queries over 960 will be excluded fromt he stylesheet.
// EM calculation: 960 / 16 = 60
legacyWidth: 60
},
files: {
'<%= loc.dist %>/static/css/main.ie.css': '<%= loc.dist %>/static/css/main.css'
}
}
},
/**
* Copy: https://github.com/gruntjs/grunt-contrib-copy
*
* Copy files and folders.
*/
copy: {
main: {
files: [
{
expand: true,
cwd: '<%= loc.src %>',
src: [
// HTML files
'*.html',
],
dest: '<%= loc.dist %>'
},
{
expand: true,
cwd: '<%= loc.src %>/static',
src: [
// Fonts
'fonts/*'
],
dest: '<%= loc.dist %>/static'
},
{
expand: true,
cwd: '<%= loc.src %>/static',
src: [
// Images
'img/**'
],
dest: '<%= loc.dist %>/static'
},
{
expand: true,
flatten: true,
cwd: '<%= loc.modules %>',
src: [
'html5shiv/dist/html5shiv-printshiv.min.js',
],
dest: '<%= loc.dist %>/static/vendor/html5shiv'
},
{
expand: true,
flatten: true,
cwd: '<%= loc.modules %>',
src: [
'box-sizing-polyfill/boxsizing.htc'
],
dest: '<%= loc.dist %>/static/vendor/box-sizing-polyfill'
}
]
}
},
/**
* JSHint: https://github.com/gruntjs/grunt-contrib-jshint
*
* Validate files with JSHint.
* Below are options that conform to idiomatic.js standards.
* Feel free to add/remove your favorites: http://www.jshint.com/docs/#options
*/
jshint: {
options: {
camelcase: false,
curly: true,
forin: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
quotmark: true,
sub: true,
boss: true,
strict: true,
evil: true,
eqnull: true,
browser: true,
plusplus: false,
globals: {
jQuery: true,
$: true,
module: true,
require: true,
define: true,
console: true,
EventEmitter: true
}
},
all: ['<%= loc.src %>/static/js/app.js']
},
/**
* Topdoc: https://github.com/topcoat/topdoc
*
* A command line tool for generating usage docs based on css comments
*/
topdoc: {
icons: {
options: {
source: 'static/css/',
destination: '_includes/identity/icons/',
template: 'src/topdoc-templates/icons/index.jade',
templateData: {
family: 'cf-icons'
}
}
}
},
/**
* Watch: https://github.com/gruntjs/grunt-contrib-watch
*
* Run predefined tasks whenever watched file patterns are added, changed or deleted.
* Add files to monitor below.
*/
watch: {
css: {
files: ['<%= loc.src %>/static/css/**/*.less'],
tasks: ['css']
},
js: {
files: ['Gruntfile.js', '<%= loc.src %>/static/js/**/*.js'],
tasks: ['js']
},
content: {
files: ['**/*.html', '/downloads/*.md', '/guides/*.md', '/identity/*.md', '/ui-toolkit/*.md'],
tasks: ['copy']
}
}
};
/**
* Initialize a configuration object for the current project.
*/
grunt.initConfig(config);
grunt.registerTask(
'cleanUpAfterTopdoc',
'Topdoc runs on all non-minified CSS files, including .ie.css files. We need to delete those.',
function() {
grunt.file.delete(grunt.file.expand('_includes/**/**/main.ie.html'));
}
);
/**
* Create custom task aliases and combinations.
*/
grunt.registerTask('compile-cf', ['concat:topdocIcons']);
grunt.registerTask('css', ['less', 'autoprefixer', 'legacssy', 'cssmin', 'usebanner:css', 'copy']);
grunt.registerTask('js', ['browserify', 'uglify', 'usebanner:js', 'copy']);
grunt.registerTask('test', ['jshint']);
grunt.registerTask('build', ['test', 'css', 'js', 'copy']);
grunt.registerTask('default', ['build']);
grunt.registerTask('build-partials-from-cf-docs', ['topdoc', 'cleanUpAfterTopdoc']);
};