-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGruntfile.coffee
More file actions
383 lines (346 loc) · 11.7 KB
/
Gruntfile.coffee
File metadata and controls
383 lines (346 loc) · 11.7 KB
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
# Build configurations.
module.exports = (grunt) ->
grunt.registerMultiTask 'fileconstruct', 'Build a file', ->
src = @data.src
dist = @data.dist
return grunt.log.warn('src is required') if !src
return grunt.log.warn('dist is required') if !dist
cwd = @data.cwd ? './'
files = grunt.file.expand {cwd}, src
return grunt.verbose.warn('No src files found') if !files.length is 0
path = require 'path'
return grunt.log.warn('path lib is required') if !path
console.log 'files:', files
console.log dist
grunt.file.delete(dist) if grunt.file.exists(dist)
scripts = "<% if (config.environment === 'dev') { %>\n"
files.forEach (file) ->
scripts += "<script src='#{file}'></script>\n"
scripts += "<% } %>\n"
grunt.file.write dist, scripts
grunt.template.process
grunt.registerMultiTask "wrap", "Wraps source files with specified header and footer", ->
data = @data
path = require("path")
header = grunt.file.read(grunt.template.process(data.header))
footer = grunt.file.read(grunt.template.process(data.footer))
contents = grunt.file.read(grunt.template.process(data.content))
prodScripts = grunt.file.read(grunt.template.process(data.prodScripts))
devScripts = grunt.file.read(grunt.template.process(data.devScripts)) if data.devScripts
tmp = header + contents + prodScripts
tmp = tmp + devScripts if data.devScripts
tmp = tmp + footer
grunt.file.write "./.temp/index.html", tmp
grunt.file.delete(grunt.template.process(data.devScripts)) if data.devScripts
grunt.log.writeln "File \"" + "./.temp/index.html" + "\" created."
grunt.initConfig
# Deletes deployment and temp directories.
# The temp directory is used during the build process.
# The deployment directory contains the artifacts of the build.
# These directories should be deleted before subsequent builds.
# These directories are not committed to source control.
path:
toApp: "./serviceTracker/src/main/assets/application"
fileconstruct:
scripts:
cwd: "<%= path.toApp %>/.temp"
dist: "<%= path.toApp %>/src/devScripts.html"
src: [
"<%= path.toApp %>/scripts/libs/vendors/jquery/jquery.js"
"<%= path.toApp %>/scripts/libs/vendors/angular/angular.js"
"<%= path.toApp %>/scripts/libs/vendors/angular-resource/angular-resource.js"
"<%= path.toApp %>/scripts/libs/vendors/angular-route/angular-route.js"
"<%= path.toApp %>/scripts/libs/vendors/angular-bootstrap/ui-bootstrap-tpls.js"
"<%= path.toApp %>/scripts/libs/vendors/modules/**/*Module.js"
"<%= path.toApp %>/scripts/libs/vendors/filters/**/*.js"
"<%= path.toApp %>/scripts/libs/vendors/libs/**/*.js"
"<%= path.toApp %>/scripts/libs/vendors/resources/**/*.js"
"<%= path.toApp %>/scripts/libs/vendors/directives/**/*.js"
"<%= path.toApp %>/scripts/libs/vendors/services/**/*.js"
"<%= path.toApp %>/scripts/config/development.js"
"<%= path.toApp %>/scripts/app.js"
"<%= path.toApp %>/scripts/routes.js"
"<%= path.toApp %>/scripts/responseInterceptors/*.js"
"<%= path.toApp %>/scripts/controllers/**/*.js"
"<%= path.toApp %>/scripts/directives/**/*.js"
"<%= path.toApp %>/scripts/services/**/*.js"
"<%= path.toApp %>/scripts/filters/**/*.js"
"<%= path.toApp %>/scripts/resources/**/*.js"
]
wrap:
dev:
header: '<%= path.toApp %>/src/header.html'
content: '<%= path.toApp %>/src/content.html'
prodScripts : '<%= path.toApp %>/src/prodScripts.html'
devScripts: '<%= path.toApp %>/src/devScripts.html'
footer: '<%= path.toApp %>/src/footer.html'
dest: '<%= path.toApp %>'
prod:
header: '<%= path.toApp %>/src/header.html'
content: '<%= path.toApp %>/src/content.html'
prodScripts : '<%= path.toApp %>/src/prodScripts.html'
footer: '<%= path.toApp %>/src/footer.html'
dest: '<%= path.toApp %>/'
clean:
bower:
src: [
'<%= path.toApp %>/libs/vendors/'
'./bower_components/'
'<%= path.toApp %>/styles/vendors/'
]
dev:
src: [
'<%= path.toApp %>/public/'
'<%= path.toApp %>/.test/'
'<%= path.toApp %>/.temp/'
]
prod:
src: [
'<%= path.toApp %>/.test/'
'<%= path.toApp %>/.temp/'
]
# Compile CoffeeScript (.coffee) files to JavaScript (.js).
coffee:
dev:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: '<%= path.toApp %>/scripts/**/*.coffee'
dest: '<%= path.toApp %>/.temp/'
expand: true
ext: '.js'
]
options:
bare: true
prod:
files: [
'<%= path.toApp %>/.temp/scripts/env.js': [ '<%= path.toApp %>/.temp/scripts/config/production.coffee' ]
'<%= path.toApp %>/.temp/scripts/scripts.js': [
'<%= path.toApp %>/.temp/scripts/libs/vendors/modules/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/libs/vendors/resources/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/libs/vendors/filters/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/libs/vendors/directives/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/libs/vendors/services/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/app.coffee'
'<%= path.toApp %>/.temp/scripts/routes.coffee'
'<%= path.toApp %>/.temp/scripts/responseInterceptors/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/resources/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/services/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/directives/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/controllers/**/*.coffee'
'<%= path.toApp %>/.temp/scripts/filters/**/*.coffee'
]
'<%= path.toApp %>/.temp/scripts/views.js': [ '<%= path.toApp %>/.temp/scripts/views.coffee' ]
]
options:
bare: true
sourceMap: false
# Compile LESS (.less) files to CSS (.css).
less:
styles:
files:
'<%= path.toApp %>/styles/vendors/styles.css': ['<%= path.toApp %>/styles/vendors/bootstrap/bootstrap.less']
#options:
# sourcemap: true
connect:
app:
options:
base: './serviceTracker/src/main/assets/application'
port: 5000
livereload: false
keepalive: true
# Copies directories and files from one location to another.
copy:
# Copies the contents of the temp directory, except views, to the dist directory.
# In 'dev' individual files are used.
dev:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: '**'
dest: './public/'
expand: true
]
# Copies img directory to temp.
img:
files: [
cwd: '<%= path.toApp %>/src/'
src: ['img/**/*.png','img/**/*.jpg','img/**/*.gif']
dest: '<%= path.toApp %>/.temp/'
expand: true
]
# Copies favicon to temp.
favicon:
files: [
cwd: '<%= path.toApp %>/src/'
src: 'favicon.ico'
dest: './.temp/'
expand: true
]
# Copies csslib directory to temp.
csslib:
files: [
cwd: '<%= path.toApp %>/src/'
src: ['styles/lib/**/*','styles/vendors/**/*']
dest: '<%= path.toApp %>/.temp/'
expand: true
]
# Copies styles directory with less to temp.
styleSource:
files: [
cwd: '<%= path.toApp %>/src/'
src: 'styles/**/*'
dest: '<%= path.toApp %>/.temp/'
expand: true
]
# Copies fonts directory to temp.
fonts:
files: [
cwd: '<%= path.toApp %>/src/'
src: 'fonts/**/*'
dest: '<%= path.toApp %>/.temp/'
expand: true
]
# Copies js files to the temp directory
scriptSource:
files: [
cwd: '<%= path.toApp %>/src/scripts'
src: '**/*.js'
dest: '<%= path.toApp %>/.temp/scripts'
expand: true
,
cwd: '<%= path.toApp %>/src/scripts'
src: '**/*.coffee'
dest: '<%= path.toApp %>/.temp/scripts'
expand: true
,
cwd: '<%= path.toApp %>/src/libs/'
src: '**/*.js'
dest: '<%= path.toApp %>/.temp/scripts/libs'
expand: true
,
cwd: '<%= path.toApp %>/src/libs/'
src: '**/*.coffee'
dest: '<%= path.toApp %>/.temp/scripts/libs'
expand: true
]
# Task is run when the watched index.template file is modified.
index:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: 'index.html'
dest: '<%= path.toApp %>/public/'
expand: true
]
# Task is run when a watched script is modified.
scripts:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: 'scripts/**'
dest: './public/'
expand: true
]
# Task is run when a watched style is modified.
styles:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: 'styles/**'
dest: '<%= path.toApp %>/public/'
expand: true
]
# Task is run when a watched view is modified.
views:
files: [
cwd: '<%= path.toApp %>/.temp/'
src: 'views/**'
dest: '<%= path.toApp %>/public/'
expand: true
]
# Compresses png files
imagemin:
img:
files: [
cwd: '<%= path.toApp %>/src/'
src: ['img/**/*.png','img/**/*.jpg','img/**/*.gif']
dest: '<%= path.toApp %>/.temp/'
expand: true
]
options:
optimizationLevel: 7
# Install Bower components
bower:
install:
options:
targetDir: '<%= path.toApp %>'
layout: 'byType'
install: true
verbose: true
cleanTargetDir: false
cleanBowerDir: false
# 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:
'<%= path.toApp %>/.temp/scripts/views.js': '<%= path.toApp %>/.temp/views/**/*.html'
options:
trim: '<%= path.toApp %>/.temp/'
template:
views:
files:
'<%= path.toApp %>/.temp/views/': '<%= path.toApp %>/src/views/**/*.html'
dev:
files:
'<%= path.toApp %>/.temp/index.html': '<%= path.toApp %>/.temp/index.html'
environment: 'dev'
prod:
files: '<%= template.dev.files %>'
environment: 'prod'
# 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-uglify'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-contrib-less'
grunt.loadNpmTasks 'grunt-contrib-concat'
# Register grunt tasks supplied by grunt-hustler.
# Referenced in package.json.
# https://github.com/CaryLandholt/grunt-hustler
grunt.loadNpmTasks 'grunt-hustler'
# Grunt-Bower-Task.
grunt.loadNpmTasks 'grunt-bower-task'
# Starts a web server
# Enter the following command at the command line to execute this task:
# grunt server
grunt.registerTask 'server', [
'default'
'connect'
]
# Compiles the app with non-optimized build settings and places the build artifacts in the dist directory.
# Enter the following command at the command line to execute this build task:
# grunt
grunt.registerTask 'default', [
'clean:dev'
'bower:install'
#'copy:scriptSource'
#'coffee:dev'
#'fileconstruct'
#'wrap:dev'
#'copy:styleSource'
#'template:views'
#'copy:img'
#'copy:favicon'
#'copy:csslib'
'less:styles'
#'copy:fonts'
#'template:dev'
#'copy:dev'
]
# Compiles the app with non-optimized build settings, places the build artifacts in the dist directory, and watches for file changes.
# Enter the following command at the command line to execute this build task:
# grunt dev
grunt.registerTask 'dev', [
'default'
]