-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
115 lines (98 loc) · 3.11 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
var gulp = require('gulp');
var gulpIf = require('gulp-if');
var autoprefixer = require('autoprefixer');
var babel = require('gulp-babel');
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var eslint = require('gulp-eslint');
var mergeStream = require('merge-stream');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var postcss = require('gulp-postcss');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var exec = require('child_process').exec;
var onError = function(err) {
notify.onError({
title: "Error",
message: "<%= error %>",
})(err);
this.emit('end');
};
var plumberOptions = {
errorHandler: onError,
};
gulp.task('css', function() {
var sassOptions = {
includePaths: [
'node_modules/mcgriddle/_sass/mcgriddle',
'node_modules/mq-sass/stylesheets',
]
};
var postCSSOptions = require('./config.postcss.json');
var postCSSProcessors = [
autoprefixer(postCSSOptions.autoprefixer),
];
return gulp.src([
'themes/jonsuh-v8/source/assets/_sass/**/*.scss',
'themes/jonsuh-v8/source/assets/css/**/*.css'
])
.pipe(plumber(plumberOptions))
.pipe(sourcemaps.init())
.pipe(sass(sassOptions))
.pipe(postcss(postCSSProcessors))
.pipe(sourcemaps.write())
.pipe(gulp.dest('public/assets/css'));
});
function eslintFixed(file) {
return file.eslint != null && file.eslint.fixed;
}
gulp.task('eslint', function() {
return gulp.src('themes/jonsuh-v8/source/assets/_js/**/*.js')
.pipe(eslint({
fix: true
}))
.pipe(eslint.format())
.pipe(gulpIf(eslintFixed, gulp.dest('themes/jonsuh-v8/source/assets/_js')))
.pipe(eslint.failAfterError());
});
gulp.task('js-vendor', function() {
var chartjs = gulp.src([
'node_modules/chart.js/dist/Chart.js',
])
.pipe(concat('chart.js'))
.pipe(gulp.dest('public/assets/js'));
var flickity = gulp.src(['node_modules/flickity/dist/flickity.pkgd.js'])
.pipe(concat('flickity.js'))
.pipe(gulp.dest('public/assets/js'));
return mergeStream(chartjs, flickity);
});
gulp.task('js', ['js-vendor', 'eslint'], function() {
return gulp.src([
'node_modules/rellax/rellax.js',
'themes/jonsuh-v8/source/assets/_js/utility.js',
'themes/jonsuh-v8/source/assets/_js/share.js',
'themes/jonsuh-v8/source/assets/_js/app.js',
])
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('app.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('public/assets/js'));
});
gulp.task('watch', function() {
var browserSyncConfig = require('./bs-config.js');
browserSync.init(browserSyncConfig);
exec('hexo generate --watch', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
gulp.watch([
'themes/jonsuh-v8/source/assets/_sass/**/*.scss',
'themes/jonsuh-v8/source/assets/css/**/*.css'
], ['css']);
gulp.watch('themes/jonsuh-v8/source/assets/_js/**/*.js', ['js']);
});
gulp.task('build', ['css', 'js']);
gulp.task('default', ['build', 'watch']);