-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (88 loc) · 2.49 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
///* jshint camelcase:false */
//var gulp = require('gulp');
//var browserSync = require('browser-sync');
//var del = require('del');
//var glob = require('glob');
var gulp = require('gulp-param')(require('gulp'), process.argv),
mocha = require("gulp-mocha"),
istanbul = require('gulp-istanbul'),
bench = require('gulp-bench'),
uglify = require('gulp-uglify'),
rimraf = require('gulp-rimraf'),
bump = require('gulp-bump'),
replace = require('gulp-replace'),
rename = require('gulp-rename'),
browserify = require('gulp-browserify'),
SRC = 'index.js',
DEST = 'dist',
SRC_COMPILED = 'safe.accessors.js',
MIN_FILE = 'safe.accessors.min.js',
VERSION_FILES = ['./package.json', './component.json', './bower.json'];
VERSION_FILES_JS = [SRC, 'package.js'];
gulp.task('test', function(cov) {
var reporters = ['html'];
if (cov) {
reporters.push('text');
} else {
reporters.push('text-summary');
}
return gulp.src([SRC])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
return gulp.src(['test/specs/*.spec.js'])
.pipe(
mocha({
globals: '*',
reporter: 'dot'
})
)
.pipe(istanbul.writeReports({
reporters: reporters
}));
});
});
gulp.task('bench', ['browserify'], function(func) {
func = func || '*';
return gulp.src('bench/'+ func + '.js')
.pipe(bench());
});
gulp.task('browserify', function() {
return gulp.src([SRC])
.pipe(browserify())
.pipe(rename(SRC_COMPILED))
.pipe(gulp.dest(DEST));
});
gulp.task('clean', function() {
return gulp.src(DEST)
.pipe(rimraf());
});
gulp.task('bump-in-js', function(semver) {
return gulp.src(VERSION_FILES_JS)
.pipe(replace(/(version?\s?=?\:?\s\')([\d\.]*)\'/gi, '$1' + semver + "'"))
.pipe(gulp.dest('./'));
});
// usage: gulp bump -s <% Version %>
// usage: gulp bump --semver <% Version %>
gulp.task('bump', ['bump-in-js'], function(semver) {
if (typeof semver !== 'string' || semver.length <= 0) {
console.error('pass a new version `gulp bump --semver 2.4.1`');
process.exit(1);
}
return gulp.src(VERSION_FILES)
.pipe(bump({
version: semver
}))
.pipe(gulp.dest('./'));
});
gulp.task('build', function() {
return gulp.src([SRC])
.pipe(rename(SRC_COMPILED))
.pipe(gulp.dest(DEST))
.on('finish', function () {
gulp.src(DEST + '/' + SRC_COMPILED)
.pipe(uglify())
.pipe(rename(MIN_FILE))
.pipe(gulp.dest(DEST))
});
});