forked from ringcentral/ringcentral-js-client
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
132 lines (98 loc) · 3.67 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
(function() {
/** @type {gulp.Gulp} */
var gulp = require('gulp'),
gutil = require('gulp-util'),
sourcemaps = require('gulp-sourcemaps'),
path = require('path'),
sourcemapsDebug = false,
webpackConfigure = {
useMemoryFs: true,
progress: false
},
webpackFormat = {
version: true,
timings: true
},
webpackFailAfter = {
errors: true,
warnings: true
};
/**
* Compiles TypeScript modules into a Webpack bundle (including external dependencies CryptoJS, Promise and PUBNUB)
* TODO TypeScript cache
* TODO Export definitions
*/
gulp.task('webpack', [], function() {
var webpack = require('gulp-webpack-build');
return gulp.src('./webpack.config.js', {base: path.resolve('./build')})
.pipe(webpack.init(webpackConfigure))
.pipe(webpack.run())
.pipe(webpack.format(webpackFormat))
.pipe(webpack.failAfter(webpackFailAfter))
.pipe(gulp.dest('./build'));
});
/**
* Replaces Webpack stuff in source map files
*/
gulp.task('sourcemap', ['webpack'], function() {
var replace = require('gulp-replace');
return gulp.src(['./build/ringcentral-client.js.map'])
.pipe(replace(/webpack:\/\/\//g, ''))
.pipe(replace(/(\.\.\/src\/)/g, '.$1'))
.pipe(gulp.dest('./build'));
});
/**
* Minifies build and bundle
*/
gulp.task('uglify', ['sourcemap'], function() {
var uglify = require('gulp-uglify'),
rename = require('gulp-rename');
return gulp.src(['./build/ringcentral-client.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 fs = require('fs'),
pkg = require('./package.json'),
bower = require('./bower.json'),
version = require('./build/ringcentral-client').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();
});
/**
* Default Task
*/
gulp.task('default', ['uglify', 'version']);
/**
* Watch Task
*
* (!) This will not run version and sourcemap, the one must run full build before commit
*/
gulp.task('watch', ['webpack'], function() {
var webpack = require('gulp-webpack-build');
gulp.watch('./src/**/*.ts').on('change', function(event) {
gutil.log('File', gutil.colors.magenta(event.path), 'was', event.type);
if (event.type === 'changed') {
gulp.src(event.path, {base: path.resolve('./build')})
.pipe(webpack.closest('webpack.config.js'))
.pipe(webpack.init(webpackConfigure))
.pipe(webpack.watch(function(err, stats) {
gulp.src(this.path, {base: this.base})
.pipe(webpack.proxy(err, stats))
.pipe(webpack.format(webpackFormat))
.pipe(gulp.dest('./build'));
}));
}
});
});
})();