-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
191 lines (159 loc) · 5.27 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
'use strict';
var gulp = require('gulp');
var browserify = require('gulp-browserify');
var sass = require('gulp-sass');
var csso = require('gulp-csso');
var livereload = require('gulp-livereload');
var tinylr = require('tiny-lr');
var server = tinylr();
var jade = require('gulp-jade');
var path = require('path');
var express = require('express');
var app = express();
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var s3 = require('gulp-s3');
var gzip = require('gulp-gzip');
var colors = require('colors');
var rename = require('gulp-rename');
var _ = require('lodash');
var moment = require('moment');
var PRODUCTION_MODE = gutil.env.production;
var projectName = require('./package').name;
gulp.task('js-lib', function() {
return gulp.src('src/js/lib/**/*.js')
.pipe(gulpif(PRODUCTION_MODE, uglify()))
.pipe(gulp.dest('./public/js/lib/'))
.pipe( livereload( server ));
});
gulp.task('gzip', ['build'], function() {
return gulp.src('public/**/*.{js,css}')
.pipe(gzip())
.pipe(rename(function(path) {
path.extname = '';
}))
.pipe(gulp.dest('./public/'));
});
gulp.task('browserify', function() {
// Single entry point to browserify
return gulp.src('src/js/app.js')
.pipe(browserify({
debug : !PRODUCTION_MODE
}))
.on('error', gutil.log)
.on('error', gutil.beep)
.pipe(gulpif(PRODUCTION_MODE, uglify()))
.pipe(gulp.dest('./public/js/'))
.pipe( livereload( server ));
});
gulp.task('css', function() {
return gulp
.src('src/stylesheets/app.scss')
.pipe(
sass({
includePaths: ['src/stylesheets'],
errLogToConsole: true
}))
.pipe( gulpif(PRODUCTION_MODE, csso()) )
.pipe( gulp.dest('./public/css/') )
.pipe( livereload( server ));
});
gulp.task('fonts', function() {
return gulp
.src('src/fonts/**/*.{otf,svg,ttf,woff,eot}')
.pipe( gulp.dest('./public/fonts/') )
.pipe( livereload( server ));
});
gulp.task('images', function() {
return gulp
.src('src/images/**/*')
.pipe( gulp.dest('./public/images/') )
.pipe( livereload( server ));
});
gulp.task('jade', function() {
delete require.cache[require.resolve('./src/js/utils')];
var utils = require('./src/js/utils');
// var host = '/' + projectName + '/';
// if(!PRODUCTION_MODE) {
// host = '/';
// }
var host = './';
return gulp.src('src/templates/index.jade')
.pipe(jade({
pretty: !PRODUCTION_MODE,
locals: {
utils: utils,
STATIC_URL: host,
moment: moment,
_: _,
participants: require('./src/js/data/participants.json'),
alumni: require('./src/js/data/alumni.json')
}
}))
.on('error', gutil.log)
.on('error', gutil.beep)
.pipe(gulp.dest('./public/'))
.pipe( livereload( server ));
});
gulp.task('templates', ['static'], function() {
return gulp.start('jade');
});
gulp.task('express', function() {
app.use(express.static(path.resolve('./public')));
app.listen(8000);
gutil.log('Listening on port: 8000');
});
gulp.task('watch', function () {
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
gulp.watch('src/stylesheets/**/*.{scss,css}',['css', 'jade']);
gulp.watch('src/js/**/*.js',['js']);
gulp.watch('src/templates/**/*.jade',['jade', 'js']);
});
});
gulp.task('gzip', ['build'], function() {
return gulp.src('public/**/*.{js,css}')
.pipe(gzip())
.pipe(rename(function(path) {
path.extname = '';
}))
.pipe(gulp.dest('./public/'));
});
gulp.task('deploy', ['gzip'], function() {
var aws;
try {
aws = {
'key': process.env.AWS_KEY,
'secret': process.env.AWS_SECRET,
'bucket': process.env.AWS_BUCKET
};
if(!aws.key || !aws.secret || !aws.bucket) {
new Error('Problem with aws keys');
}
} catch(err) {
gutil.log('Could not parse aws keys. Aborting deployment.'.red);
return;
}
gulp.src(['./public/**', '!./public/**/*.{js,css,gz}'], { read: false })
.pipe(s3(aws, {
uploadPath: projectName + '/',
headers: {
'Cache-Control': 'max-age=300, no-transform, public'
}
}));
gulp.src('./public/**/*.{js,css,gz}', { read: false })
.pipe(s3(aws, {
uploadPath: projectName + '/',
headers: {
'Cache-Control': 'max-age=300, no-transform, public',
'Content-Encoding': 'gzip'
}
}));
});
gulp.task('js', ['browserify','js-lib']);
gulp.task('static', ['js', 'css', 'fonts', 'images']);
gulp.task('default', ['templates','express','watch']);
gulp.task('build', ['templates']);