-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
305 lines (280 loc) · 8.86 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
var ENV_STAGE = process.env.ENV_STAGE || 's:/projects/';
var fs = require("fs");
var request = require("request");
module.exports = function(grunt) {
'use strict';
// this is the directory path to your project on the stage/prod servers
var site_path = "ut-tower-shooting-50th-anniversary";
// Project configuration.
grunt.initConfig({
// Clean files from dist/ before build
clean: {
css: ["public/dist/*.css", "public/dist/*.css.map"],
js: ["public/dist/*.js", "public/dist/*.js.map"],
fonts: ["public/fonts/**"],
pages: ["public/**.html"]
},
// Copy FontAwesome/slick files to the fonts/ directory
copy: {
fonts: {
src: [
'node_modules/font-awesome/fonts/**',
'node_modules/slick-carousel/slick-carousel/fonts/**'
],
dest: 'public/fonts/',
flatten: true,
expand: true
}
},
// Transpile LESS
less: {
options: {
sourceMap: true,
sourceMapFilename: 'public/dist/style.css.map',
sourceMapURL: 'style.css.map',
sourceMapRootpath: '../',
paths: ['node_modules/bootstrap/less']
},
prod: {
options: {
compress: true,
yuicompress: true
},
files: {
"public/dist/style.css": [
"node_modules/slick-carousel/slick/slick.less",
"src/css/style.less"
]
}
}
},
// Run our JavaScript through JSHint
jshint: {
js: {
src: ['src/js/**.js']
}
},
// Lint our Bootstrap usage
bootlint: {
options: {
relaxerror: ['W005']
},
files: 'public/**.html',
},
// Use Uglify to bundle scripts
uglify: {
options: {
sourceMap: true
},
prod: {
files: {
'public/dist/js/front.js': [
'node_modules/jquery/dist/jquery.js',
'node_modules/underscore/underscore.js',
'node_modules/imagesloaded/imagesloaded.pkgd.js',
'node_modules/slick-carousel/slick/slick.js',
'node_modules/masonry-layout/dist/masonry.pkgd.js',
'src/js/slider.js',
'src/js/main.js',
'src/js/front.js'
],
'public/dist/js/shootingdata.js': [
'node_modules/jquery/dist/jquery.js',
'node_modules/underscore/underscore.js',
'src/js/slider.js',
'src/js/main.js',
'node_modules/d3/d3.js',
'node_modules/d3-queue/build/d3-queue.js',
'node_modules/topojson/build/topojson.js',
'node_modules/datatables.net/js/jquery.dataTables.js',
'node_modules/datatables.net-bs/js/dataTables.bootstrap.js',
'node_modules/datatables.net-responsive/js/dataTables.responsive.js',
'node_modules/datatables.net-responsive-bs/js/responsive.bootstrap.js',
'node_modules/moment/min/moment.min.js',
'src/js/shootingdata.js'
],
'public/dist/js/interviews.js': [
'node_modules/jquery/dist/jquery.js',
'node_modules/underscore/underscore.js',
'src/js/slider.js',
'src/js/main.js',
'src/js/interviews.js'
],
'public/dist/scripts.js': [
'node_modules/jquery/dist/jquery.js',
'node_modules/underscore/underscore.js',
'node_modules/imagesloaded/imagesloaded.pkgd.js',
'node_modules/slick-carousel/slick/slick.js',
'node_modules/masonry-layout/dist/masonry.pkgd.js',
'src/js/slider.js',
'src/js/main.js'
]
}
}
},
// Watch for changes in LESS and JavaScript files,
// relint/retranspile when a file changes
watch: {
options: {
livereload: true,
},
templates: {
files: ['pages/**/*', 'layouts/*', 'helpers/**', 'partials/*'],
tasks: ['build:html']
},
scripts: {
files: ['src/js/**.js'],
tasks: ['copy:scripts', 'build:js']
},
styles: {
files: ['src/css/**.less', 'src/css/**/**.less'],
tasks: ['build:css']
}
},
// A simple little development server
connect: {
server: {
options: {
hostname: '*',
base: 'public',
keepalive: true,
livereload: true,
open: true
}
}
},
// A tool to run the webserver and livereloader simultaneously
concurrent: {
options: {
logConcurrentOutput: true
},
dev: ['connect', 'watch']
},
// Bake out static HTML of our pages
generator: {
prod: {
files: [{
cwd: 'pages',
src: ['**/*'],
dest: 'public'
}],
options: {
partialsGlob: 'partials/*.hbs',
templates: 'layouts',
templateExt: 'hbs',
helpers: require('./helpers'),
base: 'http://projects.statesman.com/news/' + site_path + "/",
nav: [
{
title: "Introduction",
subtitle: "A new kind of madness",
file: "index"
},
{
title: "Mass shootings",
subtitle: "Explore U.S. data",
file: "shootingdata"
},
{
title: "Interviews",
subtitle: "Watch the videos",
file: "interviews"
},
{
title: "Coverage and documents",
subtitle: "Browse the archives",
file: "archives"
}
]
}
}
},
// stage path needs to be set
ftpush: {
stage: {
auth: {
host: 'cmgdtcpxahost.cmg.int',
port: 21,
authKey: 'cmg'
},
src: 'public',
dest: '/stage_aas/projects/news/' + site_path,
exclusions: ['dist/tmp','Thumbs.db','.DS_Store'],
simple: false,
useList: false,
keep: ['*']
},
// prod path will need to change
prod: {
auth: {
host: 'cmgdtcpxahost.cmg.int',
port: 21,
authKey: 'cmg'
},
src: 'public',
dest: '/prod_aas/projects/news/' + site_path,
exclusions: ['dist/tmp','Thumbs.db','.DS_Store'],
simple: false,
useList: false,
keep: ['*']
}
},
});
// Load the task plugins
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-generator');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-bootlint');
grunt.loadNpmTasks('grunt-ftpush');
// register a custom task to hit slack
grunt.registerTask('slack', function(where_dis_go) {
// first, check to see if there's a .slack file
// (this file has the webhook endpoint)
if(grunt.file.isFile('.slack')) {
// homeboy here runs async, so
var done = this.async();
// prod or stage?
var ftp_path = where_dis_go === "prod" ? "http://projects.statesman.com/news/" + site_path : "http://stage.host.coxmediagroup.com/aas/projects/news/" + site_path;
// do whatever makes you feel happy here
var payload = {
"text": "yo dawg i heard you like pushing code to *ut-tower-shooting*: " + ftp_path,
"channel": "#bakery",
"username": "Xzibit",
"icon_url": "http://projects.statesman.com/slack/icon_img/xzibit.jpg"
};
// send the request
request.post(
{
url: fs.readFileSync('.slack', {encoding: 'utf8'}),
json: payload
},
function callback(err, res, body) {
done();
if (body !== "ok") {
return console.error('upload failed:', body);
}
console.log('we slacked it up just fine people, good work');
});
}
// if no .slack file, log it
else {
grunt.log.warn('No .slack file exists. Skipping Slack notification.');
}
});
// Assorted build tasks
grunt.registerTask('build:html', ['clean:pages', 'generator', 'bootlint']);
grunt.registerTask('build:css', ['clean:css', 'clean:fonts', 'copy', 'less']);
grunt.registerTask('build:js', ['clean:js', 'jshint', 'uglify']);
grunt.registerTask('build', ['build:html', 'build:js', 'build:css']);
// Publishing tasks
grunt.registerTask('stage', ['build', 'ftpush:stage','slack:stage']);
grunt.registerTask('prod', ['build', 'ftpush:prod','slack:prod']);
// A dev task that runs a build then launches a dev server w/ livereload
grunt.registerTask('default', ['build', 'concurrent']);
};