forked from swagger-api/swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
138 lines (122 loc) · 3 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
'use strict';
var gulp = require('gulp');
var es = require('event-stream');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var less = require('gulp-less');
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var declare = require('gulp-declare');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
/**
* Clean ups ./dist folder
*/
gulp.task('clean', function() {
return gulp
.src('./dist', {read: false})
.pipe(clean({force: true}))
.on('error', gutil.log);
});
/**
* Processes Handlebars templates
*/
function templates() {
return gulp
.src(['./src/main/template/**/*'])
.pipe(handlebars())
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'Handlebars.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.on('error', gutil.log);
}
/**
* Processes CoffeeScript files
*/
function coffeescript () {
return gulp
.src(['./src/main/coffeescript/**/*.coffee'])
.pipe(coffee({bare: true}))
.on('error', gutil.log);
}
/**
* Build a distribution
*/
gulp.task('dist', ['clean'], function() {
return es.merge(
gulp.src('./src/main/javascript/doc.js'),
coffeescript(),
templates()
)
.pipe(concat('swagger-ui.js'))
.pipe(header(banner, { pkg: pkg } ))
.pipe(gulp.dest('./dist'))
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.on('error', gutil.log)
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());
});
/**
* Processes less files into CSS files
*/
gulp.task('less', ['clean'], function() {
return gulp
.src([
'./src/main/less/screen.less',
'./src/main/less/reset.less'
])
.pipe(less())
.on('error', gutil.log)
.pipe(gulp.dest('./src/main/html/css/'))
.pipe(connect.reload());
});
/**
* Copy lib and html folders
*/
gulp.task('copy', ['less'], function() {
// copy JavaScript files inside lib folder
gulp
.src(['./lib/**/*.js'])
.pipe(gulp.dest('./dist/lib'))
.on('error', gutil.log)
// copy all files inside html folder
gulp
.src(['./src/main/html/**/*'])
.pipe(gulp.dest('./dist'))
.on('error', gutil.log)
});
/**
* Watch for changes and recompile
*/
gulp.task('watch', function() {
return watch(['./src/**/*.{coffee,js,less}'], function() {
gulp.start('default');
});
});
/**
* Live reload web server of `dist`
*/
gulp.task('connect', function() {
connect.server({
root: 'dist',
livereload: true
});
});
gulp.task('default', ['dist', 'copy']);
gulp.task('serve', ['connect', 'watch'])