forked from swagger-api/swagger-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
134 lines (116 loc) · 3.31 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
'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');
// Browser Unit Tests
var karma = require('karma').server;
var karmaConfig = require('./karma.conf');
var assign = require('object.assign');
var connect = require('gulp-connect');
var cors = require('connect-cors');
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/both/*.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'}))
.on('error', console.log);
});
gulp.task('watch', ['test'], function () {
gulp.watch(paths.all, ['test']);
});
gulp.task('browsertest', function(done) {
karma.start(karmaConfig, done);
});
gulp.task('connect', function () {
connect.server({
livereload: false,
root: __dirname + '/test/spec/v2',
port: 8000,
middleware: function (a,b) {
return [ cors(a,b) ];
}
});
});
gulp.task('watch-browsertest', function(done){
var opts = assign({}, karmaConfig, {singleRun: false});
karma.start(opts, done);
});
gulp.task('default', ['clean', 'lint', 'test', 'build']);