forked from Asana/node-asana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
145 lines (134 loc) · 3.95 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var browserify = require('browserify');
var bump = require('gulp-bump');
var filter = require('gulp-filter');
var git = require('gulp-git');
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var tagVersion = require('gulp-tag-version');
var uglify = require('gulp-uglify');
var vinylBuffer = require('vinyl-buffer');
var vinylSourceStream = require('vinyl-source-stream');
/**
* Paths
*/
var index = './index.js';
var lib = 'lib/**/*.js';
var root = '*.js';
var test = 'test/**/*.js';
/**
* Bundles the code, full version to `asana.js` and minified to `asana-min.js`
*/
function browserTask(minify) {
return function(done) {
var task = browserify(
{
entries: [index],
standalone: 'Asana'
})
.bundle()
.pipe(vinylSourceStream('asana' + (minify ? '-min' : '') + '.js'));
if (minify) {
task = task
.pipe(vinylBuffer())
.pipe(uglify());
}
task.pipe(gulp.dest('dist'));
done();
};
}
/**
* Ensure that the git working directory is clean.
*/
function ensureGitClean(done) {
git.status(function(err, out) {
if (err) { throw err; }
if (!/working directory clean/.exec(out)) {
throw new Error('Git working directory not clean, will not bump version');
}
});
done();
}
gulp.task('ensure-git-clean', ensureGitClean);
/**
* Bumping version number and tagging the repository with it.
* Please read http://semver.org/
*
* You can use the commands
*
* gulp bump-patch # makes v0.1.0 → v0.1.1
* gulp bump-feature # makes v0.1.1 → v0.2.0
* gulp bump-release # makes v0.2.1 → v1.0.0
*
* To bump the version numbers accordingly after you did a patch,
* introduced a feature or made a backwards-incompatible release.
*/
function bumpVersion(importance) {
return gulp.src(['./package.json', './bower.json'])
.pipe(bump({type: importance}))
.pipe(gulp.dest('./'))
.pipe(git.commit('bump package version'))
.pipe(filter('package.json'))
.pipe(tagVersion());
}
function bumpPatch() {
return bumpVersion('patch');
}
gulp.task('bump-patch', gulp.series('ensure-git-clean', bumpPatch));
function bumpFeature() {
return bumpVersion('minor');
}
gulp.task('bump-feature', gulp.series('ensure-git-clean', bumpFeature));
function bumpVersion() {
return bumpVersion('major');
}
gulp.task('bump-release', gulp.series('ensure-git-clean', bumpVersion));
/**
* Lints all of the JavaScript files and fails if the tasks do not pass
*/
function lint() {
return gulp.src([root, lib, test])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
}
gulp.task('lint', lint);
/**
* Tests the code with mocha and ensures 100% code coverage
*/
function spec(callback) {
gulp.src(lib)
.pipe(istanbul({
includeUntested: true
}))
.pipe(istanbul.hookRequire())
.on('finish', function() {
gulp.src(test)
.pipe(mocha({
reporter: process.env.TRAVIS ? 'spec' : 'nyan'
}))
.pipe(istanbul.writeReports({
reporters: ['text', 'text-summary']
}))
.on('end', function() {
var errOrNull = null;
var coverage = istanbul.summarizeCoverage();
var incomplete = Object.keys(coverage).filter(function(key) {
return coverage[key].pct < 49; // TODO: Get this to 100%
});
if (incomplete.length > 0) {
console.log('Incomplete coverage for ' + incomplete.join(', '));
}
callback(errOrNull);
});
});
}
gulp.task('spec', gulp.series('lint', spec));
gulp.task('browser', browserTask(false));
gulp.task('browser-min', browserTask(true));
/**
* High Level Tasks
*/
gulp.task('bundle', gulp.series('browser', 'browser-min'));
gulp.task('test', gulp.series('bundle', 'spec'));