2021-06-09 15:49:04 +00:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const gulpEsbuild = require('gulp-esbuild');
|
|
|
|
const less = require("gulp-less");
|
|
|
|
const livereload = require("gulp-livereload");
|
|
|
|
const cleanCSS = require('gulp-clean-css');
|
|
|
|
const notify = require("gulp-notify");
|
|
|
|
const compilePeg = require("gulp-peg");
|
|
|
|
const plumber = require("gulp-plumber");
|
|
|
|
const sourcemaps = require('gulp-sourcemaps');
|
|
|
|
const through = require("through2");
|
|
|
|
|
|
|
|
const noop = () => through.obj();
|
2014-12-30 08:51:07 +00:00
|
|
|
|
2015-10-08 10:43:55 +00:00
|
|
|
var handleError = {errorHandler: notify.onError("Error: <%= error.message %>")};
|
2014-09-16 09:41:49 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function styles(files, dev) {
|
2015-10-08 10:43:55 +00:00
|
|
|
return gulp.src(files)
|
2021-06-09 15:49:04 +00:00
|
|
|
.pipe(dev ? plumber(handleError) : noop())
|
2014-09-16 09:41:49 +00:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(less())
|
2021-06-09 15:49:04 +00:00
|
|
|
.pipe(dev ? noop() : cleanCSS())
|
|
|
|
.pipe(sourcemaps.write(".", {sourceRoot: '/src/css'}))
|
|
|
|
.pipe(gulp.dest("../mitmproxy/tools/web/static"))
|
2015-10-08 10:43:55 +00:00
|
|
|
.pipe(livereload({auto: false}));
|
2014-09-16 09:41:49 +00:00
|
|
|
}
|
2021-06-09 15:49:04 +00:00
|
|
|
|
|
|
|
function styles_vendor_prod() {
|
|
|
|
return styles("src/css/vendor.less", false)
|
2015-10-08 10:43:55 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function styles_vendor_dev() {
|
|
|
|
return styles("src/css/vendor.less", true)
|
2014-09-13 15:00:05 +00:00
|
|
|
}
|
2021-06-09 15:49:04 +00:00
|
|
|
|
|
|
|
function styles_app_prod() {
|
|
|
|
return styles("src/css/app.less", false)
|
2015-03-06 20:17:50 +00:00
|
|
|
}
|
2014-09-13 15:00:05 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function styles_app_dev() {
|
|
|
|
return styles("src/css/app.less", true)
|
|
|
|
}
|
2014-09-16 09:41:49 +00:00
|
|
|
|
2014-12-12 16:49:10 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function esbuild(dev) {
|
|
|
|
return gulp.src('src/js/app.jsx').pipe(
|
|
|
|
gulpEsbuild({
|
|
|
|
outfile: 'app.js',
|
|
|
|
sourcemap: true,
|
|
|
|
sourceRoot: "/",
|
|
|
|
minify: !dev,
|
|
|
|
keepNames: true,
|
|
|
|
bundle: true,
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest("../mitmproxy/tools/web/static"))
|
|
|
|
.pipe(livereload({auto: false}));
|
|
|
|
}
|
2014-09-16 09:41:49 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function scripts_dev() {
|
|
|
|
return esbuild(true);
|
|
|
|
}
|
2015-10-08 10:43:55 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
function scripts_prod() {
|
|
|
|
return esbuild(false);
|
|
|
|
}
|
2014-09-13 15:00:05 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
const copy_src = ["src/images/**", "src/fonts/fontawesome-webfont.*"];
|
|
|
|
|
|
|
|
function copy() {
|
|
|
|
return gulp.src(copy_src, {base: "src/"})
|
|
|
|
.pipe(gulp.dest("../mitmproxy/tools/web/static"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const template_src = "src/templates/*";
|
|
|
|
|
|
|
|
function templates() {
|
|
|
|
return gulp.src(template_src, {base: "src/"})
|
|
|
|
.pipe(gulp.dest("../mitmproxy/tools/web"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const peg_src = "src/js/filt/filt.peg";
|
|
|
|
|
|
|
|
function peg() {
|
|
|
|
return gulp.src(peg_src, {base: "src/"})
|
2015-10-08 10:43:55 +00:00
|
|
|
.pipe(plumber(handleError))
|
2021-06-09 15:49:04 +00:00
|
|
|
.pipe(compilePeg())
|
2015-01-02 22:46:51 +00:00
|
|
|
.pipe(gulp.dest("src/"));
|
2021-06-09 15:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const dev = gulp.parallel(
|
|
|
|
copy,
|
|
|
|
styles_vendor_dev,
|
|
|
|
styles_app_dev,
|
|
|
|
peg,
|
|
|
|
scripts_dev,
|
|
|
|
templates
|
2014-12-30 08:51:07 +00:00
|
|
|
);
|
2014-09-16 09:41:49 +00:00
|
|
|
|
2021-06-09 15:49:04 +00:00
|
|
|
const prod = gulp.parallel(
|
|
|
|
copy,
|
|
|
|
styles_vendor_prod,
|
|
|
|
styles_app_prod,
|
|
|
|
peg,
|
|
|
|
scripts_prod,
|
|
|
|
templates
|
2019-12-12 15:28:11 +00:00
|
|
|
);
|
2021-06-09 15:49:04 +00:00
|
|
|
|
|
|
|
exports.dev = dev;
|
|
|
|
exports.prod = prod;
|
|
|
|
exports.default = function watch() {
|
|
|
|
const opts = {ignoreInitial: false};
|
|
|
|
livereload.listen({auto: true});
|
|
|
|
gulp.watch(["src/css/vendor*"], opts, styles_vendor_dev);
|
|
|
|
gulp.watch(["src/css/**"], opts, styles_app_dev);
|
|
|
|
gulp.watch(["src/js/**"], opts, scripts_dev);
|
|
|
|
gulp.watch(template_src, opts, templates);
|
|
|
|
gulp.watch(peg_src, opts, peg);
|
|
|
|
gulp.watch(copy_src, opts, copy);
|
|
|
|
}
|