forked from swagger-api/swagger-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (92 loc) · 2.66 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
'use strict';
var async = require('async');
var browserify = require('browserify');
var buffer = require('gulp-buffer');
var del = require('del');
var gulp = require('gulp');
var header = require('gulp-header');
var istanbul = require('gulp-istanbul');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var pkg = require('./package');
var source = require('vinyl-source-stream');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
var basename = 'swagger-client';
var paths = {
sources: ['index.js', 'lib/**/*.js'],
tests: ['test/*.js', 'test/compat/*.js', '!test/browser/*.js'],
dist: 'browser'
};
paths.all = paths.sources.concat(paths.tests).concat(['gulpfile.js']);
gulp.task('clean', function (cb) {
del([
paths.dist + '/' + basename + '.*',
'coverage',
'test/browser/' + basename + '-browser-tests.js'
], cb);
});
gulp.task('lint', function () {
return gulp
.src(paths.all)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('coverage', function () {
process.env.NODE_ENV = 'test';
return gulp
.src(paths.sources)
.pipe(istanbul({includeUntested: true}))
.pipe(istanbul.hookRequire()) // Force `require` to return covered files
.on('finish', function () {
gulp
.src(paths.tests)
.pipe(mocha({reporter: 'spec'}))
.pipe(istanbul.writeReports());
});
});
gulp.task('build', function (cb) {
// Builds browser binaries:
//
// 1 (swagger-client.js): Standalone build without uglification and including source maps
// 2 (swagger-client.min.js): Standalone build uglified and without source maps
async.map([0,1], function (n, callback) {
var useDebug = n % 2 === 0;
var b = browserify('./index.js', {
debug: useDebug,
standalone: 'SwaggerClient'
});
if (!useDebug) {
b.transform({global: true}, 'uglifyify');
}
b.transform('brfs')
.bundle()
.pipe(source(basename + (!useDebug ? '.min' : '') + '.js'))
.pipe(buffer())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('./browser/'))
.on('error', function (err) {
callback(err);
})
.on('end', function () {
callback();
});
}, function (err) {
cb(err);
});
});
gulp.task('test', function () {
process.env.NODE_ENV = 'test';
return gulp
.src(paths.tests)
.pipe(mocha({reporter: 'spec'}));
});
gulp.task('watch', ['test'], function () {
gulp.watch(paths.all, ['test']);
});
gulp.task('default', ['clean', 'lint', 'test', 'build']);