-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
270 lines (240 loc) · 6.64 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
'use strict';
var gulp = require('gulp');
var es = require('event-stream');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var less = require('gulp-less');
var wrap = require('gulp-wrap');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var header = require('gulp-header');
var order = require('gulp-order');
var jshint = require('gulp-jshint');
var runSequence = require('run-sequence');
var cssnano = require('gulp-cssnano');
var pkg = require('./package.json');
var sourcemaps = require('gulp-sourcemaps');
var bootprint = require('bootprint');
var bootprintopenapi = require('bootprint-openapi');
var yamls = [
["index", "Index"],
["products", "Product Spec"],
["prospects", "Prospect Spec"],
["quotations", "Quotation Spec"],
["proposals", "Proposal Spec"]
];
/**
* build document
*/
gulp.task('bootprint-openapi', [], function () {
for (var i = yamls.length - 1; i >= 1; i--) {
bootprint
.load(bootprintopenapi)
.build('./src/main/yaml/' + yamls[i][0] + '.yaml', './dist/yaml/doc/' + yamls[i][0] + '/')
.generate()
.done(console.log);
}
});
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', log);
});
/**
* JShint all *.js files
*/
gulp.task('lint', function () {
return gulp.src('./src/main/javascript/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
/**
* Build a distribution
*/
gulp.task('dist', ['clean', 'lint'], _dist);
function _dist() {
return es.merge(
gulp.src([
'./node_modules/es5-shim/es5-shim.js',
'./lib/sanitize-html.min.js',
'./src/main/javascript/**/*.js',
'./node_modules/swagger-client/browser/swagger-client.js'
]),
gulp
.src(['./src/main/template/templates.js'])
.on('error', log)
)
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(order(['scripts.js', 'templates.js']))
.pipe(concat('swagger-ui.js'))
.pipe(wrap('(function(){<%= contents %>}).call(this);'))
.pipe(header(banner, { pkg: pkg }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./dist/i'))
.pipe(uglify())
.on('error', log)
.pipe(rename({extname: '.min.js'}))
.on('error', log)
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./dist/i'))
.pipe(connect.reload());
}
gulp.task('dev-dist', ['lint', 'dev-copy'], _dist);
/**
* Processes less files into CSS files
*/
gulp.task('less', ['clean'], _less);
function _less() {
return gulp
.src([
'./src/main/less/screen.less',
'./src/main/less/print.less',
'./src/main/less/reset.less',
'./src/main/less/style.less'
])
.pipe(less())
.on('error', function(err){ log(err); this.emit('end');})
.pipe(gulp.dest('./src/main/html/css/'))
.pipe(connect.reload());
}
gulp.task('dev-less', _less);
/**
* Copy lib and html folders
*/
gulp.task('copy', ['less'], _copy);
function _copy() {
// copy JavaScript files inside lib folder
gulp
.src(['./lib/**/*.{js,map}',
'./node_modules/es5-shim/es5-shim.js'
])
.pipe(gulp.dest('./dist/lib'))
.pipe(gulp.dest('./dist/i/lib'))
.on('error', log);
// copy `lang` for translations
gulp
.src(['./lang/**/*.js'])
.pipe(gulp.dest('./dist/lang'))
.pipe(gulp.dest('./dist/i/lang'))
.on('error', log);
// copy all files inside html folder
gulp
.src(['./src/main/html/**/*'])
.pipe(gulp.dest('./dist'))
.pipe(gulp.dest('./dist/i'))
.on('error', log);
// copy all files inside yaml folder
gulp
.src(['./src/main/yaml/**/*'])
.pipe(gulp.dest('./dist/yaml'))
.pipe(gulp.dest('./dist/api-docs'))
.on('error', log);
}
gulp.task('rename-index', function(){
//clean index.html
gulp
.src('./dist/internal.html', {read: false})
.pipe(clean())
.on('error', log);
gulp
.src('./dist/i/internal.html')
.pipe(rename('i/index.html'))
.pipe(gulp.dest('./dist'))
.on('error', log);
//clean internal.html
gulp
.src('./dist/i/internal.html', {read: false})
.pipe(clean())
.on('error', log);
})
gulp.task('replace-swagger-ui', function(){
//clean
gulp
.src('./api/nodejs-server/node_modules/swagger-tools/middleware/swagger-ui', {read: false})
.pipe(clean())
.on('error', log);
// copy html to middleware layer, for the api
gulp
.src(['./dist/**/*'])
.pipe(gulp.dest('./api/nodejs-server/node_modules/swagger-tools/middleware/swagger-ui'))
.on('error', log);
})
gulp.task('dev-copy', ['dev-less', 'copy-local-specs'], _copy);
gulp.task('copy-local-specs', function () {
// copy the test specs
return gulp
.src(['./test/specs/**/*'])
.pipe(gulp.dest('./dist/specs'))
.on('error', log);
});
gulp.task('minify-css', function() {
/** Minify all CSS within dist folder, runs after dist process*/
return gulp.src('./dist/css/*.css')
.pipe(cssnano())
.pipe(gulp.dest('./dist/css'));
});
gulp.task('uglify-libs', function() {
/**
* Minify all JS libs within the dist folder. A nice TODO would be to use versions from CDN
*/
gulp.src('./dist/lib/*.js')
.pipe(uglify())
.pipe(gulp.dest('./dist/lib'));
});
/**
* Watch for changes and recompile
*/
gulp.task('watch', ['copy-local-specs'], function() {
return watch([
'./src/**/*.{js,less,handlebars}',
'./src/main/html/*.html',
'./src/main/yaml/*.yaml',
'./test/specs/**/*.{json,yaml}'
],
function() {
gulp.start('dev-dist');
});
});
/**
* Live reload web server of `dist`
*/
gulp.task('connect', function() {
connect.server({
port: 8888,
root: 'dist',
livereload: true
});
});
function log(error) {
console.error(error.toString && error.toString());
}
gulp.task('handlebars', function () {
gulp
.src(['./src/main/template/templates.js'])
.pipe(wrap('/* jshint ignore:start */ \n {<%= contents %>} \n /* jshint ignore:end */'))
.pipe(gulp.dest('./src/main/template/'))
.on('error', log);
});
gulp.task('default', function(callback) {
runSequence([ 'dist', 'copy'], ['rename-index'], ['bootprint-openapi'],
['uglify-libs', 'minify-css'], ['replace-swagger-ui'],
callback);
});
gulp.task('serve', ['connect', 'watch']);
gulp.task('dev', ['default'], function () {
gulp.start('serve');
});