-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgulpfile.js
192 lines (171 loc) · 5.31 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
var fs = require('fs');
var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var nodemon = require('gulp-nodemon');
var browserify = require('browserify');
var livereload = require('gulp-livereload');
var awspublish = require("gulp-awspublish");
var shell = require('gulp-shell');
var hash = require('gulp-hash');
var env = require('gulp-env');
var ini = require('ini');
try {
var aws = JSON.parse(fs.readFileSync('./aws.json'));
} catch (e) {
console.error('WARNING: aws.json empty. See https://www.npmjs.com/package/gulp-s3')
var aws = null;
}
var foundation = "./bower_components/foundation";
var paths = {
styles: ['./scss/*.scss'],
scripts: {
browserify: ["./public/scripts/browserify/*.js"],
vendor: [
foundation + "/js/vendor/jquery.js",
foundation + "/js/vendor/*.js",
foundation + "/js/foundation.min.js",
"./bower_components/jquery.transit/jquery.transit.js",
"./bower_components/slick-carousel/slick/slick.js"
]
// foundation: [foundation + "/js/foundation/foundation.abide.js", foundation + "/js/foundation/foundation.topbar.js"]
},
resources: [
"./bower_components/slick-carousel/slick/ajax-loader.gif",
"./bower_components/slick-carousel/slick/fonts/*",
],
};
gulp.task('watch', function() {
livereload.listen();
gulp.watch(paths.styles, ['styles']);
gulp.watch(paths.scripts.browserify, ['browserify']);
gulp.watch(paths.scripts.vendor, ['concat']);
});
gulp.task('livereload', livereload)
gulp.task('images-compress', function () {
var mozjpeg = require('imagemin-mozjpeg');
return gulp.src('./images/**/*.jpg')
.pipe(mozjpeg()())
.pipe(gulp.dest('./images/'));
});
gulp.task('images-upload-cached', function () {
if (!aws) {
return console.error('WARNING: No aws.json credentials found, skipping.')
}
// create a new publisher
var publisher = awspublish.create(aws);
var headers = {
'Cache-Control': 'max-age=315360000, no-transform, public'
};
return gulp.src('./images/**/*.hash*.*')
.pipe(publisher.publish(headers))
.pipe(awspublish.reporter());
});
gulp.task('images-upload-transient', function(){
if (!aws) {
return console.error('WARNING: No aws.json credentials found, skipping.')
}
// create a new publisher
var publisher = awspublish.create(aws);
var max_age = 1000 * 60 * 60; // cache for one hour.
var headers = {
'Cache-Control': 'max-age=' + max_age + ', no-transform, public'
};
return gulp.src('./images/**/!(*.hash*)')
.pipe(publisher.publish(headers))
.pipe(awspublish.reporter());
});
gulp.task('images-hash', function(){
return gulp.src('./images/**/!(*hash-*)')
.pipe(hash({
"template": "<%= name %>.hash-<%= hash %><%= ext %>"
}))
.pipe(gulp.dest('./images'))
});
gulp.task('images-download', function(){
if (!aws) {
return console.error('WARNING: No aws.json credentials found, skipping.')
}
return gulp.src('')
.pipe(shell(["aws s3 sync s3://" + aws.bucket + " ./images"]));
});
gulp.task('images', ['images-compress', 'images-upload']);
gulp.task('images-upload', ['images-hash', 'images-upload-cached', 'images-upload-transient']);
gulp.task('browserify', function() {
browserify("./public/scripts/browserify/index.js")
.bundle(function (err) {
err && console.error('[error]', err.message);
})
.pipe(source('landing.js'))
.pipe(gulp.dest('build/public/scripts/'))
.pipe(rename('landing.min.js'))
.pipe(streamify(uglify({
drop_console: true,
})))
.pipe(gulp.dest('build/public/scripts/'))
.pipe(livereload())
});
gulp.task('concat', function() {
gulp.src(paths.scripts.vendor)
.pipe(concat('vendor.js'))
.pipe(gulp.dest('build/public/scripts/'))
.pipe(rename('vendor.min.js'))
.pipe(streamify(uglify({
drop_console: true,
})))
.pipe(gulp.dest('build/public/scripts/'))
});
gulp.task('styles', function() {
gulp.src('./scss/*.scss')
.pipe(sass({
errLogToConsole: true,
includePaths: ["bower_components/foundation/scss/"]
}))
.pipe(gulp.dest('build/public/stylesheets/'))
.pipe(livereload());
gulp.src(paths.resources)
.pipe(gulp.dest('build/public/stylesheets'))
});
gulp.task('set-env', function () {
try {
var source = ini.parse(fs.readFileSync(__dirname + '/.env', 'utf-8'));
} catch (e) {
var source = {};
}
source.NODE_ENV = process.env.NODE_ENV || 'development';
env({
vars: source,
});
});
gulp.task('nodemon', ['set-env'], function() {
nodemon({
script: 'index.js',
ext: 'jade js json',
ignore: [
'assets/',
'facets/*/test/',
'node_modules/',
'test/',
],
stdout: true,
})
.on('restart', function(file){
console.log(file + " changed restarting");
livereload(file);
})
.on('readable', function() {
this.stdout
// .pipe(bistre({time: true}))
.pipe(process.stdout);
this.stderr
// .pipe(bistre({time: true}))
.pipe(process.stderr);
});
});
gulp.task('build', ['styles', 'concat', 'browserify']);
gulp.task('dev', ['build', 'nodemon', 'watch']);
gulp.task('default', ['build']);