forked from cfpb/github-wiki-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
352 lines (324 loc) · 9.57 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
module.exports = function(grunt) {
'use strict';
var path = require('path');
grunt.initConfig({
/**
* Pull in the package.json file so we can read its metadata.
*/
pkg: grunt.file.readJSON('package.json'),
/**
* Bower: https://github.com/yatskevich/grunt-bower-task
*
* Install Bower packages and migrate static assets.
*/
bower: {
install: {
options: {
targetDir: './src/vendor/',
install: true,
verbose: true,
cleanBowerDir: true,
cleanTargetDir: true,
layout: function(type, component) {
if (type === 'img') {
return path.join('../static/img');
} else if (type === 'fonts') {
return path.join('../static/fonts');
} else {
return path.join(component);
}
}
}
}
},
/**
* Concat: https://github.com/gruntjs/grunt-contrib-concat
*
* Concatenate cf-* LESS files prior to compiling them.
*/
concat: {
'cf-less': {
src: [
'src/vendor/cf-*/*.less'
],
dest: 'src/vendor/cf-concat/cf.less',
},
bodyScripts: {
src: [
'src/vendor/jquery/jquery.js',
'src/vendor/cf-*/*.js',
'src/static/js/app.js'
],
dest: 'src/static/js/main.js'
}
},
/**
* LESS: https://github.com/gruntjs/grunt-contrib-less
*
* Compile LESS files to CSS.
*/
less: {
main: {
options: {
paths: grunt.file.expand('src/vendor/**/'),
},
files: {
'src/static/css/main.css': ['src/static/css/main.less']
}
}
},
/**
* String Replace: https://github.com/erickrdch/grunt-string-replace
*
* Rewrite CSS asset paths.
*/
'string-replace': {
vendor: {
files: {
'src/static/css/': ['src/static/css/main.css']
},
options: {
replacements: [{
pattern: /url\((.*?)\)/ig,
replacement: function (match, p1, offset, string) {
var path, pathParts, pathLength, filename, newPath;
path = p1.replace(/["']/g,''); // Removes quotation marks if there are any
pathParts = path.split('/'); // Splits the path so we can find the filename
pathLength = pathParts.length;
filename = pathParts[pathLength-1]; // The filename is the last item in pathParts
grunt.verbose.writeln('');
grunt.verbose.writeln('--------------');
grunt.verbose.writeln('Original path:');
grunt.verbose.writeln(match);
grunt.verbose.writeln('--------------');
// Rewrite the path based on the file type
// Note that .svg can be a font or a graphic, not sure what to do about this.
if (filename.indexOf('.eot') !== -1 ||
filename.indexOf('.woff') !== -1 ||
filename.indexOf('.ttf') !== -1 ||
filename.indexOf('.svg') !== -1)
{
newPath = 'url("../fonts/'+filename+'")';
grunt.verbose.writeln('New path:');
grunt.verbose.writeln(newPath);
grunt.verbose.writeln('--------------');
return newPath;
} else if (filename.indexOf('.png') !== -1 ||
filename.indexOf('.gif') !== -1 ||
filename.indexOf('.jpg') !== -1)
{
newPath = 'url("../img/'+filename+'")';
grunt.verbose.writeln('New path:');
grunt.verbose.writeln(newPath);
grunt.verbose.writeln('--------------');
return newPath;
} else {
grunt.verbose.writeln('No new path.');
grunt.verbose.writeln('--------------');
return match;
}
grunt.verbose.writeln('--------------');
return match;
}
}]
}
}
},
/**
* 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
},
multiple_files: {
// Prefix all CSS files found in `src/static/css` and overwrite.
expand: true,
src: 'src/static/css/*.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: {
banner: '' // Banner now prepended by the grunt-banner task.
},
bodyScripts: {
src: ['src/static/js/main.js'],
dest: 'src/static/js/main.min.js'
}
},
/**
* CSS Min: https://github.com/gruntjs/grunt-contrib-cssmin
*
* Minify CSS and optionally rewrite asset paths.
*/
cssmin: {
combine: {
options: {
//root: '/src/'
},
files: {
'src/static/css/main.min.css': ['src/static/css/main.css'],
'src/static/css/fonts.min.css': ['src/static/css/fonts.css'],
}
}
},
/**
* Clean: https://github.com/gruntjs/grunt-contrib-clean
*
* Clear files and folders.
*/
clean: {
bowerDir: ['bower_components'],
dist: ['dist/**/*', '!dist/.git/']
},
/**
* Copy: https://github.com/gruntjs/grunt-contrib-copy
*
* Copy files and folders.
*/
copy: {
dist: {
files:
[
{
expand: true,
cwd: 'src/',
src: [
// Bring over everything in src/
'**',
// Except...
// Don't bring over everything in static/
'!static/**',
// Only include minified assets in css/ and js/
'static/css/*.min.css',
'static/js/html5shiv-printshiv.js',
'static/js/*.min.js',
'static/fonts/**',
'static/img/**',
// Exclude all vendor files because a lot will get concatenated
'!vendor/**',
// Only include vendor files that we use independently
'vendor/html5shiv/html5shiv-printshiv.js'
],
dest: 'dist/'
}
]
}
},
/**
* grunt-gh-pages: https://github.com/tschaub/grunt-gh-pages
*
* Use Grunt to push to your gh-pages branch hosted on GitHub or any other branch anywhere else
*/
'gh-pages': {
options: {
base: 'dist'
},
src: ['**']
},
/**
* 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: ['src/static/js/main.js']
},
/**
* Watch: https://github.com/gruntjs/grunt-contrib-connect
*
* Start a static web server.
*/
connect: {
server: {
options: {
base: 'dist'
},
},
},
/**
* 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: {
src: {
options: {
livereload: true
},
files: ['Gruntfile.js', 'src/index.html', 'src/static/css/*.less', 'src/static/js/app.js', '!dist/**'],
tasks: ['default','dist']
}
}
});
/**
* The above tasks are loaded here.
*/
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-string-replace');
/**
* Create custom task aliases and combinations
*/
grunt.registerTask('vendor', ['clean:bowerDir', 'bower:install', 'concat:cf-less']);
grunt.registerTask('default', ['less', 'string-replace:vendor', 'autoprefixer', 'concat:bodyScripts']);
grunt.registerTask('compile', ['less', 'string-replace:vendor', 'autoprefixer', 'concat:bodyScripts']);
grunt.registerTask('dist', ['cssmin', 'uglify', 'clean:dist', 'copy:dist']);
// Start web server
grunt.registerTask('serve', [
'dist',
'connect',
'watch'
]);
};