-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·123 lines (103 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
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
#!/usr/bin/env nodejs
'use strict';
const gulp = require('gulp');
const spawn = require('child_process').spawnSync;
const through = require('through2');
const rimraf = require('rimraf').sync;
const mkdirp = require('mkdirp').sync;
const runSequence = require('run-sequence');
const cmdPipe = function (cmd, args) {
return through.obj(function (file, enc, cb) {
let child = spawn(cmd, args, { input: file.contents });
file.contents = child.stdout;
this.push(file);
cb(child.error);
});
}
const minify = function (type) {
return cmdPipe('minify', ['--type', type]);
};
const scss = function() {
return through.obj(function (file, enc, cb) {
let child = spawn(
'sassc',
[
'-m', '-t', 'compressed', file.path,
('static/assets/css/' + file.relative.replace('scss', 'css'))
]
);
cb(child.error);
});
};
const hugo = function() {
spawn('hugo', [
'--cleanDestinationDir',
'--gc',
'--ignoreCache',
'--noChmod',
'--noTimes'
]);
};
gulp.task('clean', function () {
[
'static/assets/css',
'static/assets/js',
'static/assets/fonts',
'static/assets/images'
].forEach(function (dir) {
rimraf(dir + '/**');
mkdirp(dir);
});
rimraf('public');
});
gulp.task('css', function () {
return gulp.src('src/css/**/*.css')
.pipe(minify('css'))
.pipe(gulp.dest('static/assets/css'));
});
gulp.task('scss', function () {
return gulp.src(['src/scss/**/*.scss', '!src/scss/**/_*.scss'])
.pipe(scss());
});
gulp.task('js', function () {
return gulp.src('src/js/**/*.js')
.pipe(minify('js'))
.pipe(gulp.dest('static/assets/js'));
});
gulp.task('fonts', function () {
return gulp.src([
'src/fonts/**/*.otf',
'src/fonts/**/*.ttf'
]).pipe(gulp.dest('static/assets/fonts'));
});
gulp.task('images', function () {
return gulp.src([
'src/images/**/*.jpg',
'src/images/**/*.png',
'src/images/**/*.svg'
]).pipe(gulp.dest('static/assets/images'));
});
gulp.task('favicon', function () {
return gulp.src('src/favicon.ico').pipe(gulp.dest('static'));
});
gulp.task('hugo', function () {
hugo();
});
gulp.task('html', function () {
return gulp.src('public/**/*.html')
.pipe(minify('html'))
.pipe(gulp.dest('public'));
});
gulp.task('xml', function () {
return gulp.src('public/**/*.xml')
.pipe(minify('xml'))
.pipe(gulp.dest('public'));
});
gulp.task('default', function() {
runSequence(
'clean',
['css', 'scss', 'js', 'fonts', 'images', 'favicon'],
'hugo',
['html', 'xml']
);
});