forked from darkobodnaruk/docs.status.im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
158 lines (133 loc) · 4.25 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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 browserify = require('browserify')
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 run = require('gulp-run-command').default;
const bamboo = require('./scripts/bamboo-hr');
const genqr = require('./scripts/gen-qr');
const gitBranch = require('./scripts/git-branch');
const updateBuilds = require('./scripts/update-builds');
const getEnv = function () {
return gitBranch() == 'master' ? 'prod' : 'dev'
}
gulp.task('generate', function(cb) {
/* generate html with 'hexo generate' */
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 cb()
}).catch(function(err) { console.log(err);
hexo.exit(err);
return cb(err);
})
})
var config = {
paths: {
src: {
scss: './themes/navy/source/scss/*.scss',
js: [
'./themes/navy/source/js/dev.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
// Input file.
var bundler = watchify(browserify(config.paths.src.js, watchify.args))
// Babel transform
bundler.transform(
babelify.configure({
sourceMapRelative: './themes/navy/source/js/'
})
)
// On updates recompile
bundler.on('update', bundle)
function bundle() {
log('Compiling JS...')
return bundler
.bundle()
.on('error', function(err) {
log(err.message)
browserSync.notify('Browserify Error!')
this.emit('end')
})
.pipe(exorcist('./themes/navy/source/js/main.js.map'))
.pipe(source('main.js'))
.pipe(gulp.dest('./themes/navy/source/js'))
.pipe(browserSync.stream({ once: true }))
}
gulp.task('compress', ['sass'], function() {
gulp.src('./themes/navy/source/js/main.js')
.pipe(minify({
ext: {
min: '.min.js'
},
}))
.pipe(gulp.dest('./public/js/'))
gulp.src('./public/css/main.css')
.pipe(cleanCSS())
.pipe(rename("main.min.css"))
.pipe(gulp.dest('./public/css/'));
});
gulp.task('nightlies', function() {
return updateBuilds('nightlies', 'latest.json')
})
gulp.task('releases', function() {
return updateBuilds('releases', 'release.json')
})
gulp.task('employees', async function() {
return bamboo.saveEmployees('source/_data/employees.yml')
})
gulp.task('genqr', function() {
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('bundle', function() {
return bundle()
})
gulp.task('sass', function() {
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', run(`hexo --config _config.${getEnv()}.yml elasticsearch`))
gulp.task('watch', function() {
gulp.watch(config.paths.src.scss, ['compress'])
});
gulp.task('build', function(cb) {
runSequence('nightlies', 'generate', 'compress', 'genqr', 'bundle', 'watch')
});
gulp.task('exit', function(cb) {
process.exit(0);
});
gulp.task('run', function(cb) {
runSequence('nightlies', 'generate', 'compress', 'genqr', 'bundle', 'exit')
});
gulp.task('default', [])