gulpfile.js
2.92 KB
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
var gulp = require('gulp-param')(require('gulp'), process.argv),
mocha = require("gulp-mocha"),
eslint = require('gulp-eslint'),
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'),
header = require('gulp-header'),
SRC = 'index.js',
DEST = 'dist',
SRC_COMPILED = 'underscore.string.js',
MIN_FILE = 'underscore.string.min.js',
VERSION_FILES = ['./package.json', './component.json', './bower.json'],
VERSION_FILES_JS = [SRC, 'package.js'],
package = require('./package.json'),
headerText = '/* ' + package.name + ' ' + package.version + ' | ' +
package.license + ' licensed | ' + package.homepage + ' */\n\n';
gulp.task('test', ['lint', 'browserify'], function(cov) {
var reporters = ['html'];
if (cov) {
reporters.push('text');
} else {
reporters.push('text-summary');
}
return gulp.src(['*.js', 'helper/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
return gulp.src(['tests/*.js'])
.pipe(mocha({
ui: 'qunit',
reporter: 'dot'
}))
.pipe(istanbul.writeReports({
reporters: reporters
}));
});
});
gulp.task('lint', function() {
var toLint = [
'**/*.js',
'!gulpfile.js',
'!meteor-*.js',
'!package.js',
'!dist/**',
'!coverage/**',
'!node_modules/**'
];
return gulp.src(toLint)
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
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({
detectGlobals: true,
standalone: 's'
}))
.pipe(header(headerText))
.pipe(rename('underscore.string.js'))
.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', ['test', 'clean'], function() {
gulp.src(DEST + '/' + SRC_COMPILED)
.pipe(uglify())
.pipe(header(headerText))
.pipe(rename(MIN_FILE))
.pipe(gulp.dest(DEST));
});