-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gruntfile.coffee
383 lines (353 loc) · 9.15 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
path = require 'path'
cdnJs = [
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.min.js'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-animate.min.js'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-aria.min.js'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-messages.min.js'
'https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.28/angular-ui-router.min.js'
'https://ajax.googleapis.com/ajax/libs/angular_material/1.1.26/angular-material.min.js'
'https://cdnjs.cloudflare.com/ajax/libs/angular-material-icons/0.7.1/angular-material-icons.min.js'
'https://cdnjs.cloudflare.com/ajax/libs/ngStorage/0.3.11/ngStorage.min.js'
'https://d3js.org/d3.v3.min.js'
]
cdnCss = [
'https://ajax.googleapis.com/ajax/libs/angular_material/1.1.26/angular-material.min.css'
]
mapFiles = [
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-messages.min.js.map'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-aria.min.js.map'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.min.js.map'
'https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular-animate.min.js.map'
]
# Build configurations
module.exports = (grunt) ->
require('load-grunt-tasks')(grunt)
require('time-grunt')(grunt)
pkg = require './package.json'
grunt.initConfig
settings:
distDirectory: 'dist'
srcDirectory: 'src'
tempDirectory: '.temp'
# 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: [
'<%= settings.tempDirectory %>'
'<%= settings.distDirectory %>'
]
js: [
'<%= settings.tempDirectory %>/scripts/**/*.js'
'<%= settings.tempDirectory %>/scripts/**/*.map'
'<%= settings.tempDirectory %>/scripts/**/*.coffee'
'!<%= settings.tempDirectory %>/scripts/**/*.min.js'
'!<%= settings.tempDirectory %>/scripts/scripts.js.map'
]
# Compiles CoffeeScript (.coffee) files to JavaScript (.js)
coffee:
app:
files: [
cwd: '<%= settings.tempDirectory %>'
src: '**/*.coffee'
dest: '<%= settings.tempDirectory %>'
expand: true
ext: '.js'
]
options:
sourceMap: false
# Lints CoffeeScript files
coffeelint:
app:
files: [
cwd: ''
src: [
'src/**/*.coffee'
'!src/scripts/libs/**'
]
]
options:
indentation:
value: 1
max_line_length:
level: 'ignore'
no_tabs:
level: 'ignore'
# Sets up a web server
connect:
app:
options:
base: '<%= settings.distDirectory %>'
hostname: '0.0.0.0' # make server accessible via the network
livereload: true
middleware: (connect, options, middlewares) ->
# enable Angular's HTML5 mode
modRewrite = require 'connect-modrewrite'
middlewares.unshift(modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png$ /index.html [L]']));
return middlewares;
open: true
# Copies directories and files from one location to another
copy:
app:
files: [
cwd: '<%= settings.srcDirectory %>'
src: '**'
dest: '<%= settings.tempDirectory %>'
expand: true
,
cwd: '.components/'
src: '**'
dest: '<%= settings.tempDirectory %>'
expand: true
]
dev:
cwd: '<%= settings.tempDirectory %>'
src: '**'
dest: '<%= settings.distDirectory %>'
expand: true
prod:
files: [
cwd: '<%= settings.tempDirectory %>'
src: [
'**/*.{gif,jpeg,jpg,png,webp}'
'**/*.{css,js,html,map,config,appcache}'
]
dest: '<%= settings.distDirectory %>'
expand: true
]
# Runs unit tests using karma
karma:
unit:
options:
browsers: [
'Firefox'
]
captureTimeout: 5000
colors: true
files: cdnJs.concat([
'dist/**/main.js'
'dist/**/*.js'
'test/**/*.{coffee,js}'
])
frameworks: [
'jasmine'
]
junitReporter:
outputFile: 'test-results.xml'
keepalive: false
logLevel: 'INFO'
port: 9876
preprocessors:
'**/*.coffee': 'coffee'
reporters: [
'spec'
]
runnerPort: 9100
singleRun: true
# Compile LESS (.less) files to CSS (.css)
less:
app:
files:
'.temp/styles/styles.css': '.temp/styles/**.less'
# Convert CoffeeScript classes to AngularJS modules
ngClassify:
app:
files: [
cwd: '<%= settings.tempDirectory %>'
src: '**/*.coffee'
dest: '<%= settings.tempDirectory %>'
expand: true
]
cacheBust:
taskName:
options:
assets: [
'.temp/scripts/**/*.js'
'.temp/styles/styles.css'
]
deleteOriginals: true
src: []
includeSource:
options:
basePath: '.temp'
myTarget:
files:
'.temp/index.html': '.temp/index.html'
template:
dev:
files: '.temp/index.html': '.temp/index.html'
cdnJs: cdnJs
cdnCss: cdnCss
prod:
files: '.temp/index.html': '.temp/index.html'
environment: 'prod'
cdnJs: cdnJs
cdnCss: cdnCss
ngtemplates:
app:
cwd: '.temp',
src: 'views/**/*.html',
dest: '.temp/scripts/templates.js'
options:
htmlmin:
collapseBooleanAttributes: true
collapseWhitespace: true
removeAttributeQuotes: true
removeComments: true
removeEmptyAttributes: true
removeRedundantAttributes: true
removeScriptTypeAttributes: true
removeStyleLinkTypeAttributes: true
uglify:
options:
mangle: false
my_target:
files:
'.temp/scripts/scripts.min.js': '.temp/scripts/scripts.js'
concat:
options:
separator: ';'
sourceMap: true
dist:
src: ['.temp/scripts/*.js', '.temp/scripts/**/*.js']
dest: '.temp/scripts/scripts.js'
# Run tasks when monitored files change
watch:
basic:
files: [
'src/fonts/**'
'src/images/**'
'src/scripts/**/*.js'
'src/styles/**/*.css'
'src/**/*.html'
]
tasks: [
'copy:app'
'less'
'includeSource'
'template:dev'
'copy:dev'
]
options:
livereload: true
nospawn: true
coffee:
files: 'src/scripts/**/*.coffee'
tasks: [
'clean:working'
'coffeelint'
'copy:app'
'ngClassify:app'
'coffee:app'
'less'
'includeSource'
'template:dev'
'copy:dev'
#'karma'
]
options:
livereload: true
nospawn: true
less:
files: 'src/styles/**/*.less'
tasks: [
'copy:app'
'less'
'template:dev'
'includeSource'
'copy:dev'
]
options:
livereload: true
nospawn: true
test:
files: 'test/**/*.*'
tasks: [
'karma'
]
# Used to keep the web server alive
none:
files: 'none'
options:
livereload: true
# 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'
'ngClassify'
'coffee:app'
'less'
'includeSource'
'template:dev'
'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'
'ngClassify'
'coffee:app'
'less'
'ngtemplates'
'concat'
'uglify'
'clean:js'
'cacheBust'
'template:prod'
'includeSource'
'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'
]
# Looks like the prevailing winds are pointing to use 'serve' instead of 'server'
# Why not both? :)
# grunt serve
grunt.registerTask 'serve', [
'server'
]
# 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'
]