-
Notifications
You must be signed in to change notification settings - Fork 217
/
gulpfile.js
66 lines (52 loc) · 1.72 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
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify-es').default;
gulp.task('build', function() {
var isDevelopment = process.env.NODE_ENV === 'develop',
browserifyOpts = {
debug: isDevelopment,
standalone: 'QB',
ignoreMissing: true
};
return browserify('./src/qbMain.js', browserifyOpts)
.bundle()
.on('error', function(error) {
throw new Error(error);
})
.pipe(source('quickblox.js'))
.pipe(gulp.dest('./'))
});
gulp.task('minify', function() {
return gulp.src(['./quickblox.js'])
.pipe(uglify())
.on('error', function (err) { console.log('ERROR', err) })
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./'));
});
gulp.task('generate-build_version', function(done) {
var fs = require('fs');
var configPath = './src/qbConfig.js';
function incBuildNumber(foundedString, p1, buildNumber, p2) {
var oldBuildNumber = +buildNumber;
return p1 + (oldBuildNumber + 1) + p2;
}
fs.readFile(configPath, 'utf8', function (error, config) {
if (error) {
throw new Error(error);
}
var result = config.replace(/(buildNumber:\s\')(\d{4})(')/g, incBuildNumber);
fs.writeFile(configPath, result, 'utf8', function (error) {
if (error) {
throw new Error(error);
}
done();
});
});
});
gulp.task('watch', function() {
gulp.watch(['./src/**/*.js'], gulp.series('build'));
});
gulp.task('default', gulp.series('build', 'watch'));