-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
96 lines (83 loc) · 2.47 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
var gulp = require('gulp'),
shell = require('gulp-shell'),
path = require('path'),
s3 = require('gulp-s3'),
minify = require('gulp-minify'),
gzip = require('gulp-gzip'),
cloudfront = require('gulp-cloudfront-invalidate'),
AWS = require('aws-sdk'),
replace = require('gulp-replace');
var envName = process.env.ENV || 'staging';
var envConfig = function () {
return {
production: {
bucket: 'easyedu',
distribution: process.env.EASYEDU_SCRIPTS_PRODUCTION_DISTRIBUTION,
url: 'https://api.easyedu.co'
},
staging: {
bucket: 'easyedu',
distribution: process.env.EASYEDU_SCRIPTS_STAGING_DISTRIBUTION,
url: 'https://easy-edu.herokuapp.com'
}
}[envName];
};
function s3Config () {
return {
key: process.env.AWS_ACCESS_KEY_ID,
secret: process.env.AWS_SECRET_ACCESS_KEY,
region: 'us-west-2',
bucket: envConfig().bucket
};
};
function cloudfrontConfig () {
return {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
distribution: envConfig().distribution
};
};
gulp.task('deploy', shell.task([
'gulp config',
'gulp minify',
'gulp compress',
'gulp upload',
'gulp invalidate'
]));
gulp.task('eslint', shell.task([
'./node_modules/.bin/eslint enrollment.js',
'./node_modules/.bin/eslint --parser-options=sourceType:module --env "es6" cypress/ gulpfile.js'
]));
gulp.task('config', function() {
return gulp.src(['enrollment.js'])
.pipe(replace('http://localhost:9292', envConfig().url))
.pipe(gulp.dest('dist/' + envName));
});
gulp.task('minify', function() {
return gulp.src(['dist/' + envName + '/enrollment.js'])
.pipe(minify({ ext: { min: '.js' }, noSource: true }))
.pipe(gulp.dest('dist/' + envName));
});
gulp.task('compress', function() {
return gulp.src(['dist/' + envName + '/enrollment.js'])
.pipe(gzip({
gzipOptions: {
level: 9 // best compression
}
}))
.pipe(gulp.dest('dist/' + envName));
});
gulp.task('upload', function() {
var s3Options = {
headers: {
'Cache-Control': 'max-age=600, no-transform, public'
},
uploadPath: (envName + '/scripts'),
gzippedOnly: true
};
return gulp.src(['dist/' + envName + '/enrollment.js.gz']).pipe(s3(s3Config(), s3Options));
});
gulp.task('invalidate', function() {
var config = Object.assign({ paths: ['/enrollment.js'] }, cloudfrontConfig());
return gulp.src('dist/' + envName + '/enrollment.js.gz').pipe(cloudfront(config));
});