-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (81 loc) · 2.85 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
'use strict';
// Load plugins
var gulp = require('gulp');
var gulpAutoprefixer = require('gulp-autoprefixer');
var gulpConcat = require('gulp-concat');
var gulpCssMin = require('gulp-cssmin');
var gulpDeleteLines = require('gulp-delete-lines');
var gulpRename = require('gulp-rename');
var gulpSass = require('gulp-sass');
var nodeSass = require('node-sass');
var rimraf = require('rimraf');
gulpSass.compiler = nodeSass;
const themeName = 'tekstowo-full-dark';
const mainCssFileName = 'site';
const mainSassFileName = 'site';
const metadataFileName = 'UserStyleMetadata.txt';
const userStyleFileName = themeName + '.user.styl';
var paths = {
nodeModules: './node_modules/',
source: './src/'
};
paths.sassDir = paths.source + 'sass/';
paths.distDir = './dist/';
paths.cssDir = paths.distDir + 'css/';
paths.sassFiles = paths.sassDir + '**/*.scss';
paths.mainCss = paths.cssDir + mainCssFileName + '.css';
paths.mainMinCss = paths.cssDir + mainCssFileName + '.min.css';
paths.mainSass = paths.sassDir + mainSassFileName + '.scss';
paths.metadataFile = paths.source + metadataFileName;
paths.userStyle = paths.cssDir + userStyleFileName;
/* ### Clean ### */
// Clean output files
gulp.task('clean:dist', done => rimraf(paths.distDir, done));
gulp.task('clean', gulp.series(['clean:dist']));
/* ### Compile ### */
// Compile sass files to css
gulp.task('compile:sass', () => {
return gulp.src(paths.mainSass)
.pipe(gulpSass({ outputStyle: 'expanded' }).on('error', gulpSass.logError))
.pipe(gulpAutoprefixer())
.pipe(gulpDeleteLines({
'filters': [
'\@charset \"UTF\-8\"\;'
]
}))
.pipe(gulp.dest(paths.cssDir));
});
// Global compile task
gulp.task('compile', gulp.series('compile:sass'));
/* ### Minify ### */
// Minify CSS files
gulp.task("minify:css", () => {
return gulp.src(paths.mainCss)
.pipe(gulpCssMin())
.pipe(gulpRename({ suffix: '.min' }))
.pipe(gulp.dest(paths.cssDir));
});
// Global minify task
gulp.task('minify', gulp.series(['minify:css']));
/* ### Build ### */
// Build user styl file from metadata & compiled CSS
gulp.task("build:userStyle", () => {
return gulp.src([paths.metadataFile, paths.mainCss])
.pipe(gulpConcat(userStyleFileName))
.pipe(gulp.dest(paths.distDir));
});
// Global buidl task
gulp.task('build', gulp.series(['build:userStyle']));
/* ### Watch ### */
// Watch sass files
gulp.task('watch:sass', () => {
return gulp.watch(paths.sassFiles, gulp.series(['compile', 'minify', 'build']));
});
// Watch user style metadata file
gulp.task('watch:metadata', () => {
return gulp.watch(paths.metadataFile, gulp.series('build'));
});
//// Global watch
gulp.task('watch', gulp.parallel(['watch:sass', 'watch:metadata']));
/* ### Default ### */
gulp.task('default', gulp.series(['compile', 'minify', 'build']));