forked from HosseinKarami/HosseinKarami.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (75 loc) · 2.6 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
header = require('gulp-header'),
rename = require('gulp-rename'),
cssnano = require('gulp-cssnano'),
cp = require('child_process'),
package = require('./package.json');
var paths = {
scripts: ['src/js/scripts.js', 'src/js/material/*.js']
};
var banner = [
'/*!\n' +
' +-------------------------------------+\n' +
' * <%= package.name %> *\n' +
' * <%= package.title %> *\n' +
' * <%= package.url %> *\n' +
' * @author <%= package.author %> *\n' +
' * @version <%= package.version %> *\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= package.license %> licensed. *\n' +
' +-------------------------------------+\n' +
' */',
'\n'
].join('');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
gulp.task('jekyll-build', function (done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll.bat', ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
gulp.task('css', function () {
return gulp.src('src/scss/style.scss')
.pipe(sass({errLogToConsole: true}))
.pipe(autoprefixer('last 4 version'))
.pipe(gulp.dest('assets/css'))
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(header(banner, { package : package }))
.pipe(gulp.dest('assets/css'))
.pipe(gulp.dest('_site/assets/css'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('js',function(){
gulp.src(paths.scripts)
.pipe(header(banner, { package : package }))
.pipe(concat('scripts.js'))
.pipe(gulp.dest('assets/js'))
.pipe(uglify())
.pipe(header(banner, { package : package }))
.pipe(concat('scripts.min.js'))
.pipe(gulp.dest('assets/js'))
.pipe(gulp.dest('_site/assets/js'))
.pipe(browserSync.reload({stream:true, once: true}));
});
gulp.task('browser-sync', ['css', 'js', 'jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
gulp.task('default', ['css', 'js', 'browser-sync'], function () {
gulp.watch("src/scss/*/*.scss", ['css']);
gulp.watch(paths.scripts, ['js']);
gulp.watch(['*.html', '*/*.html', '_layouts/*.html', '_posts/*', '_includes/*.html'], ['jekyll-rebuild']);
});