forked from kevin-reece-cko/checkout-api-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
72 lines (64 loc) · 1.76 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
var connect = require('connect');
var cors = require('cors');
var { existsSync, mkdirSync } = require('fs');
const gulp = require('gulp');
var { watch } = require('gulp');
var gulpConnect = require('gulp-connect');
var exec = require('gulp-exec');
var util = require('gulp-util');
var portfinder = require('portfinder');
var swaggerRepo = require('swagger-repo');
var DIST_DIR = 'web_deploy';
if (!existsSync(DIST_DIR)) {
mkdirSync(DIST_DIR);
}
gulp.task('build', () => gulp.src(DIST_DIR).pipe(exec('npm run build:all')));
gulp.task(
'reload',
gulp.series('build', () => gulp.src(DIST_DIR).pipe(gulpConnect.reload()))
);
gulp.task('watch', (cb) => {
watch('abc_spec/**/*', gulp.series('reload'));
watch('nas_spec/**/*', gulp.series('reload'));
watch('web/**/*', gulp.series('reload'));
cb();
});
gulp.task('edit', () => {
return portfinder
.getPortPromise({ port: 5000 })
.then((port) => {
var app = connect();
app.use(swaggerRepo.swaggerEditorMiddleware());
app.listen(port);
util.log(util.colors.green('swagger-editor started http://localhost:' + port));
})
.catch((err) => {
// Could not get a free port, `err` contains the reason.
console.log(err);
});
});
gulp.task('start_site', (cb) => {
return portfinder
.getPortPromise({ port: 3001 })
.then((port) => {
// `port` is guaranteed to be a free port in this scope.
gulpConnect.server(
{
root: [DIST_DIR],
livereload: true,
port: port,
middleware: (_, __) => {
return [cors()];
},
},
function () {
this.server.on('close', cb);
}
);
})
.catch((err) => {
// Could not get a free port, `err` contains the reason.
console.log(err);
});
});
gulp.task('serve', gulp.series('build', gulp.parallel('watch', 'edit', 'start_site')));