-
Notifications
You must be signed in to change notification settings - Fork 23
/
gulpfile.js
149 lines (130 loc) · 4.68 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const gulp = require('gulp');
const internalIp = require('internal-ip');
const package = require('./package.json');
const path = require('path');
const shell = require('gulp-shell');
/**
* Template for banner to add to file headers
*/
var banner = {
main:
'/*!' +
' <%= package.name %> v<%= package.version %>' +
' | (c) ' + new Date().getFullYear() + ' <%= package.author.name %>' +
' | <%= package.license %> License' +
' | <%= package.homepage %>' +
' */\n'
};
/**
* ----------------------------------------
* STYLESHEETS TASKS
* ----------------------------------------
*/
gulp.task('styles:build', function() {
const autoprefixer = require('autoprefixer');
const cleanDir = require('gulp-clean-dir');
const concat = require('gulp-concat');
const fs = require('fs');
const header = require('gulp-header');
const nop = require('gulp-nop');
const parsePath = require('parse-filepath');
const postcss = require('gulp-postcss');
const rename = require("gulp-rename");
const sass = require('gulp-sass');
distPath = parsePath(package.style);
if (fs.existsSync(path.resolve(__dirname, 'src/sass/index.sass'))) {
return gulp.src(['node_modules/bulma/sass/utilities/_all.sass', 'src/sass/index.sass'])
.pipe(concat('app.sass'))
.pipe(sass({
loadPath: [path.resolve(__dirname, 'src/sass')],
includePaths: ['node_modules', 'node_modules/bulma/sass/utilities/'],
outputStyle: "expanded",
sourceComments: true
}).on('error', sass.logError))
.pipe(postcss([
autoprefixer({
cascade: true,
remove: true
})
]))
.pipe(header(banner.main, {package: package}))
.pipe(rename(distPath.basename.replace('.min', '')))
.pipe(cleanDir(path.resolve(__dirname, distPath.dirname)))
.pipe(gulp.dest(path.resolve(__dirname, distPath.dirname)));
} else {
return gulp.src('.').pipe(nop());
}
});
gulp.task('styles:minify', function() {
const cleancss = require('gulp-cleancss');
const cssnano = require('cssnano');
const header = require('gulp-header');
const parsePath = require('parse-filepath');
const postcss = require('gulp-postcss');
const rename = require("gulp-rename");
distPath = parsePath(package.style);
return gulp.src([path.resolve(__dirname, distPath.dirname + '/*.css'), '!' + path.resolve(__dirname, distPath.dirname + '/*.min.css')])
.pipe(cleancss())
.pipe(postcss([
cssnano({
discardComments: {
removeAll: true
}
})
]))
.pipe(header(banner.main, {package: package}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(path.resolve(__dirname, distPath.dirname)));
});
gulp.task('styles:copy', gulp.series('styles:minify', function() {
const parsePath = require('parse-filepath');
distPath = parsePath(package.style);
return gulp.src(path.resolve(__dirname, distPath.dirname + '/*.css'))
.pipe(gulp.dest(path.resolve(__dirname, 'src/docs/static/css')));
}));
/**
* ----------------------------------------
* ASSETS TASKS
* ----------------------------------------
*/
gulp.task('images:svg:minify', function() {
const svgmin = require('gulp-svgmin');
return gulp.src(path.resolve(__dirname, 'dist/images/**/*.svg'))
.pipe(svgmin())
.pipe(gulp.dest(path.resolve(__dirname, 'dist/images')));
});
/**
* ----------------------------------------
* BUILD TASKS
* ----------------------------------------
*/
gulp.task('build:styles', gulp.series('styles:build', 'styles:minify', 'styles:copy'), done => {
done();
});
gulp.task('build', gulp.series('build:styles'), done => {
done();
});
gulp.task('optimize', gulp.series('styles:minify', 'images:svg:minify'), done => {
done();
});
gulp.task('default', gulp.series('build', 'optimize'), done => {
done();
});
/**
* ----------------------------------------
* DOC TASKS
* ----------------------------------------
*/
gulp.task('doc:build', gulp.series(shell.task(['node_modules/.bin/hugo --source src/docs --destination ../../docs --cleanDestinationDir'])), done => {
done();
});
gulp.task('doc:serve', gulp.parallel(shell.task([`node_modules/.bin/hugo server -D --bind ${internalIp.v4.sync()} --baseURL ${internalIp.v4.sync()} --source src/docs --watch`]), function() {
gulp.watch(path.resolve(__dirname, 'src/sass/**/*.sass'), gulp.series('build:styles'));
}), done => {
done();
});
gulp.task('doc', gulp.series(shell.task(['node_modules/.bin/hugo server --source src/docs'])), done => {
done();
});