forked from nesk/network.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (61 loc) · 1.64 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
/*
* Requirements
*/
var path = require('path');
var babelify = require('babelify'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
chalk = require('chalk'),
exorcist = require('exorcist'),
gulp = require('gulp'),
source = require('vinyl-source-stream');
var rename = require('gulp-rename'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify');
/*
* Paths
*/
var paths = {
src: './lib/SpeedTest.js',
dest: 'dist',
watch: ['lib/**', 'utils/**']
};
var names = {
base: 'speedtest.js',
min: 'speedtest.min.js'
};
/*
* Helpers
*/
function error(error) {
console.log('\n' + chalk.red('Error: ') + error.message + '\n');
this.emit('end');
}
/*
* Tasks
*/
gulp.task('default', function() {
return browserify({
entries: paths.src,
standalone: 'SpeedTest',
debug: true
})
.transform(babelify)
.bundle().on('error', error)
.pipe(exorcist(path.join(paths.dest, names.base + '.map')))
.pipe(source(names.base))
.pipe(gulp.dest(paths.dest))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify().on('error', error))
.pipe(rename(names.min))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.dest));
});
gulp.task('watch', function(cb) {
var watcher = gulp.watch(paths.watch, ['default']);
watcher.on('change', function(event) {
var type = event.type.toUpperCase().slice(0, 1) + event.type.toLowerCase().slice(1);
console.log('\n' + chalk.yellow(type + ': ') + chalk.magenta(event.path) + '\n');
});
});