-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (104 loc) · 3.25 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
var del = require('del'),
gulp = require('gulp'),
sass = require('gulp-sass'),
data = require('gulp-data'),
shell = require('gulp-shell'),
uglify = require('gulp-uglify'),
ghPages = require('gulp-gh-pages'),
imagemin = require('gulp-imagemin'),
sourcemaps = require('gulp-sourcemaps'),
browserSync = require('browser-sync'),
runSequence = require('run-sequence').use(gulp),
nunjucksRender = require('gulp-nunjucks-render');
// Clean Dist
gulp.task('clean', function () {
return del(['public']);
});
// Browser Sync
gulp.task('browserSync', function () {
browserSync({
server: {
baseDir: 'public'
}
});
});
// Sass
gulp.task('sass', function () {
// Gets all files ending with .scss in source/sass
return gulp.src('source/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' })).on('error', sass.logError)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('public/styles'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('vendor', function () {
return gulp.src('source/static/vendor/**/*')
.pipe(gulp.dest('public/vendor'));
});
gulp.task('image', function () {
return gulp.src('source/static/images/**/*')
.pipe(imagemin())
.pipe(gulp.dest('public/images'));
});
gulp.task('js', function () {
return gulp.src('source/static/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('public'));
});
gulp.task('cname', function () {
return gulp.src('source/templates/CNAME')
.pipe(gulp.dest('public'));
});
// Nunjucks
// gulp.task('nunjucks', function () {
// nunjucksRender.nunjucks.configure(['source/templates/']);
// // Gets .html and .nunjucks files in pages
// return gulp.src('source/templates/**/[^_]*.html')
// // Renders template with nunjucks
// .pipe(nunjucksRender({ path: 'source/templates' }))
// // output files in app folder
// .pipe(gulp.dest('public'))
// .pipe(browserSync.reload({ stream: true }));
// });
gulp.task('nunjucks', function() {
return gulp.src('source/templates/**/*.+(html|nunjucks)')
// Adding data to Nunjucks
.pipe(data(function() {
return require('./source/data/data.json')
}))
.pipe(nunjucksRender({
path: ['source/templates']
}))
.pipe(gulp.dest('public'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('push-gh-master', shell.task(['git push origin master']));
gulp.task('push-gh-pages', function () {
return gulp.src('public/**/*')
.pipe(ghPages({ force: true }));
});
gulp.task('deploy', function (callback) {
runSequence(
'clean',
['sass', 'js', 'image', 'nunjucks', 'vendor', 'cname'],
'push-gh-master',
'push-gh-pages',
callback
);
});
gulp.task('watch', function () {
gulp.watch('source/static/**/*.js', ['js']);
gulp.watch('source/sass/**/*.scss', ['sass']);
gulp.watch('source/templates/**/*.html', ['nunjucks']);
gulp.watch('source/static/vendor/**/*.js', ['vendor']);
gulp.watch('source/static/vendorimages/**/*', ['images']);
});
gulp.task('default', function (callback) {
runSequence(
'clean',
['sass', 'js', 'image', 'nunjucks', 'vendor'],
['browserSync', 'watch'],
callback
);
});