-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
95 lines (79 loc) · 2.42 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
/*
* biojs-io-wig
* https://github.com/anilthanki/biojs-io-wig
*
* Copyright (c) 2014 Anil Thanki
* Licensed under the Apache 2 license.
*/
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var browserify = require('gulp-browserify');
// gulp helper
var gzip = require('gulp-gzip');
var clean = require('gulp-rimraf');
var rename = require('gulp-rename');
// path tools
var path = require('path');
var join = path.join;
var mkdirp = require('mkdirp');
// browserify build config
var buildDir = "build";
var browserFile = "browser.js";
var packageConfig = require('./package.json');
var outputFile = packageConfig.name;
// auto config for browserify
var outputFileSt = outputFile + ".js";
var outputFilePath = join(buildDir,outputFileSt);
var outputFileMinSt = outputFile + ".min.js";
var outputFileMin = join(buildDir,outputFileMinSt);
// a failing test breaks the whole build chain
gulp.task('default', ['lint', 'test', 'build-browser', 'build-browser-gzip']);
gulp.task('lint', function() {
return gulp.src('./lib/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('test', function () {
return gulp.src('./test/**/*.js', {read: false})
.pipe(mocha({reporter: 'spec',
useColors: false}));
});
gulp.task('watch', function() {
gulp.watch(['./src/**/*.js','./lib/**/*.js', './test/**/*.js'], function() {
gulp.run('test');
});
});
// will remove everything in build
gulp.task('clean', function() {
return gulp.src(buildDir).pipe(clean());
});
// just makes sure that the build dir exists
gulp.task('init', ['clean'], function() {
mkdirp(buildDir, function (err) {
if (err) console.error(err)
});
});
// browserify debug
gulp.task('build-browser',['init'], function() {
return gulp.src(browserFile)
.pipe(browserify({debug:true}))
.pipe(rename(outputFileSt))
.pipe(gulp.dest(buildDir));
});
// browserify min
gulp.task('build-browser-min',['init'], function() {
return gulp.src(browserFile)
.pipe(browserify({}))
.pipe(uglify())
.pipe(rename(outputFileMinSt))
.pipe(gulp.dest(buildDir));
});
gulp.task('build-browser-gzip', ['build-browser-min'], function() {
return gulp.src(outputFileMin)
.pipe(gzip({append: false, gzipOptions: { level: 9 }}))
.pipe(rename(outputFile + ".min.gz.js"))
.pipe(gulp.dest(buildDir));
});