forked from cfpb/porchlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
executable file
·412 lines (394 loc) · 10.9 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
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('bower.json'),
/**
* Set some src and dist location variables.
*/
loc: {
src: 'src',
dist: 'dist',
lib : 'src/static/js/lib',
views : 'views',
porchlightLess : 'src/static/css/porchlight.less'
},
/**
* Grunt-html2js: https://github.com/karlgoldstein/grunt-html2js
*
* Plugin for converting AngularJS templates to JavaScript for caching
*/
html2js: {
options: {
//rename path to work with build
//TODO : explore better way of handling locations
rename : function(moduleName){
return /views\/.*/.exec(moduleName) || moduleName
}
},
main: {
src: ['<%= loc.src %>/**/*.tpl.html'],
dest: '<%= loc.lib %>/templates.js'
}
},
/**
* Grunt-ng-annotate :https://github.com/mzgol/grunt-ng-annotate
*
* Add, remove and rebuild AngularJS dependency injection annotations
*/
ngAnnotate: {
build: {
files: {
'<%= loc.src %>/static/js/annotatedApp.js': [
'<%= loc.src %>/static/js/modules/app/app.js',
'<%= loc.src %>/static/js/**/*.js'
]
},
}
},
clean: {
build: {
src: ['<%= loc.src %>/static/js/annotatedApp.js']
}
},
/**
* Grunt Shell: https://github.com/sindresorhus/grunt-shell
*
* A good way to interact with other CLI tools
*/
shell: {
pythonServer: {
options: {
stdout: true
},
command: 'python manage.py runserver'
}
},
/**
* Grunt Open:https://github.com/jsoverson/grunt-open
*
* Open urls and files from a grunt task
*/
open : {
dev : {
path: 'http://localhost:8000/index.html',
app: 'Google Chrome'
}
},
/**
* Bower: https://github.com/yatskevich/grunt-bower-task
*
* Set up Bower packages and migrate static assets.
*/
bower: {
cf: {
options: {
targetDir: '<%= loc.src %>/vendor/',
install: false,
verbose: true,
cleanTargetDir: false,
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: [
'<%= loc.src %>/vendor/cf-*/*.less',
'!<%= loc.src %>/vendor/cf-core/*.less',
'<%= loc.src %>/vendor/cf-core/brand-pallete.less',
'<%= loc.src %>/vendor/cf-core/cf-core.less'
],
dest: '<%= loc.src %>/static/css/capital-framework.less',
},
'porchlight-less': {
src: [
'<%=loc.src %>/static/js/**/*.less'
],
dest: '<%=loc.porchlightLess%>',
},
js: {
src: [
'<%= loc.src %>/vendor/jquery/jquery.js',
'<%= loc.src %>/vendor/jquery.easing/jquery.easing.js',
'<%= loc.src %>/vendor/angular/angular.js',
'<%= loc.src %>/vendor/angular-*/angular-*.js',
'<%= loc.src %>/vendor/angular-indicator/ngActivityIndicator.js',
'<%= loc.src %>/vendor/highstock-release/highstock.src.js',
'<%= loc.src %>/vendor/highcharts-ng/src/highcharts-ng.js',
'<%= loc.src %>/vendor/cf-*/*.js',
'!<%= loc.src %>/vendor/cf-*/Gruntfile.js',
'<%= loc.src %>/static/js/annotatedApp.js'
],
dest: '<%= loc.dist %>/static/js/main.js'
}
},
/**
* Less: https://github.com/gruntjs/grunt-contrib-less
*
* Compile Less files to CSS.
*/
less: {
main: {
options: {
// The src/vendor 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('src/vendor/*').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,
sourceMapIncludeSources: 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: [
// Fonts
'images/*'
],
dest: '<%= loc.dist %>/static'
},
{
expand: true,
cwd: '<%= loc.src %>',
src: [
// Vendor files
'vendor/html5shiv/html5shiv-printshiv.min.js',
'vendor/box-sizing-polyfill/boxsizing.htc'
],
dest: '<%= loc.dist %>/static'
}
]
}
},
/**
* 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/modules/app/app.js',
'<%= loc.src %>/static/js/**/*.js'
]
},
/**
* 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: {
default: {
files: ['Gruntfile.js',
'<%= loc.src %>/**/*.html',
'<%= loc.src %>/static/js/**/*.less',
'<%= loc.src %>/static/css/**/*.less',
'<%= loc.src %>/static/js/**/*.js'
],
tasks: ['default']
}
}
};
/**
* Initialize a configuration object for the current project.
*/
grunt.initConfig(config);
/**
* Create custom task aliases and combinations.
*/
grunt.registerTask('compile-porchlight', ['concat:porchlight-less'])
grunt.registerTask('compile-cf', ['bower:cf', 'concat:cf-less', 'compile-porchlight']);
grunt.registerTask('css', ['compile-porchlight', 'less', 'autoprefixer', 'legacssy', 'cssmin', 'usebanner:css']);
grunt.registerTask('js', ['html2js', 'ngAnnotate','concat:js', 'uglify', 'usebanner:js']);
grunt.registerTask('test', ['jshint']);
grunt.registerTask('build', ['clean', 'css', 'js','copy']);
grunt.registerTask('default', ['build']);
};