forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
564 lines (529 loc) · 13.2 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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
'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'
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 meta
pkg: require('./package.json'),
bower: require('./bower.json'),
meta: {
banner: '/**\n' +
' * <%= pkg.name %>\n' +
' * @version v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @author <%= pkg.author.name %> (<%= pkg.author.email %>)\n' +
' * @license MIT License, http://www.opensource.org/licenses/MIT\n' +
' */\n'
},
// Project settings
yo: {
// Configurable paths
src: require('./bower.json').appPath || 'src',
dist: 'dist',
docs: 'docs',
pages: 'pages'
},
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['{.tmp,<%= yo.src %>}/scripts/{,*/}*.js'],
tasks: ['newer:jshint:all']
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma']
},
styles: {
options: {
spawn: false
},
files: ['{docs,<%= yo.src %>}/styles/{,*/}*.less'],
tasks: ['less:dev', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'{docs,.dev,<%= yo.src %>}/{,*/}{,docs/}*.html',
'{docs,.tmp,<%= yo.src %>}/{,*/}*.css',
'{docs,.dev,.tmp,<%= yo.src %>}/{,*/}{,docs/}*.js',
'{docs,<%= yo.src %>}/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'.dev',
'docs',
'<%= yo.src %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yo.src %>'
]
}
},
dist: {
options: {
base: '<%= yo.dist %>'
}
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'<%= yo.src %>/scripts/{,*/}*.js'
],
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yo.dist %>/*',
'!<%= yo.dist %>/.git*'
]
}]
},
docs: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yo.pages %>/*',
'!<%= yo.pages %>/.git*'
]
}]
},
server: '.tmp'
},
// Compile less stylesheets
less: {
options: {
},
dev: {
options: {
dumpLineNumbers: 'comments',
},
files: [{
expand: true,
cwd: '<%= yo.docs %>/styles/',
src: '*.less',
dest: '.tmp/styles/',
ext: '.css'
}]
},
docs: {
options: {
cleancss: false
},
files: [{
expand: true,
cwd: '<%= yo.docs %>/styles/',
src: '*.less',
dest: '.tmp/styles/',
ext: '.css'
}]
}
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 2 versions']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// 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: '<%= yo.docs %>/index.html',
options: {
dest: '<%= yo.pages %>'
}
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
html: '<%= yo.pages %>/index.html',
css: ['<%= yo.pages %>/styles/{,*/}*.css'],
options: {
assetsDirs: ['<%= yo.pages %>', '<%= yo.pages %>/images']
}
},
// Embed static ngincludes
nginclude: {
docs: {
files: [{
src: '<%= yo.docs %>/index.html',
dest: '<%= yo.pages %>/index.html'
}],
options: {
assetsDirs: ['<%= yo.src %>', '<%= yo.docs %>']
}
}
},
// Minify html files
htmlmin: {
options: {
collapseWhitespace: true,
removeComments: false
},
docs: {
files: [{
expand: true,
cwd: '<%= yo.pages %>',
src: ['*.html'],//, 'views/{,*/}*.html'],
dest: '<%= yo.pages %>'
}]
}
},
// Renames files for browser caching purposes
rev: {
dist: {
files: {
src: [
'<%= yo.pages %>/scripts/{,*/}*.js',
'<%= yo.pages %>/styles/{,*/}*.css',
'<%= yo.pages %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yo.pages %>/styles/fonts/*'
]
}
}
},
// Copies remaining files to places other tasks can use
copy: {
static: {
files: [{
expand: true,
cwd: '<%= yo.pages %>',
dest: '<%= yo.pages %>/static',
src: [
'images/{,*/}*.png',
'scripts/{,*/}*.js',
'styles/{,*/}*.css'
]
}]
},
docs: {
files: [{
expand: true,
cwd: '<%= yo.docs %>/',
dest: '<%= yo.pages %>',
src: [
'images/*',
'1.0/**/*'
]
}, {
src: 'bower_components/angular-motion/dist/angular-motion.css',
dest: '<%= yo.pages %>/styles/angular-motion.css'
}, {
src: '.tmp/styles/bootstrap-additions.css',
dest: '<%= yo.pages %>/styles/bootstrap-additions.css'
}, {
expand: true,
cwd: '<%= yo.dist %>',
dest: '<%= yo.pages %>/dist',
src: '{,*/}*.{js,map}'
}]
}
},
// Run some tasks in parallel to speed up the build process
concurrent: {
docs: [
'less:docs',
'uglify:generated',
'cssmin:generated'
],
server: [
'less:dev'
],
test: [
'less:dev'
],
dist: [
'less:dist',
'imagemin',
'svgmin',
'htmlmin'
]
},
concat: {
// generated: {
// options: {
// banner: '(function(window, document, $, undefined) {\n\'use strict\';\n',
// footer: '\n})(window, document, window.jQuery);\n'
// }
// },
dist: {
options: {
// Replace all 'use strict' statements in the code with a single one at the top
banner: '(function(window, document, undefined) {\n\'use strict\';\n',
footer: '\n})(window, document);\n',
process: function(src, filepath) {
return '// Source: ' + filepath + '\n' +
src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
}
},
files: [{
src: ['<%= yo.src %>/module.js', '<%= yo.src %>/{,*/}*.js'],
dest: '<%= yo.dist %>/<%= pkg.name %>.js'
}, {
src: ['<%= yo.dist %>/modules/{,*/}*.tpl.js'],
dest: '<%= yo.dist %>/<%= pkg.name %>.tpl.js'
}]
},
banner: {
options: {
banner: '<%= meta.banner %>',
},
files: [{
expand: true,
cwd: '<%= yo.dist %>',
src: '{,*/}*.js',
dest: '<%= yo.dist %>'
}]
},
docs: {
options: {
banner: '<%= meta.banner %>',
},
files: [{
expand: true,
cwd: '<%= yo.pages %>',
src: ['scripts/{demo,docs,angular-strap}*', 'styles/{main}*'],
dest: '<%= yo.pages %>'
}]
}
},
// Allow the use of non-minsafe AngularJS files. Automatically makes it
// minsafe compatible so Uglify does not destroy the ng references
ngmin: {
dist: {
files: [{
src: '<%= yo.dist %>/<%= pkg.name %>.js',
dest: '<%= yo.dist %>/<%= pkg.name %>.js'
}]
},
modules: {
files: [{
expand: true,
flatten: true,
cwd: '<%= yo.src %>',
src: '{,*/}*.js',
dest: '<%= yo.dist %>/modules'
}]
},
docs: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
ngtemplates: {
test: {
options: {
module: function(src) { return 'mgcrea.ngStrap.' + src.match(/src\/(.+)\/.*/)[1]; },
url: function(url) { return url.replace('src/', ''); },
htmlmin: { collapseWhitespace: true },
usemin: 'scripts/angular-strap.tpl.min.js' // docs
},
files: [{
expand: true,
flatten: true,
cwd: '<%= yo.src %>',
src: '{,*/}/*.tpl.html',
dest: '.tmp/templates',
ext: '.tpl.js'
}]
},
dist: {
options: {
module: function(src) { return 'mgcrea.ngStrap.' + src.match(/src\/(.+)\/.*/)[1]; },
url: function(url) { return url.replace('src/', ''); },
htmlmin: { collapseWhitespace: true },
},
files: [{
expand: true,
flatten: true,
cwd: '<%= yo.src %>',
src: '{,*/}/*.tpl.html',
dest: '<%= yo.dist %>/modules',
ext: '.tpl.js'
}]
},
docs: {
options: {
module: 'mgcrea.ngStrapDocs',
usemin: 'scripts/docs.tpl.min.js'
},
files: [{
cwd: '<%= yo.src %>',
src: '{,*/}docs/*.html',
dest: '.tmp/templates/scripts/src-docs.js'
},
{
cwd: '<%= yo.docs %>',
// src: 'views/{,*/}*.html',
src: 'views/{aside,sidebar}.html',
dest: '.tmp/templates/scripts/docs-views.js'
}
]
}
},
uglify: {
dist: {
options: {
report: 'gzip',
sourceMap: '<%= yo.dist %>/<%= pkg.name %>.min.map',
sourceMappingURL: '<%= pkg.name %>.min.map'
},
files: [{
expand: true,
cwd: '<%= yo.dist %>',
src: '{,*/}*.js',
dest: '<%= yo.dist %>',
ext: '.min.js'
}, {
expand: true,
cwd: '<%= yo.dist %>',
src: '{,*/}*.tpl.js',
dest: '<%= yo.dist %>',
ext: '.tpl.min.js'
}]
}
},
// Test settings
karma: {
options: {
configFile: 'test/karma.conf.js',
browsers: ['PhantomJS']
},
unit: {
options: {
reporters: ['dots', 'coverage']
},
singleRun: true,
},
server: {
options: {
reporters: ['progress']
},
autoWatch: true
}
},
coveralls: {
options: {
/*jshint camelcase: false */
coverage_dir: 'test/coverage/PhantomJS 1.9.7 (Linux)/',
force: true
}
}
});
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'ngtemplates:test',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
// 'concurrent:test',
// 'autoprefixer',
'ngtemplates:test',
'connect:test',
'karma:unit'
]);
grunt.registerTask('build', [
'clean:dist',
'ngtemplates:dist',
'concat:dist',
'ngmin:dist',
'ngmin:modules',
'uglify:dist',
'concat:banner'
]);
grunt.registerTask('docs', [
'clean:docs',
'useminPrepare',
// 'concurrent:docs',
'less:docs',
'autoprefixer',
'nginclude:docs',
'ngtemplates:test',
'ngtemplates:docs',
'concat:generated',
'ngmin:docs',
'copy:docs',
'cssmin:generated',
'uglify:generated',
'concat:docs',
'copy:static',
'rev',
'usemin',
// 'htmlmin:docs' // breaks code preview
]);
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
};