forked from darkobodnaruk/docs.status.im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
87 lines (73 loc) · 2.77 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
const log = require('fancy-log')
const gulp = require('gulp')
const webserver = require('gulp-webserver')
const postcss = require('gulp-postcss');
const gulpSass = require('gulp-sass')
const imagemin = require('gulp-imagemin')
const gulpMinify = require('gulp-minify');
const cleanCSS = require('gulp-clean-css');
const rename = require('gulp-rename');
const browserSync = require('browser-sync').create()
const Hexo = require('hexo');
const bamboo = require('./scripts/bamboo-hr');
const scriptGenqr = require('./scripts/gen-qr');
const gitBranch = require('./scripts/git-branch');
const updateBuilds = require('./scripts/update-builds');
// helper for determining env based on branch from which we build
const getEnv = () => {
return gitBranch() == 'master' ? 'prod' : 'dev'
}
// loads hexo configuration based on env we build for
const hexo = async (cmd) => {
var hexo = new Hexo(process.cwd(), {
config: `_config.${getEnv()}.yml`,
watch: false,
})
await hexo.init()
await hexo.call(cmd)
return await hexo.exit()
}
const content = () => hexo('generate')
const index = () => hexo('elasticsearch', {'delete': true})
const nightlies = () => updateBuilds('nightlies', 'latest.json')
const employees = () => bamboo.saveEmployees('source/_data/employees.yml')
const minify = () =>
gulp.src('./themes/navy/source/js/main.js')
.pipe(gulpMinify({ext:{min:'.min.js' }, mangle: true}))
.pipe(gulp.dest('./public/js/'))
const sass = () =>
gulp.src('./themes/navy/source/scss/main.scss')
.on('error', log.error)
.pipe(gulpSass())
.pipe(postcss([require('tailwindcss'), require('autoprefixer')]))
.pipe(gulp.dest('./public/css'))
.pipe(browserSync.stream())
const css = () =>
gulp.src('./public/css/main.css')
.pipe(cleanCSS())
.pipe(rename('main.min.css'))
.pipe(gulp.dest('./public/css/'));
const genqr = async () => {
await scriptGenqr('nightlies', 'APK', './public/img', 'nightly-qr-apk.png')
await scriptGenqr('nightlies', 'DIAWI', './public/img', 'nightly-qr-ios.png')
}
const devel = () => {
gulp.watch('./themes/navy/source/scss/*.scss', sass, css)
gulp.watch('./themes/navy/source/js/main.js', minify)
gulp.watch(['./source/**/*.{md,yml}', './themes/navy/**/*'], content)
}
const server = () =>
gulp.src('./public').pipe(webserver({
port: 8080, livereload: true, open: true
}));
exports.content = content
exports.sass = sass
exports.css = gulp.series(sass, css)
exports.genqr = genqr
exports.server = server
exports.index = index
exports.employees = employees
exports.nightlies = nightlies
exports.devel = gulp.parallel(server, devel)
exports.build = gulp.series(nightlies, gulp.parallel(genqr, content, exports.css, minify))
exports.default = exports.build