-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
120 lines (100 loc) · 3.05 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
/*jshint node:true */
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var del = require('del');
var coveralls = require('gulp-coveralls');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var gutil = require('gulp-util');
var rename = require('gulp-rename');
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = [
'/**',
' * <%= pkg.name %> - Copyright ' + new Date().getFullYear() + ' <%= pkg.author %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */\n'
].join('\n');
function tmpBrowserify(pkgName) {
var pkgPath = './node_modules/' + pkgName + '/src/' + pkgName + '.js';
var b = browserify().require(pkgPath, {expose: pkgName});
return b.bundle()
.pipe(source(pkgName))
.pipe(buffer())
.pipe(gulp.dest('./tmp/'));
}
function browserifyLc(dest) {
var b = browserify().require('./' + pkg.main, {expose: pkg.name});
return b.bundle()
.pipe(source(pkg.name + '.js'))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest(dest))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify()).on('error', gutil.log)
.pipe(rename(pkg.name + '.min.js'))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest(dest))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(dest));
}
gulp.task('clean:coverage', function(cb) {
del(['coverage']).then(function() {
cb();
});
});
gulp.task('clean:dist', function(cb) {
del(['dist']).then(function() {
cb();
});
});
gulp.task('instrument', function() {
return gulp.src(['src/linear-converter.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
gulp.task('browserify-arbitrary-precision', [], function() {
return tmpBrowserify('arbitrary-precision');
});
gulp.task('browserify-linear-preset-factory', [], function() {
return tmpBrowserify('linear-preset-factory');
});
gulp.task('browserify-linear-presets', [], function() {
return tmpBrowserify('linear-presets');
});
gulp.task('browserify-bigjs-adapter', [], function() {
return tmpBrowserify('bigjs-adapter');
});
gulp.task('browserify-floating-adapter', [], function() {
return tmpBrowserify('floating-adapter');
});
gulp.task('test', ['clean:coverage', 'instrument'], function() {
return gulp.src(['test/node/*.js'])
.pipe(mocha())
.pipe(istanbul.writeReports());
});
gulp.task('coveralls', function() {
gulp.src('coverage/lcov.info')
.pipe(coveralls());
});
gulp.task('browserify', ['clean:dist'], function() {
return browserifyLc('./dist/');
});
var devDeps = [
'browserify-linear-preset-factory',
'browserify-linear-presets',
'browserify-bigjs-adapter',
'browserify-floating-adapter',
'browserify-arbitrary-precision'
];
gulp.task('dev', devDeps, function() {
return browserifyLc('./tmp/');
});
gulp.task('build', ['browserify']);
gulp.task('default', ['build']);