-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
507 lines (471 loc) · 12.3 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
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'
// Configurable application
var appConfig = {
app: require('./bower.json').appPath || 'src',
dist: 'dist/client',
proxy: false, // Whether or not the proxy should be turned on
proxyConfig: [{
context: '/api',
host: 'api.github.com',
port: 443,
https: true,
changeOrigin: true,
rewrite: {
'^/api': ''
}
}]
};
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
appSettings: appConfig,
/**
* Watches files for changes and runs tasks based on the changed files
*/
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: [
'<%= appSettings.app %>/**/**/**/*.js',
'!<%= appSettings.app %>/**/**/**/*.spec.js'
],
tasks: ['newer:jshint:all', 'injector:scripts'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
sass: {
files: [
'<%= appSettings.app %>/styles/**/*.scss',
'<%= appSettings.app %>/app/{views,components}/**/*.scss'
],
tasks: ['injector:sass', 'sass', 'autoprefixer']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= appSettings.app %>/*.html',
'<%= appSettings.app %>/**/**/*.html',
'.tmp/styles/{,*/}*.css',
'.tmp/**/*.css',
'<%= appSettings.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
/**
* The actual grunt server settings
*/
connect: {
options: {
port: 9000,
hostname: '*',
livereload: 35729
},
proxies: appConfig.proxy ? appConfig.proxyConfig : [],
livereload: {
options: {
middleware: function (connect) {
var middleware = [
connect.static('.tmp'),
connect().use('/bower_components', connect.static('./bower_components')),
connect.static(appConfig.app)
];
if(appConfig.proxy) {
middleware.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
}
return middleware;
}
}
},
test: {
options: {
port: 9001,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect.static(appConfig.app)
];
}
}
}
},
/**
* @description
* Make sure code styles are up to par and there are no obvious mistakes
*/
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'server/**/**/*.js',
'<%= appSettings.app %>/{,*/}*.js',
'<%= appSettings.app %>/app/{services,views,components}/**/*.js',
'<%= appSettings.app %>/app/{services,views,components}/**/*.js',
'!<%= appSettings.app %>/app/{services,views,components}/**/*.spec.js'
]
},
test: {
options: {
jshintrc: '.jshintrc'
},
src: ['<%= appSettings.app %>/test/spec/{,*/}*.js']
}
},
/**
* @description
* Creates JSDoc-style documentation based on comments. Folder doc/template has customization options.
*
* @see {@link http://usejsdoc.org}
* @see {@link https://github.com/allenhwkim/angular-jsdoc}
*/
jsdoc : {
client : {
src: [
'<%= appSettings.app %>/{,*/}*.js',
'<%= appSettings.app %>/app/components**/{,*/}*.js',
'<%= appSettings.app %>/app/services/{,*/}*.js',
'<%= appSettings.app %>/app/views/**/{,*/}*.js'
],
options: {
destination: 'doc/client',
configure: 'node_modules/angular-jsdoc/conf.json',
template: 'doc/template'
}
}
},
/**
* @description
* Empties folders to start fresh
*/
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'doc/client',
'<%= appSettings.dist %>'
]
}]
},
server: '.tmp'
},
/**
* @description
* Add vendor prefixed styles
*/
autoprefixer: {
options: {
map: true,
browsers: ['last 8 versions']
},
dist: {
files: {
'.tmp/styles/app.css': '.tmp/styles/app.css'
}
}
},
/**
* @description
* Automatically inject Bower components into the app
*/
wiredep: {
app: {
src: ['<%= appSettings.app %>/index.html'],
ignorePath: /\.\.\//,
exclude: [ /jquery/, 'bower_components/bootstrap/dist/js/bootstrap.js']
},
sass: {
src: ['<%= appSettings.app %>/styles/*.scss', '<%= appSettings.app %>/app/views/**/*.scss'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
injector: {
//Inject application script files into index.html (doesn't include bower)
scripts: {
options: {
transform: function(filePath) {
filePath = filePath.replace('/src/', '');
return '<script src="' + filePath + '"></script>';
},
starttag: '<!-- injector:js -->',
endtag: '<!-- endinjector -->'
},
files: {
'<%= appSettings.app %>/index.html': [
[
'{.tmp,<%= appSettings.app %>}/app/templates.js',
'{.tmp,<%= appSettings.app %>}/{app,components,services}/**/*.js',
'!{.tmp,<%= appSettings.app %>}/app/app.js',
'!{.tmp,<%= appSettings.app %>}/{app,components,services}/**/*.spec.js',
'!{.tmp,<%= appSettings.app %>}/{app,components,services}/**/*.mock.js'
]
]
}
},
// Inject component scss into app.scss
sass: {
options: {
transform: function(filePath) {
filePath = filePath.replace('/src', '..');
return '@import \'' + filePath + '\';';
},
starttag: '// injector',
endtag: '// endinjector'
},
files: {
'<%= appSettings.app %>/styles/app.scss': [
'<%= appSettings.app %>/{app/views,app/components}/**/*.{scss,sass}'
]
}
}
},
/**
* @description
* Compiles Sass to CSS and generates necessary files if requested
* @property {String} [outputStyle] - nested or compressed default value is nested
*/
sass: {
options: {
imagePath: '<%= appSettings.app %>/images',
outputStyle: 'expanded',
sourceMap: true
},
dist: {
files: {
'.tmp/styles/app.css' : '<%= appSettings.app %>/styles/app.scss'
}
}
},
/**
* @description
* Reads HTML for usemin blocks to enable smart builds that automatically
* concat, minify and revision files. Creates configurations in memory so
* additional tasks can operate on them.
*/
useminPrepare: {
html: '<%= appSettings.app %>/index.html',
options: {
dest: '<%= appSettings.dist %>',
flow: {
html: {
steps: {
js: ['concat', 'uglifyjs'],
css: ['cssmin']
},
post: {}
}
}
}
},
/**
* @description
* Performs rewrites based on filerev and the useminPrepare configuration
*/
usemin: {
html: ['<%= appSettings.dist %>/{,*/}*.html'],
css: ['<%= appSettings.dist %>/styles/{,*/}*.css'],
options: {
assetsDirs: ['<%= appSettings.dist %>','<%= appSettings.dist %>/images']
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= appSettings.dist %>',
src: ['*.html', '{,*/}*.html', 'views/{,*/}*.html', 'components/{,*/}*.html'],
dest: '<%= appSettings.dist %>'
}]
}
},
/**
* @description
* ng-annotate tries to make the code safe for minification automatically by using the Angular long form for dependency injection.
*/
ngAnnotate: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: ['*.js', '!oldieshim.js'],
dest: '.tmp/concat/scripts'
}]
}
},
/**
* @description
* Replace Google CDN references
*/
cdnify: {
dist: {
html: ['<%= appSettings.dist %>/*.html']
}
},
ngtemplates: {
options: {
// This should be the name of your apps angular module
module: require('./bower.json').name || 'myApp',
usemin: 'scripts/scripts.js',
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
},
main: {
cwd: 'src',
src: ['{app,components}/**/*.html'],
dest: '.tmp/templates.js'
}
},
/**
* @description
* Copies remaining files to places other tasks can use
*/
copy: {
dist: {
files: [
{
expand: true,
dot: true,
cwd: '<%= appSettings.app %>',
dest: '<%= appSettings.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'*.html',
'images/{,*/}*.{png,jpg,svg,webp}',
'fonts/{,*/}*.*',
'.tmp/concat/scripts/templates.js'
]
},
{
expand: true,
cwd: '.tmp/images',
dest: '<%= appSettings.dist %>/images',
src: ['generated/*']
},
{
expand: true,
cwd: 'bower_components/bootstrap/dist',
src: 'fonts/*',
dest: '<%= appSettings.dist %>'
},
// Copy the server folder (if it exists)
{
expand: true,
src: ['./server/**/**/*.js'],
dest: './dist/'
}
]
},
styles: {
expand: true,
cwd: '<%= appSettings.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
/**
* @description
* Run some tasks in parallel to speed up the build process
*/
concurrent: {
server: [
'sass'
],
test: [
'sass'
],
dist: [
'sass'
]
},
/**
* @description
* Unit Test settings
*/
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: true
}
}
});
grunt.registerTask('serve', 'Compile then start a connect web server', function () {
var tasks = [
'clean:server',
'wiredep',
'injector:sass',
'injector:scripts',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
];
if(appConfig.proxy) {
tasks.unshift('configureProxies:server');
}
grunt.task.run(tasks);
});
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'karma'
]);
grunt.registerTask('build', [
'clean:dist',
'wiredep',
'useminPrepare',
'ngtemplates',
'concurrent:dist',
'concat',
'ngAnnotate',
'autoprefixer',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'usemin',
'htmlmin',
'jsdoc'
]);
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
};