-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
gulpfile.js
125 lines (111 loc) · 4.12 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
import gulp from 'gulp'
import nodeSass from 'node-sass'
import gulpSass from 'gulp-sass';
const sass = gulpSass(nodeSass);
import sourcemaps from 'gulp-sourcemaps'
import autoprefixer from 'gulp-autoprefixer'
import csso from 'gulp-csso'
import rename from 'gulp-rename'
import browserSyncSrc from 'browser-sync'
const browserSync = browserSyncSrc.create()
import cp from 'child_process'
import {deleteSync, deleteAsync} from 'del';
import data from 'gulp-data'
import pluck from 'gulp-pluck'
import frontMatter from 'gulp-front-matter'
import pkg from './package.json' assert { type: "json" }
const VERSION = pkg.version;
const HOME = pkg.homepage;
const CDN = 'https://unpkg.com/bulmaswatch';
var changedTheme = '';
gulp.task('clean', async function() {
await deleteAsync(['*/*.css', '*/*.css.map']);
});
gulp.task('jekyll-build', function(done) {
browserSync.notify('Jekyll build');
cp.exec('bundle exec jekyll build --config _config.yml,_config.local.yml', function(err, stdout, stderr) {
console.log(stdout);
}).on('exit', function(code) {
done(code === 0 ? null : 'ERROR: Jekyll process exited with code: ' + code);
});
});
gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function() {
browserSync.reload();
}));
gulp.task('sass:dev', function() {
console.log('Building', changedTheme);
return gulp.src(changedTheme ? `${changedTheme}/*.scss` : '*/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: 'node_modules/bulma'
}).on('error', sass.logError))
.pipe(rename({
suffix: '.min'
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(changedTheme ? `_site/${changedTheme}` : '_site/'))
.pipe(browserSync.reload({
stream: true
}))
.pipe(gulp.dest(changedTheme ? `_site/${changedTheme}` : '.'));
});
gulp.task('serve', gulp.parallel('sass:dev', 'jekyll-build', function() {
browserSync.init({
server: {
baseDir: '_site'
},
ghostMode: {
clicks: false,
forms: false
},
reloadDelay: 500
});
gulp.watch(['*/*.scss', '!_site/**'], gulp.series('sass:dev')).on('change', function(event) {
console.log('SCSS: File ' + event.path + ' was ' + event.type + ', running tasks...');
changedTheme = event.path.split('/')[event.path.split('/').length - 2]
});
gulp.watch(['**/*.{html,md}', '!_site/**'], gulp.series('jekyll-rebuild')).on('change', function(event) {
console.log('HTML: File ' + event.path + ' was ' + event.type + ', running tasks...');
});
}));
gulp.task('sass', gulp.series('clean', function compile() {
return gulp.src('*/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: 'node_modules/bulma'
}).on('error', sass.logError))
.pipe(rename({
suffix: '.min'
}))
.pipe(autoprefixer())
.pipe(csso())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
}));
gulp.task('api', function() {
var API = {
version: VERSION,
themes: []
};
deleteSync(['api/*']);
return gulp.src('./_themes/*.md')
.pipe(frontMatter({
property: 'meta'
}))
.pipe(data(function(file) {
delete file.meta.order;
file.meta.preview = HOME + '/' + file.meta.name.toLowerCase() + '/';
file.meta.thumb = HOME + '/thumb/?' + file.meta.name.toLowerCase();
file.meta.css = CDN + '@' + VERSION + '/' + file.meta.name.toLowerCase() + '/bulmaswatch.min.css';
file.meta.scss = CDN + '@' + VERSION + '/' + file.meta.name.toLowerCase() + '/bulmaswatch.scss';
file.meta.scssVariables = CDN + '@' + VERSION + '/' + file.meta.name.toLowerCase() + '/_variables.scss';
}))
.pipe(pluck('meta', 'themes.json'))
.pipe(data(function(file) {
API.themes = file.meta;
file.contents = new Buffer(JSON.stringify(API));
}))
.pipe(gulp.dest('api'));
});
gulp.task('default', gulp.series('serve'));
gulp.task('build', gulp.parallel('sass', 'api'));