-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (90 loc) · 2.73 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
/* gulpfile for wintersmith */
// load Gulp
const gulp = require('gulp');
const gutil = require('gulp-util');
// plugins
const sass = require('gulp-sass');
const cleanCSS = require('gulp-clean-css');
const runWintersmith = require('run-wintersmith');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('autoprefixer');
const ghPages = require('gulp-gh-pages');
const extend = require('gulp-extend');
// other
const del = require('del');
const bourbon = require('bourbon');
// Directories
const dirs = {
build: 'dist',
contents: 'contents',
templates: 'templates'
};
// Helper tasks
// cleans the build dir
gulp.task('clean', () => {
return del([
dirs.build, dirs.content + 'css/main.css'
]);
});
// compile sass files
gulp.task('sass', () => {
gulp.src(dirs.contents + '/sass/**/*.scss')
.pipe(sass({includePaths: bourbon.includePaths}).on('error', sass.logError))
.pipe(gulp.dest(dirs.contents + '/css'));
});
// autoprefix css attributes
gulp.task('autoprefixer', function () {
return gulp.src(dirs.content + '/css/main.css')
.pipe(sourcemaps.init())
.pipe(postcss([ autoprefixer() ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dirs.contents + '/css'));
});
// minify CSS files
gulp.task('minify-css', () => {
return gulp.src(dirs.contents + '/css/main.css')
.pipe(cleanCSS())
.pipe(gulp.dest(dirs.contents + '/css'));
});
gulp.task('create-production-config', function() {
gutil.log('Creating production config');
gulp.src(['./config.json', './config.production.base.json']).pipe(extend('config.production.json', true)).pipe(gulp.dest('./'));
gutil.log('Setting production config for Wintersmith\'s use');
runWintersmith.settings.configFile = 'config.production.json';
});
// Main Tasks
// Build task
gulp.task('build', [
'clean', 'sass', 'autoprefixer', 'minify-css', 'create-production-config'
], function(cb) {
// Tell Wintersmith to build
runWintersmith.build(function() {
// Log on successful build
gutil.log('Wintersmith has finished building!');
// Tell gulp task has finished
cb();
});
});
// Preview task
gulp.task('preview', ['sass'], function() {
// Tell Wintersmith to run in preview mode
runWintersmith.preview();
});
// deploy task
gulp.task('deploy', ['build'], function() {
return gulp.src([
'./' + dirs.build + '/**/*',
'./CNAME'
]).pipe(ghPages());
});
// Watch task
gulp.task('watch', ['preview'], function() {
function reportChange(e) {
gutil.log(gutil.template('File <%= file %> was <%= type %>, rebuilding...', {
file: gutil.colors.cyan(e.path),
type: e.type
}));
}
gulp.watch(dirs.contents + '/sass/**/*.scss', ['sass']).on('change', reportChange);
});