forked from keen/keen-tracking.js
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
54 lines (45 loc) · 1.46 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
var gulp = require('gulp'),
pkg = require('./package.json');
var aws = require('gulp-awspublish'),
connect = require('gulp-connect'),
rename = require('gulp-rename');
// FIXME: move this to npm if possible
gulp.task('serve', function () {
return connect.server({
root: [__dirname, 'dist'],
port: 8000
});
});
gulp.task('deploy', function() {
if (!process.env.AWS_KEY || !process.env.AWS_SECRET) {
throw 'AWS credentials are required!';
}
var publisher = aws.create({
key: process.env.AWS_KEY,
secret: process.env.AWS_SECRET,
bucket: 'prodperfect-keen-js', // pkg.name
endpoint: 's3.us-east-2.amazonaws.com',
region: 'us-east-2'
});
var cacheLife = (1000 * 60 * 60 * 24 * 365); // 1 year
var headers = {
// Cache policy (1000 * 60 * 60 * 1) // 1 hour
// 'Cache-Control': 'max-age=3600000, public',
// 'Expires': new Date(Date.now() + 3600000).toUTCString()
'Cache-Control': 'max-age=' + cacheLife + ', public',
'Expires': new Date(Date.now() + cacheLife).toUTCString()
};
return gulp.src([
'./dist/keen-tracking.js',
'./dist/keen-tracking.min.js'
])
.pipe(rename(function(path) {
path.dirname += '/';
var name = pkg.name + '-' + pkg.version;
path.basename = (path.basename.indexOf('min') > -1) ? name + '.min' : name;
}))
.pipe(aws.gzip())
.pipe(publisher.publish(headers, { force: true }))
.pipe(publisher.cache())
.pipe(aws.reporter());
});