diff options
author | Bruce Berrios <[email protected]> | 2022-02-08 14:33:41 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2022-02-08 20:33:41 +0100 |
commit | 345740db5f07b27a73af766facddbc1a04de3f6e (patch) | |
tree | 6946c88f2cc8ad627fe29e068430c2532b872d9e /frontend/gulpfile.js | |
parent | c4e62dddfb8b2491b76d9027fc15359b67dcffb4 (diff) | |
download | monkeytype-345740db5f07b27a73af766facddbc1a04de3f6e.tar.gz monkeytype-345740db5f07b27a73af766facddbc1a04de3f6e.zip |
Separate backend and frontend dependencies (#2441) by Bruception
* Add request validation to user endpoints
* Remove tag id log
* Remove verbs from endpoints
* Remove old code
* Remove uid
* Fix
* Remove name from URI
* Rename utils
* Fix
* Move prettier
* Update gulp file
* Add additional scripts
* Update package-lock
* Update contributing.md
Co-authored-by: Miodec <[email protected]>
Diffstat (limited to 'frontend/gulpfile.js')
-rw-r--r-- | frontend/gulpfile.js | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/frontend/gulpfile.js b/frontend/gulpfile.js new file mode 100644 index 000000000..fdeb7b57b --- /dev/null +++ b/frontend/gulpfile.js @@ -0,0 +1,123 @@ +const { task, src, dest, series, watch } = require("gulp"); +// const axios = require("axios"); +const browserify = require("browserify"); +const babelify = require("babelify"); +const concat = require("gulp-concat"); +const del = require("del"); +const source = require("vinyl-source-stream"); +const buffer = require("vinyl-buffer"); +const vinylPaths = require("vinyl-paths"); +const eslint = require("gulp-eslint-new"); +var sass = require("gulp-sass")(require("dart-sass")); +const replace = require("gulp-replace"); +const uglify = require("gulp-uglify"); +const through2 = require("through2"); +// sass.compiler = require("dart-sass"); + +let eslintConfig = "../.eslintrc.json"; + +task("clean", function () { + return src(["./public/"], { allowEmpty: true }).pipe(vinylPaths(del)); +}); + +task("lint-js", function () { + return src("./src/js/**/*.js") + .pipe(eslint(eslintConfig)) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +task("lint-json", function () { + return src("./static/**/*.json") + .pipe(eslint(eslintConfig)) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +task("browserify", function () { + const b = browserify({ + entries: "./src/js/index.js", + //a source map isn't very useful right now because + //the source files are concatenated together + debug: false, + }); + return b + .transform( + babelify.configure({ + presets: ["@babel/preset-env"], + plugins: ["@babel/transform-runtime"], + }) + ) + .bundle() + .pipe(source("monkeytype.js")) + .pipe(buffer()) + .pipe( + uglify({ + mangle: false, + }) + ) + .pipe(dest("./public/js")); +}); + +task("static", function () { + return src("./static/**/*", { dot: true }).pipe(dest("./public/")); +}); + +task("sass", function () { + return src("./src/sass/*.scss") + .pipe(concat("style.scss")) + .pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError)) + .pipe(dest("public/css")); +}); + +task("updateSwCacheName", function () { + let date = new Date(); + let dateString = + date.getFullYear() + + "-" + + (date.getMonth() + 1) + + "-" + + date.getDate() + + "-" + + date.getHours() + + "-" + + date.getMinutes() + + "-" + + date.getSeconds(); + return src(["static/sw.js"]) + .pipe( + replace( + /const staticCacheName = .*;/g, + `const staticCacheName = "sw-cache-${dateString}";` + ) + ) + .pipe( + through2.obj(function (file, enc, cb) { + var date = new Date(); + file.stat.atime = date; + file.stat.mtime = date; + cb(null, file); + }) + ) + .pipe(dest("./public/")); +}); + +task( + "compile", + series( + "lint-js", + "lint-json", + "browserify", + "static", + "sass", + "updateSwCacheName" + ) +); + +task("watch", function () { + watch("./src/sass/**/*.scss", series("sass")); + watch("./src/js/**/*.js", series("lint-js", "browserify")); + watch("./static/**/*.*", series("lint-json", "static")); +}); + +task("build", series("clean", "compile")); |