forked from darkobodnaruk/docs.status.im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (101 loc) · 3.28 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
const gulp = require('gulp')
const log = require('fancy-log')
const source = require('vinyl-source-stream')
const babelify = require('babelify')
const watchify = require('watchify')
const exorcist = require('exorcist')
const browserSync = require('browser-sync').create()
const sass = require('gulp-sass')
const imagemin = require('gulp-imagemin')
const Hexo = require('hexo');
const runSequence = require('run-sequence');
const minify = require('gulp-minify');
const cleanCSS = require('gulp-clean-css');
const rename = require("gulp-rename");
const bamboo = require('./scripts/bamboo-hr');
const genqr = require('./scripts/gen-qr');
const gitBranch = require('./scripts/git-branch');
const updateBuilds = require('./scripts/update-builds');
var config = {
paths: {
src: {
scss: './themes/navy/source/scss/*.scss',
js: [ './themes/navy/source/js/main.js', ],
},
dist: {
css: './public/css',
js: './public/js'
}
}
}
// Watchify args contains necessary cache options to achieve fast incremental bundles.
// See watchify readme for details. Adding debug true for source-map generation.
watchify.args.debug = true
// 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 (cmdName, args={}) => {
var h = new Hexo(process.cwd(), {
config: `_config.${getEnv()}.yml`,
watch: false,
})
try {
await h.init()
await h.call(cmdName, args)
await h.exit()
} catch(err) {
h.exit(err)
throw err
}
}
gulp.task('generate', async (cb) => {
await hexo('generate') /* generate html with 'hexo generate' */
})
gulp.task('minify', () => {
return gulp.src('./themes/navy/source/js/main.js')
.pipe(minify({ext:{min:'.min.js' }, mangle: true}))
.pipe(gulp.dest('./public/js/'))
});
gulp.task('compress', ['sass'], () => {
return gulp.src('./public/css/main.css')
.pipe(cleanCSS())
.pipe(rename("main.min.css"))
.pipe(gulp.dest('./public/css/'));
});
gulp.task('nightlies', () => {
return updateBuilds('nightlies', 'latest.json')
})
gulp.task('releases', () => {
return updateBuilds('releases', 'release.json')
})
gulp.task('employees', async () => {
return bamboo.saveEmployees('source/_data/employees.yml')
})
gulp.task('genqr', () => {
genqr('nightlies', 'APK', 'public/nightly/img', 'qr-apk.png')
genqr('nightlies', 'DIAWI', 'public/nightly/img', 'qr-ios.png')
genqr('releases', 'APK', 'public/stable/img', 'qr-apk.png')
genqr('releases', 'DIAWI', 'public/stable/img', 'qr-ios.png')
})
gulp.task('sass', () => {
return gulp.src("./themes/navy/source/scss/main.scss")
.pipe(sass())
.on('error', log)
.pipe(gulp.dest(config.paths.dist.css))
.pipe(browserSync.stream())
})
gulp.task('index', async () => {
await hexo('elasticsearch', {'delete': true})
})
gulp.task('watch', async () => {
gulp.watch(config.paths.src.scss, ['compress'])
});
gulp.task('build', (cb) => {
runSequence('generate', 'genqr', 'compress', 'minify', 'exit')
});
gulp.task('exit', (cb) => {
process.exit(0);
});
gulp.task('default', [])