2022-01-24 12:35:28 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const util = require('gulp-util');
|
|
|
|
const gulpConnect = require('gulp-connect');
|
|
|
|
const connect = require('connect');
|
|
|
|
const cors = require('cors');
|
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const portfinder = require('portfinder');
|
|
|
|
const swaggerRepo = require('swagger-repo');
|
2018-06-12 16:50:45 +00:00
|
|
|
|
2022-01-24 12:35:28 +00:00
|
|
|
const DIST_DIR = 'dist';
|
|
|
|
const SPEC_DIR = 'spec';
|
2018-06-12 16:50:45 +00:00
|
|
|
|
2020-11-11 15:04:06 +00:00
|
|
|
gulp.task('build', function (cb) {
|
|
|
|
exec('npm run build', function (err, stdout, stderr) {
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
2018-06-12 16:50:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-24 12:35:28 +00:00
|
|
|
|
2020-11-11 15:04:06 +00:00
|
|
|
gulp.task('edit', function () {
|
|
|
|
portfinder.getPort({ port: 5000 }, function (err, port) {
|
2022-01-24 12:35:28 +00:00
|
|
|
let app = connect();
|
2018-06-12 16:50:45 +00:00
|
|
|
app.use(swaggerRepo.swaggerEditorMiddleware());
|
|
|
|
app.listen(port);
|
|
|
|
util.log(util.colors.green('swagger-editor started http://localhost:' + port));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-11 15:04:06 +00:00
|
|
|
gulp.task('reload', gulp.series('build', function () {
|
2018-06-12 16:50:45 +00:00
|
|
|
gulp.src(DIST_DIR).pipe(gulpConnect.reload())
|
2020-11-11 15:04:06 +00:00
|
|
|
}));
|
2018-06-12 16:50:45 +00:00
|
|
|
|
|
|
|
gulp.task('watch', function () {
|
2022-01-24 12:35:28 +00:00
|
|
|
gulp.watch([`${SPEC_DIR}/**/*`, 'web/**/*'], gulp.series('reload'));
|
2018-06-12 16:50:45 +00:00
|
|
|
});
|
2020-11-11 15:04:06 +00:00
|
|
|
|
|
|
|
gulp.task('serve', gulp.parallel('build', 'edit', 'watch', function () {
|
|
|
|
portfinder.getPort({ port: 3000 }, function (err, port) {
|
|
|
|
gulpConnect.server({
|
|
|
|
root: [DIST_DIR],
|
|
|
|
livereload: true,
|
|
|
|
port: port,
|
|
|
|
middleware: function (gulpConnect, opt) {
|
|
|
|
return [
|
|
|
|
cors()
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}));
|