mitmproxy/web/gulpfile.js

181 lines
5.9 KiB
JavaScript
Raw Normal View History

2014-09-13 15:00:05 +00:00
var gulp = require("gulp");
var merge = require('merge-stream');
2014-09-13 15:00:05 +00:00
var concat = require('gulp-concat');
var jshint = require("gulp-jshint");
var less = require("gulp-less");
var livereload = require("gulp-livereload");
var minifyCSS = require('gulp-minify-css');
2014-09-13 23:21:13 +00:00
var notify = require("gulp-notify");
2014-12-12 16:49:10 +00:00
var peg = require("gulp-peg");
2014-09-13 21:05:12 +00:00
var plumber = require("gulp-plumber");
2014-09-13 23:21:13 +00:00
var qunit = require("gulp-qunit");
2014-09-13 15:00:05 +00:00
var react = require("gulp-react");
var rename = require("gulp-rename");
2014-09-13 15:00:05 +00:00
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
2014-12-12 16:49:10 +00:00
var dont_break_on_errors = function () {
return plumber(function (error) {
notify.onError("<%= error.message %>").apply(this, arguments);
2014-09-13 23:21:13 +00:00
this.emit('end');
});
};
2014-09-13 15:00:05 +00:00
var path = {
dist: "../libmproxy/web/",
js: {
vendor: [
'vendor/jquery/jquery.js',
'vendor/lodash/lodash.js',
'vendor/react/react-with-addons.js',
'vendor/react-router/react-router.js',
],
app: [
2014-09-17 13:22:42 +00:00
'js/utils.js',
'js/dispatcher.js',
'js/actions.js',
2014-12-12 16:49:10 +00:00
'js/filt/filt.js',
2014-09-18 23:35:36 +00:00
'js/flow/utils.js',
'js/store/store.js',
'js/store/view.js',
'js/store/settingstore.js',
'js/connection.js',
2014-09-18 21:22:02 +00:00
'js/components/utils.jsx.js',
2014-11-28 19:03:04 +00:00
'js/components/virtualscroll.jsx.js',
'js/components/header.jsx.js',
'js/components/flowtable-columns.jsx.js',
'js/components/flowtable.jsx.js',
2014-09-18 19:13:50 +00:00
'js/components/flowdetail.jsx.js',
'js/components/mainview.jsx.js',
'js/components/eventlog.jsx.js',
'js/components/footer.jsx.js',
'js/components/proxyapp.jsx.js',
2014-09-15 16:08:26 +00:00
'js/app.js',
2014-09-13 15:00:05 +00:00
],
},
2014-12-12 16:49:10 +00:00
peg: "js/filt/filt.pegjs",
2014-09-13 15:00:05 +00:00
css: {
vendor: ["css/vendor.less"],
2014-12-12 16:49:10 +00:00
app: ["css/app.less"],
all: ["css/**"]
2014-09-13 15:00:05 +00:00
},
2014-12-12 16:49:10 +00:00
vendor: ["vendor/**"],
2014-09-13 15:00:05 +00:00
fonts: ["src/vendor/fontawesome/fontawesome-webfont.*"],
2014-12-12 16:49:10 +00:00
html: ["*.html", "!benchmark.html", "!test.html"],
images: ["images/**"],
test: ["test.html"],
opts: {base: "src", cwd: "src"}
2014-09-13 15:00:05 +00:00
};
2014-09-13 15:00:05 +00:00
gulp.task("fonts", function () {
return gulp.src(path.fonts)
.pipe(gulp.dest(path.dist + "static/fonts"));
});
function styles_dev(files) {
2014-12-12 16:49:10 +00:00
return (gulp.src(files, path.opts)
.pipe(dont_break_on_errors())
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write(".", {sourceRoot: "/static"}))
.pipe(gulp.dest(path.dist + "static"))
2014-12-12 16:49:10 +00:00
.pipe(livereload({auto: false})));
}
gulp.task("styles-app-dev", styles_dev.bind(undefined, path.css.app));
gulp.task("styles-vendor-dev", styles_dev.bind(undefined, path.css.vendor));
gulp.task("styles-dev", ["styles-app-dev", "styles-vendor-dev"]);
function styles_prod(files) {
2014-12-12 16:49:10 +00:00
return (gulp.src(files, path.opts)
2014-09-13 15:00:05 +00:00
.pipe(less())
// No sourcemaps support yet :-/
// https://github.com/jonathanepollack/gulp-minify-css/issues/34
.pipe(minifyCSS())
2014-09-13 15:00:05 +00:00
.pipe(gulp.dest(path.dist + "static"))
2014-12-12 16:49:10 +00:00
.pipe(livereload({auto: false})));
2014-09-13 15:00:05 +00:00
}
gulp.task("styles-app-prod", styles_prod.bind(undefined, path.css.app));
gulp.task("styles-vendor-prod", styles_prod.bind(undefined, path.css.vendor));
2014-09-13 15:00:05 +00:00
gulp.task("styles-prod", ["styles-app-prod", "styles-vendor-prod"]);
function scripts_dev(files, filename) {
2014-12-12 16:49:10 +00:00
return gulp.src(files, path.opts)
.pipe(dont_break_on_errors())
.pipe(sourcemaps.init())
.pipe(react())
2014-09-13 15:00:05 +00:00
.pipe(concat(filename))
.pipe(sourcemaps.write(".", {sourceRoot: "/static"}))
2014-09-13 15:00:05 +00:00
.pipe(gulp.dest(path.dist + "static/js"))
2014-12-12 16:49:10 +00:00
.pipe(livereload({auto: false}));
2014-09-13 15:00:05 +00:00
}
gulp.task("scripts-app-dev", scripts_dev.bind(undefined, path.js.app, "app.js"));
gulp.task("scripts-vendor-dev", scripts_dev.bind(undefined, path.js.vendor, "vendor.js"));
2014-09-13 15:00:05 +00:00
gulp.task("scripts-dev", ["scripts-app-dev", "scripts-vendor-dev"]);
function scripts_prod(files, filename) {
2014-12-12 16:49:10 +00:00
return gulp.src(files, path.opts)
.pipe(react())
.pipe(concat(filename))
.pipe(uglify())
.pipe(gulp.dest(path.dist + "static/js"))
2014-12-12 16:49:10 +00:00
.pipe(livereload({auto: false}));
}
gulp.task("scripts-app-prod", scripts_prod.bind(undefined, path.js.app, "app.js"));
gulp.task("scripts-vendor-prod", scripts_prod.bind(undefined, path.js.vendor, "vendor.js"));
2014-09-13 15:00:05 +00:00
gulp.task("scripts-prod", ["scripts-app-prod", "scripts-vendor-prod"]);
2014-09-13 15:00:05 +00:00
gulp.task("jshint", function () {
2014-12-12 16:49:10 +00:00
return gulp.src(path.js.app.concat(["!"+path.peg.replace("pegjs","js")]), path.opts)
2014-09-13 23:21:13 +00:00
.pipe(dont_break_on_errors())
.pipe(react())
2014-09-13 15:00:05 +00:00
.pipe(jshint())
.pipe(jshint.reporter("jshint-stylish"));
2014-09-13 15:00:05 +00:00
});
2014-12-12 16:49:10 +00:00
gulp.task("peg", function () {
return gulp.src(path.peg, path.opts)
.pipe(dont_break_on_errors())
.pipe(peg({exportVar:"Filt"}))
.pipe(gulp.dest(".", path.opts));
});
2014-09-17 21:59:39 +00:00
gulp.task("images", function () {
//(spriting code in commit 4ca720b55680e40b3a4361141a2ad39f9de81111)
2014-12-12 16:49:10 +00:00
return gulp.src(path.images, path.opts)
.pipe(gulp.dest(path.dist + "static"));
});
2014-09-13 15:00:05 +00:00
gulp.task("html", function () {
2014-12-12 16:49:10 +00:00
return gulp.src(path.html, path.opts)
2014-09-15 16:39:25 +00:00
.pipe(gulp.dest(path.dist + "templates"))
2014-12-12 16:49:10 +00:00
.pipe(livereload({auto: false}));
2014-09-13 15:00:05 +00:00
});
2014-12-12 16:49:10 +00:00
gulp.task('test', function () {
return gulp.src(path.test, path.opts)
2014-09-13 23:21:13 +00:00
.pipe(qunit({verbose: true}));
});
2014-12-12 16:49:10 +00:00
common = ["fonts", "html", "jshint", "peg", "images"];
2014-09-13 15:00:05 +00:00
gulp.task("dev", common.concat(["styles-dev", "scripts-dev"]));
gulp.task("prod", common.concat(["styles-prod", "scripts-prod"]));
gulp.task("default", ["dev"], function () {
livereload.listen({auto: true});
2014-12-12 16:49:10 +00:00
gulp.watch(path.vendor, path.opts, ["scripts-vendor-dev", "styles-vendor-dev"]);
gulp.watch(path.js.app, path.opts, ["scripts-app-dev", "jshint"]);
gulp.watch(path.peg, path.opts, ["peg"]);
gulp.watch(path.css.all, path.opts, ["styles-app-dev"]);
gulp.watch(path.html, path.opts, ["html"]);
2014-09-15 16:08:26 +00:00
});