-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
218 lines (185 loc) · 6.35 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
/**
* TODO: Nettoyer !
* TODO: Structuer les taches.
* TODO: Essayer Juice pour remplacer Premailer. https://github.com/leemunroe/grunt-email-workflow/blob/master/grunt/juice.js
*/
module.exports = function (grunt) {
// require it at the top and pass in the grunt instance
require('time-grunt')(grunt);
var imageminMozjpeg = require('imagemin-mozjpeg');
// Project configuration.
grunt.initConfig({
//Next we can read in the project settings from the package.json file into the pkg property.
//This allows us to refer to the values of properties within our package.json file, as we'll see shortly.
pkg: grunt.file.readJSON('package.json'),
/**
* Project paths setup
*/
paths: {
// assets folder name.
assets: 'assets',
// where to store compiled files.
compile: 'compile',
// where to store built files.
dist: 'dist',
// sources
src: {
path : 'src',
less : '<%= paths.src.path %>/styles/less/',
layouts : '<%= paths.src.path %>/layouts/',
emails : '<%= paths.src.path %>/emails/',
partials: '<%= paths.src.path %>/partials/',
data : '<%= paths.src.path %>/data/',
helpers : '<%= paths.src.path %>/helpers/',
img : '<%= paths.src.path %>/img/'
},
// Le domaine qui héberge les images.
remoteAssetsDomain: 'http://preprod.lahautesociete.com/petzl/petzl_newsletter/'
},
// secrets.json is ignored in git because it contains sensitive data
// See the README for configuration settings
vault: grunt.file.readJSON('vault.json'),
// Optimise les images et les place dans le dossier assets/img
imagemin: {
dynamic: {
options: { // Target options
optimizationLevel: 3, // png
svgoPlugins : [{
removeViewBox: false
}],
//use: [imageminMozjpeg({quality: 10})] // jpg compress.
}, // Target
files : [{
expand: true, // Enable dynamic expansion
cwd : '<%= paths.src.path.img %>', // Src matches are relative to this path
src : ['**/*.{png,jpg,gif}'], // Actual patterns to match
dest : '<%= paths.compile %>/<%= paths.assets %>/' // Destination path prefix
}]
}
},
// Vider les dossiers de compil/dist/...
clean: {
build: {
src: ['<%= paths.compile %>/*', '<%= paths.dist %>/*']
}
},
// Compiler les fichiers less.
less: {
dev : {},
dist: {
options: {
paths: ['<%= paths.src.less %>']
},
files : {
'<%= paths.compile %>/<%= paths.assets %>/css/main.css': '<%= paths.src.less %>/main.less'
}
}
},
// "Assembler" les layouts avec leurs contenus (handlebars).
assemble: {
options: {
layoutdir: '<%= paths.src.layouts %>',
assets : '<%= paths.compile %>/<%= paths.assets %>',
partials : ['<%= paths.src.partials %>/**/*.hbs'],
data : ['<%= paths.src.data %>/data.json'],
helpers : ['<%= paths.src.helpers %>/myHelpers.js'],
flatten : true,
toto : 'tutu'
},
dist : {
options: {
//baseUrl: '<%= paths.distDomain %>'
},
src : ['<%= paths.src.emails %>/*.hbs'],
dest : '<%= paths.compile %>/'
}
},
// Copier les assets (images) dans 'dist".
copy: {
files: {
cwd : '<%= paths.compile %>/', // set working folder / root to copy
src : ['<%= paths.assets %>/img/**/*.*'], // copy all files and subfolders
dest : '<%= paths.dist %>/', // destination folder
expand: true // required when using cwd
}
},
// "Inliner" les styles.
premailer: {
dist: {
options: {
removeComments: false,
verbose : true,
ioException : true
},
files : [{
cwd : '<%= paths.compile %>/',
expand: true,
src : ['*.html'],
dest : '<%= paths.dist %>/'
}]
}
},
// Préfixe le chemin des images avec 'remoteAssetsDomain'. Les images doivent être préalablement placées sur le domaine 'à la main (ftp)'.
cdn: {
options: {
/** @required - root URL of your CDN (may contains sub-paths as shown below) */
cdn : '<%= paths.remoteAssetsDomain %>',
/** @optional - if provided both absolute and relative paths will be converted */
flatten : true,
/** @optional - if provided will be added to the default supporting types */
supportedTypes: 'html'
},
dist : {
/** @required - gets sources here, may be same as dest */
cwd : '<%= paths.dist %>',
/** @required - puts results here with respect to relative paths */
dest: '<%= paths.dist %>',
/** @required - files to process */
src : ['{,*/}*.html', '{,**/}*.html'],
}
},
// Use Mailgun option if you want to email the design to your inbox or to something like Litmus
mailgun: {
mailer: {
options: {
key : "<%= vault.mailgun.api_key %>", // Enter your Mailgun API key here
sender : "<%= vault.mailgun.sender %>",
recipient: "<%= vault.mailgun.recipient %>",
subject : "Newslettr <%= grunt.template.today(\'yyyy-mm-dd-HH:MM\') %>"
},
src : '<%= paths.dist %>/*.html'
}
},
// Watches for changes to css or email templates then runs grunt tasks
watch: {
options : {
livereload: true,
},
gruntfile: {
files: 'Gruntfile.js',
tasks: ['default']
},
src : {
files: ['<%= paths.src.less %>/*', '<%= paths.src.emails %>/*', '<%= paths.src.layouts %>/*', '<%= paths.src.partials %>/**/*', '<%= paths.src.data %>/*'],
tasks: ['default']
}
}
});
// Load tasks.
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-assemble');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-mailgun');
grunt.loadNpmTasks('grunt-premailer');
grunt.loadNpmTasks('grunt-cdn');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-notify');
// Default task(s). On vide les dossiers 'compile' et 'dist'. On less. On assemble dans 'compile'. On optimise les images (et les copie dans 'compile/assets/img').
grunt.registerTask('default', ['clean', 'less', 'assemble', 'imagemin']);
// Dist. On fait la tache 'default'. On copy les éléments de 'compile' vers 'dist'. On inline les style.
grunt.registerTask('dist', ['default', 'copy', 'premailer']);
// Send. On fait la tache 'dist'. On change les liens des images. On envoie le/les emails.
grunt.registerTask('send', ['dist', 'cdn', 'mailgun']);
};