-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.coffee
257 lines (231 loc) · 7.28 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
module.exports = (grunt)->
###
Define Default Paths
###
globalConfig =
path: "public/assets"
srcPath: "amplus/assets"
jsVendorPath: "public/assets/js/vendor"
cssVendorPath: "public/assets/css/vendor"
layoutFile: "app/views/index.volt"
httpPath: "http://amplusmarketing.com" # url to your live site
###
Setting up CSS & JS Load Order
###
cssFilesToInject = [
globalConfig.cssVendorPath + "/bootstrap.min.css"
globalConfig.cssVendorPath + '/**/*.css'
globalConfig.path + '/css/**/*.css'
]
jsFilesToInject = [
globalConfig.jsVendorPath + '/jquery.min.js'
globalConfig.jsVendorPath + '/bootstrap.min.js'
]
###
Grunt Initial Settings
###
grunt.initConfig
data: globalConfig
pkg: grunt.file.readJSON('package.json')
# Setting up Concurrent Operations
concurrent:
prepareDevLinks: ['sails-linker:devJs', 'sails-linker:devStyles']
prepareProdLinks: ['sails-linker:prodJs', 'sails-linker:prodStyles']
preprocessors: ['newer:coffee:dev', 'newer:imagemin:dist']
"prod-preprocessors": ["compass:dist"]
minify: ['newer:uglify:dist', 'newer:cssmin:dist']
watch:
tasks: ['watch', 'compass:dev']
options:
logConcurrentOutput: true
###
Development Specific Settings
###
# CoffeeScript
coffee:
dev:
options:
bare: true
sourceMaps: true
sourceMapDir: '<%= data.path %>/js/app/sourcemaps/'
files: [
expand: true
cwd: '<%= data.path %>/js/app/coffeescripts/'
src: ['**/*.coffee']
dest: '<%= data.path %>/js/app/'
ext: '.js'
]
# Compass (includes Sass)
compass:
dev: # default environment is development
options:
sassDir: '<%= data.path %>/css/app/sass'
cssDir: '<%= data.path %>/css/app'
imagesDir: '<%= data.path %>/img/src'
fontsDir: '<%= data.srcPath %>/fonts'
generatedImagesPath: '<%= data.path %>/img/src'
watch: true
dist:
options:
relativeAssets: false
httpPath: '<%= data.httpPath %>'
httpStylesheetsPath: '<%= data.httpPath %>/css/app'
httpImagesPath: '<%= data.httpPath %>/img/dist'
httpGeneratedImagesPath: '<%= data.httpPath %>/img/dist'
httpJavascriptsPath: '<%= data.httpPath %>/js/app'
httpFontsPath: '<%= data.httpPath %>/fonts'
environment: 'production'
# CoffeeScript JSLint Plugin
coffeelint:
app: ['<%= data.path %>/js/app/**/*.coffee']
# Clean (Delete js/css files after the .coffee/.sass is Deleted)
clean:
js:
src: ['<%= data.path %>/js/app/filename']
css:
src: ['<%= data.path %>/css/app/filename']
img:
src: ['<%= data.path %>/img/src/filename']
# Image Optimization
imagemin:
dist:
files: [
expand: true
cwd: '<%= data.path %>/img/src'
src: ['**/*.{png,jpg,gif}']
dest: '<%= data.path %>/img/dist'
]
###
Production Specific Settings
###
# Concatenate the Compiled CSS and JS Files
concat:
js:
src: jsFilesToInject
dest: '<%= data.httpPath %>/js/production.js'
css:
src: cssFilesToInject
dest: '<%= data.httpPath %>/css/production.css'
# Compress the JS Files
uglify:
dist:
files:
'<%= data.httpPath %>/js/production.min.js': ['<%= data.httpPath %>/js/production.js']
# Compress the CSS Files
cssmin:
dist:
files:
'<%= data.httpPath %>/css/production.min.css': ['<%= data.httpPath %>/css/production.css']
###
Linking up the Files
###
# Injecting Links for CSS and JS into Layout Page
'sails-linker':
devJs:
options:
startTag: '<!--SCRIPTS-->'
endTag: '<!--SCRIPTS END-->'
fileTmpl: '<script src="%s"></script>'
appRoot: "public/"
files:
'<%= data.layoutFile %>': jsFilesToInject
prodJs:
options:
startTag: '<!--SCRIPTS-->'
endTag: '<!--SCRIPTS END-->'
fileTmpl: '<script src="%s?ver=<%= pkg.version %>"></script>'
appRoot: "public/"
files:
'<%= data.layoutFile %>': ['<%= data.path %>/js/production.min.js']
devStyles:
options:
startTag: '<!--STYLES-->'
endTag: '<!--STYLES END-->'
fileTmpl: '<link rel="stylesheet" href="%s" />'
appRoot: "public/"
files:
'<%= data.layoutFile %>': cssFilesToInject
# Adding Watch Options
watch:
configFiles:
files: ['Gruntfile.coffee']
options:
reload: true,
livereload: true
# Auto Linking on Delete/Add
css:
files: ['<%= data.path %>/css/**/*.css']
tasks: ['sails-linker:devStyles']
options:
event: ['added', 'deleted']
js:
files: ['<%= data.path %>/js/**/*.js']
tasks: ['sails-linker:devJs']
options:
event: ['added', 'deleted']
coffeeScripts:
files: ['<%= data.path %>/js/app/coffeescripts/**/*.coffee']
tasks: ['newer:coffee:dev', 'coffeelint']
options:
event: ['added', 'changed']
imageAdd:
files: ['<%= data.path %>/img/src/**/*.{png,jpg,gif}']
tasks: ['newer:imagemin:dist']
options:
event: ['added']
# Deletion of CoffeeScripts, Sass Scripts, Images
deleteCoffeeScripts:
files: ['<%= data.path %>/js/app/coffeescripts/**/*.coffee']
tasks: ['clean:js']
options:
event: ['deleted']
spawn: false
deleteSass:
files: ['<%= data.path %>/css/app/sass/**/*.sass']
tasks: ['clean:css']
options:
event: ['deleted']
spawn: false
imageDelete:
files: ['<%= data.path %>/img/src/**/*']
tasks: ['clean:img']
options:
event: ['deleted']
spawn: false
###
Running Tasks
###
require("load-grunt-tasks")(grunt)
# Custom Task Response
grunt.event.on "watch", (action, filepath, target)->
if (target is 'deleteCoffeeScripts' and action is 'deleted')
# Finds the JS Equivalent Path
javascriptPath = (filepath.replace("coffeescripts\\", "")).replace(".coffee", ".js")
grunt.config.set("clean.js.src", javascriptPath)
if (target is 'deleteSass' and action is 'deleted')
# Finds the CSS Equivalent Path
cssPath = (filepath.replace("sass\\", "")).replace(".sass", ".css")
grunt.config("clean.css.src", cssPath)
if (target is "imageDelete" and action is 'deleted')
imgPath = filepath.replace("src\\", "dist\\")
grunt.config("clean.img.src", imgPath)
# Aliasing Tasks - Sectioning Tasks for Better Management
grunt.registerTask "initializeApp", [
'concurrent:preprocessors'
'concurrent:prepareDevLinks'
'coffeelint'
]
grunt.registerTask "initializeProdApp", [
'concurrent: prod-preprocessors'
'concurrent: minify'
'concurrent: prepareProdLinks'
]
# Default Task
grunt.registerTask "default", [
'initializeApp'
"concurrent:watch"
]
# Production Environment
grunt.registerTask "prod", [
'initializeProdApp'
]