forked from codeforamerica/lexington-qold
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
195 lines (177 loc) · 5.84 KB
/
gulpfile.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
var gulp = require('gulp'),
connect = require('gulp-connect'),
less = require('gulp-less'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
markdown = require('gulp-markdown'),
convert = require('gulp-convert'),
imagemin = require('gulp-imagemin'),
replace = require('gulp-replace'),
del = require('del'),
run = require('run-sequence'),
psi = require('psi'),
open = require('open'),
fs = require('fs');
var jsFiles = [
'bower_components/jquery/dist/jquery.js',
'bower_components/bootstrap/js/transition.js',
'bower_components/bootstrap/js/button.js',
'bower_components/bootstrap/js/collapse.js',
'bower_components/bootstrap/js/dropdown.js',
'bower_components/bootstrap/js/tooltip.js',
'bower_components/jquery-placeholder/jquery.placeholder.js',
'bower_components/leaflet/dist/leaflet.js',
'assets/scripts/vendor/jquery-ui-1.10.3.custom.min.js',
'assets/scripts/vendor/chosen.jquery.js',
'bower_components/d3/d3.js',
'assets/scripts/vendor/pubsub.js',
'bower_components/topojson/topojson.js',
'assets/scripts/vendor/typeahead.js',
'assets/scripts/vendor/jquery-tourbus.js',
'bower_components/lodash/dist/lodash.underscore.js',
'bower_components/jquery.scrollTo/jquery.scrollTo.js',
'assets/scripts/function-globals.js',
'assets/scripts/functions/*.js',
'assets/scripts/config.js',
'assets/scripts/main.js'
];
// livereload server
gulp.task('connect', function() {
connect.server({
root: '_site',
livereload: true,
port: 8000
});
});
// Less processing
gulp.task('less', function() {
return gulp.src('assets/less/main.less')
.pipe(less())
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('_site/css'))
.pipe(connect.reload());
});
gulp.task('less-build', function() {
return gulp.src('assets/less/main.less')
.pipe(less())
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(minifycss())
.pipe(gulp.dest('_site/css'));
});
// JavaScript
gulp.task('js', function() {
return gulp.src(jsFiles)
.pipe(concat('main.js'))
.pipe(gulp.dest('_site/js'))
.pipe(connect.reload());
});
gulp.task('js-build', function() {
return gulp.src(jsFiles)
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('_site/js'));
});
// markdown
gulp.task('markdown', function() {
return gulp.src('assets/data/meta/*.md')
.pipe(markdown())
.pipe(gulp.dest('_site/data/meta/'))
.pipe(connect.reload());
});
gulp.task('fonts', function() {
return gulp.src('assets/fonts/*')
.pipe(gulp.dest('_site/fonts/'))
.pipe(connect.reload());
});
gulp.task('geo', function() {
// cp topo and geojson
return gulp.src('assets/data/*json')
.pipe(gulp.dest('_site/data/'))
.pipe(connect.reload());
});
// CSV to JSON
gulp.task('convert', function() {
return gulp.src('assets/data/metric/*.csv')
.pipe(convert({
from: 'csv',
to: 'json'
}))
.pipe(gulp.dest('_site/data/metric/'));
});
// image processing
gulp.task('imagemin', function() {
return gulp.src('assets/images/build/*')
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
}))
.pipe(gulp.dest('_site/images'));
});
gulp.task('static', function() {
return gulp.src('static/*')
.pipe(gulp.dest('_site/'))
.pipe(connect.reload());
});
// cache busting
gulp.task('cachebuster', function() {
return gulp.src('_site/**/*.html')
.pipe(replace(/foo=[0-9]*/g, 'foo=' + Math.floor((Math.random() * 100000) + 1)))
.pipe(gulp.dest('_site/'));
});
// open broser
gulp.task("browser", function(){
return open('http://localhost:8000');
});
// watch
gulp.task('watch', function () {
gulp.watch(['./static/*.html'], ['static']);
gulp.watch(['./assets/data/meta/*.md'], ['markdown']);
gulp.watch(['./assets/less/**/*.less'], ['less']);
gulp.watch('assets/scripts/**/*.js', ['js']);
});
gulp.task('clean', function(cb) {
return del('./_site', cb)
});
// rename files for basic setup
gulp.task('init', function() {
// make sure people don't run this twice and end up with no search.js
fs.exists('assets/scripts/functions/search.js.basic', function(exists) {
if (exists) {
console.log("renaming search files...");
// rename mecklenburg search file to search.js.meck
fs.rename('assets/scripts/functions/search.js', 'assets/scripts/functions/search.js.advanced', function(err) {
if ( err ) { console.log('ERROR: ' + err); }
});
// rename default search file to search.js
fs.rename('assets/scripts/functions/search.js.basic', 'assets/scripts/functions/search.js', function(err) {
if ( err ) { console.log('ERROR: ' + err); }
});
}
});
});
// performace tests
gulp.task('psi-mobile', function (cb) {
psi({
nokey: 'true', // or use key: ‘YOUR_API_KEY’
url: 'http://mcmap.org/qol',
strategy: 'mobile'
}, cb);
});
// performace test
gulp.task('psi-desktop', function (cb) {
psi({
nokey: 'true', // or use key: ‘YOUR_API_KEY’
url: 'http://mcmap.org/qol',
strategy: 'desktop'
}, cb);
});
// controller tasks
gulp.task('default', ['build','less', 'js', 'watch', 'connect']);
gulp.task('build', function(cb) {
run('clean',
['less-build', 'js-build', 'markdown', 'fonts', 'convert', 'static', 'cachebuster','geo','imagemin'],
cb);
});