forked from jenil/bulmaswatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
120 lines (107 loc) · 3.88 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var csso = require('gulp-csso');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var cp = require('child_process');
var del = require('del');
var data = require('gulp-data');
var pluck = require('gulp-pluck');
var frontMatter = require('gulp-front-matter');
const pkg = require('./package.json');
const VERSION = pkg.version;
const HOME = pkg.homepage;
const CDN = 'https://unpkg.com/bulmaswatch';
var changedTheme = '';
gulp.task('clean', function() {
return del(['*/*.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', ['jekyll-build'], function() {
browserSync.reload();
});
gulp.task('serve', ['sass:dev', 'jekyll-build'], function() {
browserSync.init({
server: {
baseDir: '_site'
},
ghostMode: {
clicks: false,
forms: false
},
reloadDelay: 500
});
gulp.watch(['*/*.scss', '!_site/**'], ['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/**'], ['jekyll-rebuild']).on('change', function(event) {
console.log('HTML: File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
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('sass', ['clean'], function() {
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: []
};
del(['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', ['serve']);