-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
349 lines (322 loc) · 9.1 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
346
347
348
349
/* jshint indent:2,maxstatements:false */
/* global module,require */
/*
This file configures common tasks when developing on slingsby.
Static files like css and js needs to be transpiled (minified and concatenated) before they can be
served, and SASS needs to be compiled to CSS and so on. In broad steps this process is first
collecting all files needed in the ./tmp directory, and then building the final set of files into
./build, which is also served by the devserver. Some processes might skip the ./tmp directory
entirely, like the imagemin step which takes the graphics directly from slingsby/static-src to
build/static.
To just run the devserver, all you need to do is `grunt prep`. This will generate all the files you
need, and when deploying Travis will run `grunt build` which in addition to prep also packages the
python code and the static files into tarballs that can be pushed to the server.
*/
module.exports = function (grunt) {
"use strict";
/* jshint camelcase: false */
// Load all grunt tasks defined in package.json
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
bower: {
install: {
options: {
copy: false,
}
}
},
/*
* Compile all .hbs (handlebars) templates to a shared file
*/
handlebars: {
compile: {
options: {
namespace: "slingsby.templates",
// Transform paths to sensible template names -> Extract filename, remove ext
processName: function (name) {
var path = name.split('/');
var filename = path[path.length - 1];
var parts = filename.split('.');
parts.pop(); //removes extension
return parts.join('.');
}
},
files: {
".tmp/handlebars_templates.js": "slingsby/*/templates/handlebars/*.hbs"
}
}
},
/*
* Compile SASS stylesheets.
*/
sass: {
dist: {
options: {
outputStyle: 'compressed',
includePaths: [
'.tmp/sass',
'bower_components/bootstrap-sass-official/assets/stylesheets',
'bower_components/blueimp-gallery/css',
'bower_components/compass-mixins/lib',
],
},
files: {
'.tmp/static/stylesheets/styles.css': 'slingsby/static-src/sass/styles.scss',
'.tmp/static/stylesheets/archive.css': 'slingsby/static-src/sass/archive.scss',
'.tmp/static/stylesheets/widgEditor.css': 'slingsby/static-src/sass/widgEditor.scss',
},
}
},
/* Needed because django can't serve out of the same directory it collects static files to */
copy: {
tmpToBuild: {
files: [{
expand: true,
src: ['**'],
cwd: '.tmp/static',
dest: 'build/static/'
}]
},
},
jshint: {
options: {
'jshintrc': '.jshintrc',
},
all: [
'Gruntfile.js',
'slingsby/**/static/js/*.js',
// Ignore the widgEditor lib that's not in the bower registry
'!slingsby/general/static/js/widgEditor.js',
]
},
/*
* Recompile css, update static dir and reload on template changes.
*/
watch: {
options: {
livereload: true
},
css: {
files: ['slingsby/static-src/sass/*.scss'],
tasks: ['sass', 'clean:build', 'copy:tmpToBuild']
},
js: {
files: ['<%= jshint.all %>'],
tasks: ['uglify', 'clean:build', 'copy:tmpToBuild']
},
templates: {
files: ['slingsby/**/templates/*.html'],
tasks: []
},
handlebars: {
files: ['slingsby/**/handlebars/*.hbs'],
tasks: ['handlebars', 'uglify', 'clean:build', 'copy:tmpToBuild']
},
python: {
files: ['slingsby/**/*.py']
}
},
pylint: {
slingsby: {
options: {
rcfile: '.pylintrc',
ignore: 'migrations',
},
src: ['slingsby', '*.py', 'tools/*.py'],
}
},
// Shortcuts for some often used commands
shell: {
options: {
stderr: true,
},
buildPython: {
command: 'python setup.py sdist --dist-dir build --formats gztar',
},
collectstatic: {
command: function () {
// The build/static directory needs to exist for the collectstatic command to succeed
grunt.file.mkdir('build/static');
return 'python manage.py collectstatic --noinput';
},
},
packageStatic: {
command: [
'cd build/static',
'tar czf ../static_files.tar.gz *',
].join(' && '),
},
},
clean: {
options: {
'no-write': false,
},
python: [
'slingsby/**/*.pyc',
'slingsby.egg-info',
],
build: [
'build',
],
tmp: [
'.tmp',
],
serverAssets: [
'slingsby/server-assets',
],
media: [
'media/**',
'!media',
]
},
imagemin: {
static: {
files: [{
expand: true,
cwd: 'slingsby/static-src/gfx',
src: [
'**/*.{png,jpg,gif}',
// Ignore originals
'!originals/**',
],
dest: '.tmp/static/gfx',
}]
},
},
filerev: {
options: {
algorithm: 'md5',
length: 8,
},
gfx: {
src: [
'build/static/gfx/**/*.{png,jpg,gif}',
'!build/static/gfx/widgEditor/**',
'!build/static/stylesheets/img/**',
]
},
styles: {
src: 'build/static/stylesheets/*.css',
},
js: {
src: 'build/static/js/*.js',
},
misc: {
src: [
'build/static/favicon.ico',
'build/static/robots.txt',
],
},
},
// Dumps filerev results to disk
filerev_assets: {
dist: {
options: {
dest: 'slingsby/server-assets/filerevs.json',
cwd: 'build/static/',
prettyPrint: true,
}
}
},
cssUrlEmbed: {
css: {
options: {
baseDir: 'slingsby/static-src/',
},
files: {
'.tmp/sass/_fonts.scss': 'slingsby/static-src/sass/_fonts_separate.scss',
}
}
},
uglify: {
options: {
sourceMap: true,
sourceMapIncludeSources: true,
},
dist: {
files: {
'.tmp/static/js/main.min.js': [
'bower_components/jquery/dist/jquery.js',
'slingsby/general/static/js/main.js',
],
'.tmp/static/js/articles.min.js': [
'bower_components/handlebars/handlebars.runtime.js',
'.tmp/handlebars_templates.js',
'bower_components/moment/moment.js',
'bower_components/moment/locale/nb.js',
'slingsby/articles/static/js/articles.js',
],
'.tmp/static/js/musikk.min.js': [
'slingsby/musikk/static/js/musikk.js',
],
'.tmp/static/js/event_detail.min.js': [
'slingsby/events/static/js/event_detail.js',
],
'.tmp/static/js/instagram.min.js': [
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal.js',
'slingsby/instagram/static/js/instagram.js',
],
'.tmp/static/js/archive.min.js': [
// Only add required parts of blueimp-gallery
//'bower_components/blueimp-gallery/js/blueimp-helper.js',
'bower_components/blueimp-gallery/js/blueimp-gallery.js',
'bower_components/blueimp-gallery/js/blueimp-gallery-fullscreen.js',
'bower_components/blueimp-gallery/js/blueimp-gallery-indicator.js',
//'bower_components/blueimp-gallery/js/blueimp-gallery-video.js',
//'bower_components/blueimp-gallery/js/blueimp-gallery-youtube.js',
//'bower_components/blueimp-gallery/js/blueimp-gallery-vimeo.js',
'bower_components/blueimp-gallery/js/jquery.blueimp-gallery.js',
'slingsby/archive/static/js/archive.js',
],
'build/static/js/socialSummary.min.js': 'slingsby/articles/static/js/socialSummary.js',
'build/static/js/widgEditor.min.js': 'slingsby/general/static/js/widgEditor.js',
}
}
},
});
// Default task
grunt.registerTask('default', [
'clean',
'prep',
'watch',
]);
grunt.registerTask('lint', [
'jshint',
'pylint',
]);
grunt.registerTask('pybuild', [
'shell:buildPython',
]);
grunt.registerTask('rev-files', [
'filerev',
'filerev_assets',
]);
grunt.registerTask('prep', [
'clean:build',
'shell:collectstatic',
'buildStyles',
'buildScripts',
'imagemin',
'copy:tmpToBuild',
]);
grunt.registerTask('build', [
'clean',
'prep',
'rev-files',
'shell:packageStatic',
'pybuild',
]);
grunt.registerTask('buildStyles', [
'cssUrlEmbed',
'sass',
]);
grunt.registerTask('buildScripts', [
'handlebars',
'uglify',
]);
grunt.registerTask('init-bower-deps', [
'bower',
]);
};