2019-05-23 14:16:53 +00:00
|
|
|
var gulp = require('gulp');
|
2019-06-24 12:51:53 +00:00
|
|
|
var util = require('gulp-util');
|
2019-05-23 14:16:53 +00:00
|
|
|
var gulpConnect = require('gulp-connect');
|
|
|
|
var connect = require('connect');
|
|
|
|
var cors = require('cors');
|
|
|
|
var path = require('path');
|
|
|
|
var exec = require('child_process').exec;
|
|
|
|
var portfinder = require('portfinder');
|
|
|
|
var swaggerRepo = require('swagger-repo');
|
|
|
|
|
|
|
|
var DIST_DIR = 'web_deploy';
|
|
|
|
|
|
|
|
gulp.task('serve', ['build', 'watch', 'edit'], function() {
|
|
|
|
portfinder.getPort({port: 3000}, function (err, port) {
|
|
|
|
gulpConnect.server({
|
|
|
|
root: [DIST_DIR],
|
|
|
|
livereload: true,
|
|
|
|
port: port,
|
|
|
|
middleware: function (gulpConnect, opt) {
|
|
|
|
return [
|
|
|
|
cors()
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('edit', function() {
|
|
|
|
portfinder.getPort({port: 5000}, function (err, port) {
|
|
|
|
var app = connect();
|
|
|
|
app.use(swaggerRepo.swaggerEditorMiddleware());
|
|
|
|
app.listen(port);
|
|
|
|
util.log(util.colors.green('swagger-editor started http://localhost:' + port));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build', function (cb) {
|
|
|
|
exec('npm run build', function (err, stdout, stderr) {
|
|
|
|
console.log(stderr);
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('reload', ['build'], function () {
|
|
|
|
gulp.src(DIST_DIR).pipe(gulpConnect.reload())
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function () {
|
|
|
|
gulp.watch(['api/swag-dark-api/**/*', 'web/**/*'], ['reload']);
|
|
|
|
});
|