forked from biojs/biojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (71 loc) · 2.22 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
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
// external tools
var path = require('path');
var join = path.join;
var mkdirp = require('mkdirp');
var gzip = require('gulp-gzip');
var clean = require('gulp-rimraf');
var rename = require('gulp-rename');
var browserify = require('gulp-browserify');
// config
var buildDir = "build";
var browserFile = "browser.js";
var packageConfig = require('./package.json');
var outputFile = packageConfig.name;
// auto config
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', 'build-browser', 'build-browser-gzip']);
gulp.task('lint', function() {
return gulp.src('./src/*.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', './test/**/*.js'], function() {
gulp.run('test');
});
});
// 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));
});
// 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)
});
});