forked from status-im/nimbus-site
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
75 lines (64 loc) · 2.09 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
const log = require('fancy-log')
const gulp = require('gulp')
const gulpSass = require('gulp-sass')(require('sass'))
const rename = require("gulp-rename")
const cleanCSS = require('gulp-clean-css')
const rollup = require('gulp-better-rollup')
const webserver = require('gulp-webserver')
const terser = require('rollup-plugin-terser').terser
const browserSync = require('browser-sync').create()
const Hexo = require('hexo')
const runSequence = require('run-sequence')
const gitBranch = require('./scripts/git-branch')
const getEnv = function () {
return gitBranch() == 'master' ? 'prod' : 'dev'
}
const html = (done) => {
var hexo = new Hexo(process.cwd(), {
config: `_config.${getEnv()}.yml`,
watch: false,
})
hexo.init().then(function() {
return hexo.call('generate')
}).then(function() {
return hexo.exit()
}).then(function() {
return done()
}).catch(function(err) {
console.log(err)
hexo.exit(err)
return done(err)
})
}
const js = () =>
gulp.src('js/main.js')
.on('error', log.error)
.pipe(rollup({ plugins: [terser()] }, 'iife'))
.pipe(rename("main.min.js"))
.pipe(gulp.dest('public/js'))
const sass = () =>
gulp.src("./themes/navy/source/scss/main.scss")
.on('error', log.error)
.pipe(gulpSass())
.pipe(gulp.dest('./public/css'))
.pipe(browserSync.stream())
const css = () =>
gulp.src('./public/css/main.css')
.on('error', log.error)
.pipe(cleanCSS())
.pipe(rename("main.min.css"))
.pipe(gulp.dest('./public/css/'))
const devel = () => {
gulp.watch('./js/*.js', js)
gulp.watch(['./source/**/*.{md,yml}', './themes/navy/**/*'], html)
gulp.watch('./themes/navy/source/scss/*.scss', sass, css)
}
const server = () =>
gulp.src('./public').pipe(webserver({livereload: true, open: true}));
exports.html = html
exports.js = js
exports.sass = sass
exports.css = gulp.series(sass, css)
exports.devel = gulp.parallel(server, devel)
exports.build = gulp.parallel(html, js, exports.css)
exports.default = exports.build