forked from ringcentral/ringcentral-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
89 lines (62 loc) · 2.17 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
(function() {
/** @type {gulp.Gulp} */
var gulp = require('gulp'),
gutil = require('gulp-util'),
rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
fs = require('fs'),
exec = require('child_process').exec,
sourcemapsDebug = true;
function execute(cmd){
return function(cmd, cb) {
exec(cmd, {cwd: __dirname}, function(e, stdout, stderr) {
if (e === null) {
gutil.log(stdout);
return cb();
}
gutil.log(gutil.colors.red('External Command Error'));
gutil.log(stdout);
gutil.log(e.stack || e);
gutil.log(stderr);
cb(e);
});
}.bind(null, cmd)
}
gulp.task('bower', execute('npm run bower'));
gulp.task('webpack', ['bower'], execute('npm run webpack'));
/**
* Minifies build and bundle
*/
gulp.task('uglify', ['webpack'], function() {
return gulp
.src(['./build/ringcentral.js', './build/ringcentral-bundle.js'])
.pipe(sourcemaps.init({loadMaps: true, debug: sourcemapsDebug}))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.', {debug: sourcemapsDebug}))
.pipe(gulp.dest('./build'));
});
/**
* Propagates version number to package.json and bower.json
*/
gulp.task('version', ['webpack'], function(cb) {
var pkg = require('./package.json'),
bower = require('./bower.json'),
version = require('./build/ringcentral').version;
pkg.version = version;
bower.version = version;
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
fs.writeFileSync('./bower.json', JSON.stringify(bower, null, 2));
gutil.log('Current version is', gutil.colors.magenta(version));
cb();
});
/**
* Quick Task
*/
gulp.task('quick', ['webpack', 'version']);
/**
* Default Task
*/
gulp.task('default', ['quick', 'uglify']);
})();