forked from CaryLandholt/AngularFun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
619 lines (578 loc) · 16.8 KB
/
Gruntfile.coffee
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# Build configurations
module.exports = (grunt) ->
grunt.initConfig
# Deletes dist and .temp directories
# The .temp directory is used during the build process
# The dist directory contains the artifacts of the build
# These directories should be deleted before subsequent builds
# These directories are not committed to source control
clean:
working: [
'./.temp/'
'./dist/'
]
# Used for those that desire plain old JavaScript
jslove: [
'**/*.coffee'
'!**/bower_components/**'
'!**/node_modules/**'
]
# Compiles CoffeeScript (.coffee) files to JavaScript (.js)
coffee:
app:
cwd: './.temp/'
src: '**/*.coffee'
dest: './.temp/'
expand: true
ext: '.js'
options:
sourceMap: true
# Used for those that desire plain old JavaScript
jslove:
files: [
cwd: './'
src: [
'**/*.coffee'
'!**/bower_components/**'
'!**/node_modules/**'
]
dest: './'
expand: true
ext: '.js'
]
# Lints CoffeeScript files
coffeelint:
files: './src/scripts/**/*.coffee'
options:
indentation:
value: 1
max_line_length:
level: 'ignore'
no_tabs:
level: 'ignore'
# Sets up a web server
connect:
app:
options:
base: './dist/'
livereload: true
middleware: require './middleware'
open: true
port: 0
# Copies directories and files from one location to another
copy:
app:
files: [
cwd: './src/'
src: '**'
dest: './.temp/'
expand: true
,
cwd: './bower_components/angular/'
src: 'angular.*'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/angular-animate/'
src: 'angular-animate.*'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/angular-resource/'
src: 'angular-resource.*'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/angular-route/'
src: 'angular-route.*'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/bootstrap/less/'
src: '*'
dest: './.temp/styles/'
expand: true
,
cwd: './bower_components/bootstrap/fonts/'
src: '*'
dest: './.temp/fonts/'
expand: true
,
cwd: './bower_components/html5shiv/dist/'
src: 'html5shiv-printshiv.js'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/json3/lib/'
src: 'json3.min.js'
dest: './.temp/scripts/libs/'
expand: true
,
cwd: './bower_components/requirejs/'
src: 'require.js'
dest: './.temp/scripts/libs/'
expand: true
]
dev:
cwd: './.temp/'
src: '**'
dest: './dist/'
expand: true
prod:
files: [
cwd: './.temp/'
src: 'fonts/**'
dest: './dist/'
expand: true
,
cwd: './.temp/'
src: 'images/**'
dest: './dist/'
expand: true
,
cwd: './.temp/'
src: [
'scripts/ie.min.*.js'
'scripts/scripts.min.*.js'
]
dest: './dist/'
expand: true
,
cwd: './.temp/'
src: 'styles/styles.min.*.css'
dest: './dist/'
expand: true
,
'./dist/index.html': './.temp/index.min.html'
]
# Renames files based on their hashed content
# When the files contents change, the hash value changes
# Used as a cache buster, ensuring browsers load the correct static resources
#
# glyphicons-halflings.png -> glyphicons-halflings.6c8829cc6f.png
# scripts.min.js -> scripts.min.6c355e03ee.js
hash:
images: './.temp/images/**/*'
scripts:
cwd: './.temp/scripts/'
src: [
'ie.min.js'
'scripts.min.js'
]
expand: true
styles: './.temp/styles/styles.min.css'
# Compresses png files
imagemin:
images:
files: [
cwd: './.temp/'
src: 'images/**/*.png'
dest: './.temp/'
expand: true
]
options:
optimizationLevel: 7
# Compiles jade templates
jade:
views:
cwd: './.temp/'
src: '**/views/*.jade'
dest: './.temp/'
expand: true
ext: '.html'
options:
pretty: true
spa:
cwd: './.temp/'
src: 'index.jade'
dest: './.temp/'
expand: true
ext: '.html'
options:
pretty: true
# Runs unit tests using karma
karma:
unit:
options:
browsers: [
'PhantomJS'
]
captureTimeout: 5000
colors: true
files: [
'./dist/scripts/libs/angular.js'
'./dist/scripts/libs/angular-animate.js'
'./dist/scripts/libs/angular-route.js'
'./dist/scripts/libs/angular-resource.js'
'./bower_components/angular-mocks/angular-mocks.js'
'./dist/scripts/**/*.js'
'./test/scripts/**/*.{coffee,js}'
]
frameworks: [
'jasmine'
]
junitReporter:
outputFile: './test-results.xml'
keepalive: false
logLevel: 'INFO'
port: 9876
preprocessors:
'**/*.coffee': 'coffee'
reporters: [
'dots'
'junit'
'progress'
]
runnerPort: 9100
singleRun: true
# Compile LESS (.less) files to CSS (.css)
less:
app:
files:
'./.temp/styles/styles.css': './.temp/styles/styles.less'
# Minifies index.html
# Extra white space and comments will be removed
# Content within <pre /> tags will be left unchanged
# IE conditional comments will be left unchanged
# Reduces file size by over 14%
minifyHtml:
prod:
src: './.temp/index.html'
ext: '.min.html'
expand: true
# Creates main file for RequireJS
ngShim:
scripts:
cwd: './.temp/scripts/'
angular: 'libs/angular.min.js'
modules: [
'ngAnimate': 'libs/angular-animate.min.js'
'ngResource': 'libs/angular-resource.min.js'
'ngRoute': 'libs/angular-route.min.js'
]
src: [
'**/*.{coffee,js}'
'!libs/angular.{coffee,js}'
'!libs/angular-animate.{coffee,js}'
'!libs/angular-resource.{coffee,js}'
'!libs/angular-route.{coffee,js}'
'!libs/html5shiv-printshiv.{coffee,js}'
'!libs/json3.min.{coffee,js}'
'!libs/require.{coffee,js}'
]
dest: 'main.coffee'
# Creates a file to push views directly into the $templateCache
# This will produce a file with the following content
#
# angular.module('app').run(['$templateCache', function ($templateCache) {
# $templateCache.put('/views/directives/tab.html', '<div class="tab-pane" ng-class="{active: selected}" ng-transclude></div>');
# $templateCache.put('/views/directives/tabs.html', '<div class="tabbable"> <ul class="nav nav-tabs"> <li ng-repeat="tab in tabs" ng-class="{active:tab.selected}"> <a href="http://localhost:3005/scripts/views.js" ng-click="select(tab)">{{tab.caption}}</a> </li> </ul> <div class="tab-content" ng-transclude></div> </div>');
# $templateCache.put('/views/people.html', '<ul ng-hide="!people.length"> <li class="row" ng-repeat="person in people | orderBy:\'name\'"> <a ng-href="#/people/{{person.id}}" ng-bind="person.name"></a> </li> </ul>');
# $templateCache.put('/views/repos.html', '<ul ng-hide="!repos.length"> <li ng-repeat="repo in repos | orderBy:\'pushed_at\':true"> <a ng-href="{{repo.url}}" ng-bind="repo.name" target="_blank"></a> <div ng-bind="repo.description"></div> </li> </ul>');
# $templateCache.put('/views/tweets.html', '<ul ng-hide="!tweets.length"> <li class="row" ng-repeat="tweet in tweets"> <div class="span1 thumbnail"> <img ng-src="{{tweet.profile_image_url}}"/> </div> <div class="span6"> <div> <b ng-bind="tweet.from_user_name"></b> <a ng-href="https://twitter.com/{{tweet.from_user}}" ng-bind="tweet.from_user | twitterfy" target="_blank"></a> </div> <div ng-bind="tweet.text"></div> </div> </li> </ul>');
# }]);
#
# This file is then included in the output automatically
# AngularJS will use it instead of going to the file system for the views, saving requests
# Notice that the view content is actually minified. :)
ngTemplateCache:
views:
files:
'./.temp/scripts/views.js': './.temp/views/**/*.html'
options:
trim: './.temp'
# RequireJS optimizer configuration for both scripts and styles
# This configuration is only used in the 'prod' build
# The optimizer will scan the main file, walk the dependency tree, and write the output in dependent sequence to a single file
# Since RequireJS is not being used outside of the main file or for dependency resolution (this is handled by AngularJS), RequireJS is not needed for final output and is excluded
# RequireJS is still used for the 'dev' build
# The main file is used only to establish the proper loading sequence
requirejs:
scripts:
options:
baseUrl: './.temp/scripts/'
findNestedDependencies: true
logLevel: 0
mainConfigFile: './.temp/scripts/main.js'
name: 'main'
# Exclude main from the final output to avoid the dependency on RequireJS at runtime
onBuildWrite: (moduleName, path, contents) ->
modulesToExclude = ['main']
shouldExcludeModule = modulesToExclude.indexOf(moduleName) >= 0
return '' if shouldExcludeModule
contents
optimize: 'uglify2'
out: './.temp/scripts/scripts.min.js'
preserveLicenseComments: false
skipModuleInsertion: true
uglify:
# Let uglifier replace variables to further reduce file size
no_mangle: false
useStrict: true
wrap:
start: '(function(){\'use strict\';'
end: '}).call(this);'
styles:
options:
baseUrl: './.temp/styles/'
cssIn: './.temp/styles/styles.css'
logLevel: 0
optimizeCss: 'standard'
out: './.temp/styles/styles.min.css'
# Compiles underscore expressions
#
# The example below demonstrates the use of the environment configuration setting
# In 'prod' build the hashed file of the concatenated and minified scripts is referened
# In environments other than 'prod' the individual files are used and loaded with RequireJS
#
# <% if (config.environment === 'prod') { %>
# <script src="<%= config.getHashedFile('./.temp/scripts/scripts.min.js', {trim: './.temp'}) %>"></script>
# <% } else { %>
# <script data-main="/scripts/main.js" src="/scripts/libs/require.js"></script>
# <% } %>
template:
indexDev:
files:
'./.temp/index.html': './.temp/index.html'
'./.temp/index.jade': './.temp/index.jade'
index:
files: '<%= template.indexDev.files %>'
environment: 'prod'
# Concatenates and minifies JavaScript files
uglify:
scripts:
files:
'./.temp/scripts/ie.min.js': [
'./.temp/scripts/libs/json3.js'
'./.temp/scripts/libs/html5shiv-printshiv.js'
]
# Run tasks when monitored files change
watch:
basic:
files: [
'./src/fonts/**'
'./src/images/**'
'./src/scripts/**/*.js'
'./src/styles/**/*.css'
'./src/views/**/*.html'
]
tasks: [
'copy:app'
'copy:dev'
'karma'
]
options:
livereload: true
nospawn: true
coffee:
files: './src/scripts/**/*.coffee'
tasks: [
'coffeelint'
'copy:app'
'coffee:app'
'copy:dev'
'karma'
]
options:
livereload: true
nospawn: true
jade:
files: './src/views/**/*.jade'
tasks: [
'copy:app'
'jade:views'
'copy:dev'
'karma'
]
options:
livereload: true
nospawn: true
less:
files: './src/styles/**/*.less'
tasks: [
'copy:app'
'less'
'copy:dev'
]
options:
livereload: true
nospawn: true
spaHtml:
files: './src/index.html'
tasks: [
'copy:app'
'template:indexDev'
'copy:dev'
'karma'
]
options:
livereload: true
nospawn: true
spaJade:
files: './src/index.jade'
tasks: [
'copy:app'
'template:indexDev'
'jade:spa'
'copy:dev'
'karma'
]
options:
livereload: true
nospawn: true
test:
files: './test/**/*.*'
tasks: [
'karma'
]
# Used to keep the web server alive
none:
files: 'none'
options:
livereload: true
# ensure only tasks are executed for the changed file
# without this, the tasks for all files matching the original pattern are executed
grunt.event.on 'watch', (action, filepath, key) ->
path = require 'path'
file = filepath.substr(4) # trim "src/" from the beginning. I don't like what I'm doing here, need a better way of handling paths.
dirname = path.dirname file
ext = path.extname file
basename = path.basename file, ext
grunt.config ['copy', 'app'],
cwd: './src/'
src: file
dest: './.temp/'
expand: true
copyDevConfig = grunt.config ['copy', 'dev']
copyDevConfig.src = file
if key is 'coffee'
copyDevConfig.src = path.join(dirname, "#{basename}.{coffee,js,js.map}")
coffeeConfig = grunt.config ['coffee', 'app']
coffeeConfig.src = file
coffeeLintConfig = grunt.config ['coffeelint', 'files']
coffeeLintConfig = filepath
grunt.config ['coffee', 'app'], coffeeConfig
grunt.config ['coffeelint', 'files'], coffeeLintConfig
if key is 'spaJade'
copyDevConfig.src = path.join(dirname, "#{basename}.{jade,html}")
if key is 'jade'
copyDevConfig.src = path.join(dirname, "#{basename}.{jade,html}")
jadeConfig = grunt.config ['jade', 'views']
jadeConfig.src = file
grunt.config ['jade', 'views'], jadeConfig
if key is 'less'
copyDevConfig.src = [
path.join(dirname, "#{basename}.{less,css}")
path.join(dirname, 'styles.css')
]
grunt.config ['copy', 'dev'], copyDevConfig
# Register grunt tasks supplied by grunt-coffeelint.
# Referenced in package.json.
# https://github.com/vojtajina/grunt-coffeelint
grunt.loadNpmTasks 'grunt-coffeelint'
# Register grunt tasks supplied by grunt-contrib-*.
# Referenced in package.json.
# https://github.com/gruntjs/grunt-contrib
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-connect'
grunt.loadNpmTasks 'grunt-contrib-copy'
grunt.loadNpmTasks 'grunt-contrib-imagemin'
grunt.loadNpmTasks 'grunt-contrib-jade'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-contrib-requirejs'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-watch'
# Register grunt tasks supplied by grunt-hustler.
# Referenced in package.json.
# https://github.com/CaryLandholt/grunt-hustler
grunt.loadNpmTasks 'grunt-hustler'
# Register grunt tasks supplied by grunt-karma.
# Referenced in package.json.
# https://github.com/karma-runner/grunt-karma
grunt.loadNpmTasks 'grunt-karma'
# Compiles the app with non-optimized build settings
# Places the build artifacts in the dist directory
# Enter the following command at the command line to execute this build task:
# grunt build
grunt.registerTask 'build', [
'clean:working'
'coffeelint'
'copy:app'
'ngShim'
'coffee:app'
'less'
'template:indexDev'
'jade'
'copy:dev'
]
# Compiles the app with non-optimized build settings
# Places the build artifacts in the dist directory
# Opens the app in the default browser
# Watches for file changes, and compiles and reloads the web browser upon change
# Enter the following command at the command line to execute this build task:
# grunt or grunt default
grunt.registerTask 'default', [
'build'
'connect'
'watch'
]
# Identical to the default build task
# Compiles the app with non-optimized build settings
# Places the build artifacts in the dist directory
# Opens the app in the default browser
# Watches for file changes, and compiles and reloads the web browser upon change
# Enter the following command at the command line to execute this build task:
# grunt dev
grunt.registerTask 'dev', [
'default'
]
# Compiles the app with optimized build settings
# Places the build artifacts in the dist directory
# Enter the following command at the command line to execute this build task:
# grunt prod
grunt.registerTask 'prod', [
'clean:working'
'coffeelint'
'copy:app'
'ngShim'
'coffee:app'
'imagemin'
'hash:images'
'less'
'jade:views'
'ngTemplateCache'
'requirejs'
'uglify'
'hash:scripts'
'hash:styles'
'template:index'
'jade:spa'
'minifyHtml'
'copy:prod'
]
# Opens the app in the default browser
# Build artifacts must be in the dist directory via a prior grunt build, grunt, grunt dev, or grunt prod
# Enter the following command at the command line to execute this build task:
# grunt server
grunt.registerTask 'server', [
'connect'
'watch:none'
]
# Compiles the app with non-optimized build settings
# Places the build artifacts in the dist directory
# Runs unit tests via karma
# Enter the following command at the command line to execute this build task:
# grunt test
grunt.registerTask 'test', [
'build'
'karma'
]
# Compiles all CoffeeScript files in the project to JavaScript then deletes all CoffeeScript files
# Used for those that desire plain old JavaScript
# Enter the following command at the command line to execute this build task:
# grunt jslove
grunt.registerTask 'jslove', [
'coffee:jslove'
'clean:jslove'
]