forked from HansUXdev/Motion-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
292 lines (264 loc) · 9.07 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
var $ = require('gulp-load-plugins')();
var argv = require('yargs').argv;
var browser = require('browser-sync');
var gulp = require('gulp');
var panini = require('panini');
var rimraf = require('rimraf');
var sequence = require('run-sequence');
var sherpa = require('style-sherpa');
var webpack = require('webpack-stream');
var imageResize = require('gulp-image-resize');
var rename = require("gulp-rename");
// var ghPages = require('gulp-gh-pages');
// Check for --production flag
var isProduction = !!(argv.production);
// Port to use for the development server.
var PORT = 8000;
// Browsers to target when prefixing CSS.
var COMPATIBILITY = ['last 2 versions', 'ie >= 9'];
// File paths to various assets are defined here.
var PATHS = {
assets: [
'src/assets/**/*',
'src/assets/css/fonts/**/*',
'!src/assets/{!img,scss}/**/*'
],
sass: [
'bower_components/foundation-sites/scss',
'bower_components/motion-ui/src/'
],
javascript: [
'bower_components/jquery/dist/jquery.js',
'bower_components/what-input/what-input.js',
'bower_components/foundation-sites/js/foundation.core.js',
'bower_components/foundation-sites/js/foundation.util.*.js',
// Paths to individual JS components defined below
'bower_components/foundation-sites/js/foundation.abide.js',
'bower_components/foundation-sites/js/foundation.accordion.js',
'bower_components/foundation-sites/js/foundation.accordionMenu.js',
'bower_components/foundation-sites/js/foundation.drilldown.js',
'bower_components/foundation-sites/js/foundation.dropdown.js',
'bower_components/foundation-sites/js/foundation.dropdownMenu.js',
'bower_components/foundation-sites/js/foundation.equalizer.js',
'bower_components/foundation-sites/js/foundation.interchange.js',
'bower_components/foundation-sites/js/foundation.magellan.js',
'bower_components/foundation-sites/js/foundation.offcanvas.js',
// Yeah... I'm just going to get rid of this...
// 'bower_components/foundation-sites/js/foundation.orbit.js',
'bower_components/foundation-sites/js/foundation.responsiveMenu.js',
'bower_components/foundation-sites/js/foundation.responsiveToggle.js',
'bower_components/foundation-sites/js/foundation.reveal.js',
'bower_components/foundation-sites/js/foundation.slider.js',
'bower_components/foundation-sites/js/foundation.sticky.js',
'bower_components/foundation-sites/js/foundation.tabs.js',
'bower_components/foundation-sites/js/foundation.toggler.js',
'bower_components/foundation-sites/js/foundation.tooltip.js',
//
'bower_components/cta/dist/cta.js',
'bower_components/waypoints/lib/jquery.waypoints.min.js',
'bower_components/flexslider/jquery.flexslider-min.js',
'vendor/Landio/js/plugins/jquery.vimeo.api.js',
'vendor/Landio/js/plugins/video.js',
// ButtonComponentMorph/js/modernizr.custom.js',
'bower_components/classie/classie.js',
'vendor/ButtonComponentMorph/js/uiMorphingButton_inflow.js',
'src/assets/js/morphing-newsletter.js',
// animated-signup-flow
'vendor/animated-signup-flow/js/velocity.min.js',
// 'src/assets/js/**/*.js',
'src/assets/js/app.js',
'src/assets/js/signup.js'
],
};
// IMAGE sizes
// 75 // icons
// 100 // small
// 400x370 // medium
// 900x170 // responsive-ad
// 2000x750 - for obit
// blog - 850w x 350h
// portfolio - 550 x 550
// large logo - 450 x 183
var INTERCHANGE = {
testimonial: [
'./src/assets/img/field-girl.jpeg',
'./src/assets/img/scarf-girl.jpeg',
'./src/assets/img/scarf-girl2.jpeg'
],
orbit: [
'./src/assets/img/surf-relax.jpeg',
'./src/assets/img/water-bubbles.jpeg',
'./src/assets/img/waterfall3.jpeg'
],
small: [
'./src/assets/img/*.{jpeg,jpg,png,svg}'
],
medium: [
'./src/assets/img/*.{jpeg,jpg,png,svg}'
],
large: [
'./src/assets/img/*.{jpeg,jpg,png,svg}'
],
xsmall: ['320'],
xmedium: ['480'],
xlarge: ['920']
};
// INTERCHANGE task will dynamically resize all the images and rename them
// which means you can go tell those non-coder "designers" to get off photoshop
// and go ahead and pickup (s)css.
gulp.task('interchange', function() {
// CUSTOM
// Use this for slider profile images
gulp.src(INTERCHANGE.testimonial)
.pipe(rename({suffix: '@testimonial'}))
.pipe(imageResize({
height: 75,
width: 75,
crop : true,
}))
.pipe(gulp.dest('./dist/assets/img/orbit'))
// Images in your orbit slider are always perfect
gulp.src(INTERCHANGE.orbit)
.pipe(rename({suffix: '@obit'}))
.pipe(imageResize({
height: 750,
width: 2000,
crop : true,
}))
.pipe(gulp.dest('./dist/assets/img/orbit'))
// By default
// NOTES: is there a way to loop through (INTERCHANGE) for each
// or write it differently / more efficiently?
gulp.src(INTERCHANGE.small)
.pipe(rename({suffix: '@small'}))
.pipe(imageResize({ width: INTERCHANGE.xsmall }))
.pipe(gulp.dest('./dist/assets/img/interchange'));
gulp.src(INTERCHANGE.medium)
.pipe(rename({suffix: '@medium'}))
.pipe(imageResize({ width: INTERCHANGE.xmedium }))
.pipe(gulp.dest('./dist/assets/img/interchange'))
gulp.src(INTERCHANGE.large)
.pipe(imageResize({ width: INTERCHANGE.xlarge }))
.pipe(rename({suffix: '@large'}))
.pipe(gulp.dest('./dist/assets/img/interchange'))
});
// gulp.task('deploy', function() {
// return gulp.src('./dist/**/**/*')
// .pipe(ghPages());
// });
// Delete the "dist" folder
// This happens every time a build starts
gulp.task('clean', function(done) {
rimraf('dist', done);
});
// Copy files out of the assets folder
// This task skips over the "img", "js", and "scss" folders, which are parsed separately
gulp.task('copy', function() {
return gulp.src(PATHS.assets)
.pipe(gulp.dest('dist/assets'));
});
// Copy page templates into finished HTML files
gulp.task('pages', function() {
return gulp.src('src/pages/**/*.{html,hbs,handlebars}')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
data: 'src/data/',
helpers: 'src/helpers/'
}))
.pipe(gulp.dest('dist'))
.on('finish', browser.reload);
});
gulp.task('pages:reset', function(done) {
panini.refresh();
gulp.run('pages');
done();
});
gulp.task('styleguide', function(done) {
sherpa('src/styleguide/index.md', {
output: 'dist/styleguide.html',
template: 'src/styleguide/template.html'
}, function() {
browser.reload;
done();
});
});
// Compile Sass into CSS
// In production, the CSS is compressed
gulp.task('sass', function() {
var uncss = $.if(isProduction, $.uncss({
html: ['src/**/*.html'],
ignore: [
new RegExp('.foundation-mq'),
new RegExp('^\.is-.*')
]
}));
var minifycss = $.if(isProduction, $.minifyCss());
return gulp.src('src/assets/scss/app.scss')
.pipe($.sourcemaps.init())
.pipe($.sass({
includePaths: PATHS.sass
})
.on('error', $.sass.logError))
.pipe($.autoprefixer({
browsers: COMPATIBILITY
}))
.pipe(uncss)
.pipe(minifycss)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('dist/assets/css'))
.pipe(browser.reload({ stream: true }));
});
// Combine JavaScript into one file
// In production, the file is minified
gulp.task('javascript', function() {
var uglify = $.if(isProduction, $.uglify()
.on('error', function (e) {
console.log(e);
}));
return gulp.src(PATHS.javascript)
.pipe($.sourcemaps.init())
.pipe($.concat('app.js'))
.pipe(uglify)
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('dist/assets/js'))
.on('finish', browser.reload);
});
// Use Webpack
gulp.task('webpack', function() {
return gulp.src('src/assets/js/home.js')
.pipe(webpack())
.pipe(gulp.dest('dist/'));
});
// Copy images to the "dist" folder
// In production, the images are compressed
gulp.task('images', function() {
var imagemin = $.if(isProduction, $.imagemin({
progressive: true
}));
return gulp.src('src/assets/img/**/*')
.pipe(imagemin)
.pipe(gulp.dest('dist/assets/img'))
.on('finish', browser.reload);
});
// Build the "dist" folder by running all of the above tasks
gulp.task('build', function(done) {
sequence('clean', ['pages', 'sass', 'javascript', 'interchange', 'images', 'copy'], 'styleguide', 'javascript', done);
});
// Start a server with LiveReload to preview the site in
gulp.task('server', ['build'], function() {
browser.init({
server: 'dist', port: PORT
});
});
// Build the site, run the server, and watch for file changes
gulp.task('default', ['build', 'server'], function() {
gulp.watch(PATHS.assets, ['copy']);
gulp.watch(['src/pages/**/*'], ['pages']);
gulp.watch(['src/{layouts,partials,helpers,data}/**/*'], ['pages:reset']);
gulp.watch(['src/assets/scss/**/{*.scss, *.sass}'], ['sass']);
gulp.watch(['src/assets/js/**/*.js'], ['javascript']);
gulp.watch(['src/assets/img/**/*'], ['images','interchange']);
gulp.watch(['src/styleguide/**'], ['styleguide']);
});