forked from leemunroe/grunt-email-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
345 lines (271 loc) · 10 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// secrets.json is ignored in git because it contains sensitive data
// See the README for configuration settings
secrets: grunt.file.readJSON('secrets.json'),
// Re-usable filesystem paths (these shouldn't be modified)
paths: {
src: 'src',
src_img: 'src/img',
dist: 'dist',
dist_img: 'dist/img',
preview: 'preview'
},
// Takes your SCSS files and compiles them to CSS
sass: {
dist: {
options: {
style: 'expanded'
},
files: {
'<%= paths.src %>/css/main.css': '<%= paths.src %>/css/scss/main.scss'
}
},
// This task compiles Sass for the browser-baed preview UI.
// You should not need to edit it.
preview: {
options: {
style: 'compressed'
},
files: {
'<%= paths.preview %>/css/preview.css': '<%= paths.preview %>/scss/preview.scss'
}
}
},
// Assembles your email content with HTML layout
assemble: {
options: {
layoutdir: '<%= paths.src %>/layouts',
partials: ['<%= paths.src %>/partials/**/*.hbs'],
helpers: ['<%= paths.src %>/helpers/**/*.js'],
data: ['<%= paths.src %>/data/*.{json,yml}'],
flatten: true
},
pages: {
src: ['<%= paths.src %>/emails/*.hbs'],
dest: '<%= paths.dist %>/'
}
},
// Replace compiled template images sources from ../src/html to ../dist/html
replace: {
src_images: {
options: {
usePrefix: false,
patterns: [
{
match: /(<img[^>]+[\"'])(\.\.\/src\/img\/)/gi, // Matches <img * src="../src/img or <img * src='../src/img'
replacement: '$1../<%= paths.dist_img %>/'
},
{
match: /(url\(*[^)])(\.\.\/src\/img\/)/gi, // Matches url('../src/img') or url(../src/img) and even url("../src/img")
replacement: '$1../<%= paths.dist_img %>/'
}
]
},
files: [{
expand: true,
flatten: true,
src: ['<%= paths.dist %>/*.html'],
dest: '<%= paths.dist %>'
}]
}
},
// Inlines your CSS
juice: {
your_target: {
options: {
preserveMediaQueries: true,
applyAttributesTableElements: true,
applyWidthAttributes: true,
preserveImportant: true,
webResources: {
images: false
}
},
files: [{
expand: true,
src: ['<%= paths.dist %>/*.html'],
dest: ''
}]
}
},
// Optimize images
imagemin: {
dynamic: {
options: {
optimizationLevel: 3,
svgoPlugins: [{ removeViewBox: false }]
},
files: [{
expand: true,
cwd: '<%= paths.src_img %>',
src: ['**/*.{png,jpg,gif}'],
dest: '<%= paths.dist_img %>'
}]
}
},
// Watches for changes to CSS or email templates then runs grunt tasks
watch: {
emails: {
files: ['<%= paths.src %>/css/scss/*','<%= paths.src %>/emails/*','<%= paths.src %>/layouts/*','<%= paths.src %>/partials/*','<%= paths.src %>/data/*','<%= paths.src %>/helpers/*'],
tasks: ['default']
},
preview_dist: {
files: ['./dist/*'],
tasks: [],
options: {
livereload: true
}
},
preview: {
files: ['<%= paths.preview %>/scss/*'],
tasks: ['sass:preview','autoprefixer:preview'],
options: {
livereload: true
}
}
},
// Use Mailgun option if you want to email the design to your inbox or to something like Litmus
// grunt send --template=transaction.html
mailgun: {
mailer: {
options: {
key: '<%= secrets.mailgun.api_key %>', // See README for secrets.json or replace this with your own key
sender: '<%= secrets.mailgun.sender %>', // See README for secrets.json or replace this with your preferred sender
recipient: '<%= secrets.mailgun.recipient %>', // See README for secrets.json or replace this with your preferred recipient
subject: 'This is a test email'
},
src: ['<%= paths.dist %>/'+grunt.option('template')]
}
},
// Use Rackspace Cloud Files if you're using images in your email
// grunt cdnify
cloudfiles: {
prod: {
'user': '<%= secrets.cloudfiles.user %>', // See README for secrets.json or replace this with your user
'key': '<%= secrets.cloudfiles.key %>', // See README for secrets.json or replace this with your own key
'region': '<%= secrets.cloudfiles.region %>', // See README for secrets.json or replace this with your region
'upload': [{
'container': '<%= secrets.cloudfiles.container %>', // See README for secrets.json or replace this with your container name
'src': '<%= paths.dist_img %>/*',
'dest': '/',
'stripcomponents': 0
}]
}
},
// CDN will replace local paths with your CDN path
cdn: {
cloudfiles: {
options: {
cdn: '<%= secrets.cloudfiles.uri %>', // See README for secrets.json or replace this with your cdn uri
flatten: true,
supportedTypes: 'html'
},
cwd: './<%= paths.dist %>',
dest: './<%= paths.dist %>',
src: ['*.html']
},
aws_s3: {
options: {
cdn: '<%= secrets.s3.bucketuri %>/<%= secrets.s3.bucketname %>/<%= secrets.s3.bucketdir %>', // See README for secrets.json or replace this with your Amazon S3 bucket uri
flatten: true,
supportedTypes: 'html'
},
cwd: './<%= paths.dist %>',
dest: './<%= paths.dist %>',
src: ['*.html']
}
},
// Use Amazon S3 for images
// grunt s3upload
aws_s3: {
options: {
accessKeyId: '<%= secrets.s3.key %>', // See README for secrets.json
secretAccessKey: '<%= secrets.s3.secret %>', // See README for secrets.json
region: '<%= secrets.s3.region %>', // Enter region or leave blank for US Standard region
uploadConcurrency: 5, // 5 simultaneous uploads
downloadConcurrency: 5 // 5 simultaneous downloads
},
prod: {
options: {
bucket: '<%= secrets.s3.bucketname %>', // Define your S3 bucket name in secrets.json
differential: true, // Only uploads the files that have changed
params: {
CacheControl: '2000'
}
},
files: [
{expand: true, cwd: '<%= paths.dist_img %>', src: ['**'], dest: '<%= secrets.s3.bucketdir %>/<%= paths.dist_img %>'}
]
}
},
// Send your email template to Litmus for testing
// grunt litmus --template=transaction.html
litmus: {
test: {
src: ['<%= paths.dist %>/'+grunt.option('template')],
options: {
username: '<%= secrets.litmus.username %>', // See README for secrets.json or replace this with your username
password: '<%= secrets.litmus.password %>', // See README for secrets.json or replace this with your password
url: 'https://<%= secrets.litmus.company %>.litmus.com', // See README for secrets.json or replace this with your company url
clients: ['android4', 'aolonline', 'androidgmailapp', 'aolonline', 'ffaolonline',
'chromeaolonline', 'appmail6', 'iphone6', 'ipadmini', 'ipad', 'chromegmailnew',
'iphone6plus', 'notes85', 'ol2002', 'ol2003', 'ol2007', 'ol2010', 'ol2011',
'ol2013', 'outlookcom', 'chromeoutlookcom', 'chromeyahoo', 'windowsphone8'] // https://#{company}.litmus.com/emails/clients.xml
}
}
},
/**************************************************************************************************************
START: Browser-based preview tasks.
You should not need to edit anything between this and the end block.
***************************************************************************************************************/
// Autoprefixer for css
autoprefixer: {
preview: {
options: {
browsers: ['last 6 versions', 'ie 9']
},
src: 'preview/css/preview.css'
}
},
// Express server for browser previews
express: {
server: {
options: {
port: 4000,
hostname: '127.0.0.1',
bases: ['<%= paths.dist %>', '<%= paths.preview %>', '<%= paths.src %>'],
server: './server.js',
livereload: true
}
}
},
// Open browser preview
open: {
preview: {
path: 'http://localhost:4000'
}
}
/**************************************************************************************************************
END: Browser-based preview tasks.
You should not need to edit anything between this and the start block.
***************************************************************************************************************/
});
// Load assemble
grunt.loadNpmTasks('assemble');
// Load all Grunt tasks
// https://github.com/sindresorhus/load-grunt-tasks
require('load-grunt-tasks')(grunt);
// Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['sass:dist','assemble','juice','imagemin','replace:src_images']);
// Use grunt send if you want to actually send the email to your inbox
grunt.registerTask('send', ['mailgun']);
// Upload images to our CDN on Rackspace Cloud Files
grunt.registerTask('cdnify', ['default','cloudfiles','cdn:cloudfiles']);
// Upload image files to Amazon S3
grunt.registerTask('s3upload', ['aws_s3:prod', 'cdn:aws_s3']);
// Launch the express server and start watching
// NOTE: The server will not stay running if the grunt watch task is not active
grunt.registerTask('serve', ['default', 'sass:preview', 'autoprefixer:preview', 'express', 'open', 'watch']);
};