forked from jbossorg/bootstrap-community
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
108 lines (96 loc) · 3.29 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
'use strict';
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var jsLibs = [
'./node_modules/scrollpos-styler/scrollPosStyler.js',
'./node_modules/jquery/dist/jquery.slim.min.js',
'./node_modules/tether/dist/js/tether.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/anchor-js/anchor.js',
'./themes/dracoio/js/**/*.js'
];
function sriTransformer(tHash) {
var res = {};
for (var key in tHash){
res[key.substr(key.lastIndexOf('/') + 1)] = tHash[key];
}
return res;
}
gulp.task('css', function () {
return gulp.src('./themes/dracoio/scss/**/*.scss')
.pipe(plugins.sass())
.pipe(plugins.postcss())
.pipe(gulp.dest('./themes/dracoio/static/css'));
});
gulp.task('css:watch', gulp.series('css', function () {
gulp.watch('./themes/dracoio/scss/**/*.scss', gulp.series('css'));
}));
gulp.task('js', function () {
return gulp.src(jsLibs)
.pipe(plugins.concat('dracoio.js'))
.pipe(gulp.dest('./themes/dracoio/static/js'));
});
gulp.task('js:watch', gulp.series('js', function () {
gulp.watch(jsLibs, gulp.series('js'));
}));
gulp.task('fonts', function() {
return gulp.src('./node_modules/font-awesome/fonts/*')
.pipe(gulp.dest('./themes/dracoio/static/fonts'))
});
gulp.task('fonts:watch', gulp.series('fonts', function () {
gulp.watch(['./node_modules/font-awesome/fonts/*'], gulp.series('fonts'));
}));
gulp.task('watch', gulp.parallel(gulp.series('fonts', 'fonts:watch'), gulp.series('css', 'css:watch'), gulp.series('js', 'js:watch')));
gulp.task('hugo:serve', function (cb) {
var exec = require('child_process').exec;
exec('hugo serve', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('hugo', function (cb) {
var exec = require('child_process').exec;
var githubProject = process.env['CIRCLE_PROJECT_USERNAME'];
var baseURLArg = '';
if (githubProject && githubProject !== "teiid" && process.env['CIRCLE_PROJECT_REPONAME']) {
baseURLArg = ' --baseURL https://' + githubProject + '.github.io/' + process.env['CIRCLE_PROJECT_REPONAME'] + '/';
}
exec('hugo' + baseURLArg, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('optimize-html', function() {
return gulp.src(['./public/**/*.html'])
.pipe(plugins.cacheBust({
type: 'timestamp'
}))
.pipe(plugins.htmlmin({
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true,
minifyURLs: true,
removeComments: true
}))
.pipe(gulp.dest('./public'));
});
gulp.task('optimize-css', function() {
return gulp.src(['./public/**/*.css'])
.pipe(plugins.uncss({
html: ['./public/**/*.html'],
ignore: [/^\.sps.*/, /\.collapse\.show$/, /\.collapsing$/, '.sidenav.active', '.anchorjs-icon']
}))
.pipe(gulp.dest('./public'));
});
gulp.task('optimize-js', function() {
return gulp.src(['./public/**/*.js'])
.pipe(plugins.uglify())
.pipe(gulp.dest('./public'));
});
gulp.task('optimize', gulp.series('optimize-html', 'optimize-css', 'optimize-js'));
gulp.task('serve', gulp.parallel('watch', 'hugo:serve'));
gulp.task('build', gulp.series('fonts', 'css', 'js', 'hugo', 'optimize'));
gulp.task('default', gulp.series('serve'));