-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
235 lines (202 loc) · 6.32 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
'use strict';
// generated on 2014-06-19 using generator-gulp-webapp 0.1.0
var gulp = require('gulp'),
runSequence = require('run-sequence'),
fs = require('fs');
// load plugins
var $ = require('gulp-load-plugins')();
gulp.task('styles', function () {
return gulp.src('app/styles/main.scss')
.pipe($.sass({
outputStyle: 'expanded',
precision: 10
}))
.pipe($.autoprefixer('last 1 version'))
.pipe(gulp.dest('.tmp/styles'))
.pipe($.size());
});
gulp.task('scripts', function () {
return gulp.src('app/scripts/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')))
.pipe($.size());
});
gulp.task('html', ['styles', 'scripts'], function () {
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
return gulp.src('.tmp/*.html')
.pipe($.useref.assets({searchPath: '{.tmp,app}'}))
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.rev())
.pipe($.useref.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('images', function () {
return gulp.src('app/images/**/*')
// TODO: can't enable imagemin right now it would break retina support
// .pipe($.cache($.imagemin({
// optimizationLevel: 3,
// progressive: true,
// interlaced: true
// })))
.pipe(gulp.dest('dist/images'))
.pipe($.size());
});
gulp.task('favicons', function () {
return gulp.src([
'app/favicon*.{png,ico}',
])
.pipe(gulp.dest('dist'))
.pipe($.size());
});
gulp.task('fonts', function () {
return gulp.src('app/fonts/**/*.{eot,svg,ttf,woff}')
.pipe(gulp.dest('dist/fonts'))
.pipe($.size());
});
gulp.task('extras', function () {
return gulp.src(['app/*.*', '!app/*.html'], { dot: true })
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function () {
return gulp.src(['.tmp', 'dist'], { read: false }).pipe($.clean());
});
gulp.task('build', ['html', 'favicons', 'images', 'fonts', 'extras']);
gulp.task('build:dev', function(cb) {
// TODO: runSequence is a hack waiting for Gulp 4.0 to be out
runSequence(
'templates:render:dev',
'build',
cb);
});
gulp.task('build:prod', function(cb) {
// TODO: runSequence is a hack waiting for Gulp 4.0 to be out
runSequence(
'templates:render:prod',
'build',
cb);
});
gulp.task('templates:extend', function () {
return gulp.src([
'app/*.html',
'!app/_master.html',
])
.pipe($.htmlExtend({
annotations: true,
verbose: true
}))
.pipe(gulp.dest('.tmp'));
});
gulp.task('templates:render:dev', ['templates:extend'], function() {
var content = fs.readFileSync('./envs/dev.json'),
data = JSON.parse(content);
return gulp.src('.tmp/*.html')
.pipe($.data(function () {
return data;
}))
.pipe($.template())
.pipe(gulp.dest('.tmp'));
});
gulp.task('templates:render:prod', ['templates:extend'], function() {
var content = fs.readFileSync('./envs/prod.json'),
data = JSON.parse(content);
return gulp.src('.tmp/*.html')
.pipe($.data(function () {
return data;
}))
.pipe($.template())
.pipe(gulp.dest('.tmp'));
});
gulp.task('connect', function () {
var connect = require('connect');
var app = connect()
.use(require('connect-livereload')({ port: 35729 }))
.use(connect.static('.tmp'))
.use(connect.static('app'))
.use(connect.directory('app'));
require('http').createServer(app)
.listen(9000)
.on('listening', function () {
console.log('Started connect web server on http://localhost:9000');
});
});
gulp.task('serve', ['connect', 'styles', 'templates:render:dev'], function () {
require('opn')('http://localhost:9000');
});
// inject bower components
gulp.task('wiredep', function () {
var wiredep = require('wiredep').stream;
gulp.src('app/styles/*.scss')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app/styles'));
gulp.src('app/*.html')
.pipe(wiredep({
directory: 'app/bower_components'
}))
.pipe(gulp.dest('app'));
});
gulp.task('watch', ['connect', 'serve'], function () {
var server = $.livereload();
// watch for changes
gulp.watch([
'.tmp/*.html',
// 'app/*.html',
'.tmp/styles/**/*.css',
'app/scripts/**/*.js',
'app/images/**/*'
]).on('change', function (file) {
server.changed(file.path);
});
gulp.watch('app/styles/**/*.scss', ['styles']);
gulp.watch('app/scripts/**/*.js', ['scripts']);
gulp.watch('app/images/**/*', ['images']);
gulp.watch('envs/dev.json', ['templates:render:dev']);
gulp.watch('app/*.html', ['templates:render:dev']);
gulp.watch('bower.json', ['wiredep']);
});
gulp.task('set-env', function (cb) {
$.env({
file: ".env.json"
});
cb();
});
// AWS
gulp.task('aws:publish', ['set-env'], function() {
var publisher = $.awspublish.create({
bucket: process.env.AWS_S3_BUCKET,
key: process.env.AWS_S3_KEY,
secret: process.env.AWS_S3_SECRET,
region: 'eu-west-1',
endpoint: 's3-eu-west-1.amazonaws.com'
// TODO: move the s3 to the Frankfürt region
// but knox do not support the HMAC-SHA-256 auth yet
// region: 'eu-central-1',
// endpoint: 's3.eu-central-1.amazonaws.com'
});
return gulp.src('./dist/**/*')
.pipe(publisher.publish())
.pipe(publisher.sync())
.pipe($.awspublish.reporter());
});
gulp.task('aws:sync', function(cb) {
// TODO: runSequence is a hack waiting for Gulp 4.0 to be out
runSequence(
'clean',
'build:prod',
'aws:publish',
function() {
$.notify({ message: "Site published to the S3" });
// inform the sequence has been completed
cb();
});
});