mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 15:26:15 +08:00
1877cc31e7
* Replaced browserify with webpack * Modified gulpfile and webpack config * Removed attempts of using undefined variables and functions * fixed some incorrect changes * setfunbox fix * Added fallback for crypto-browserify and stream-browserify * added circular dependency detection * Created production tasks for gulp and updated webpack config * fixed circular dependency in misc * not failing on circular dependency * Removed unused imports * Added babel loader and plugins to webpack * Removed unused dependencies and removed babel's plugins * Workaround for test logic import in random quote * Created a separate webpack config file for production * Changed relative paths to absolute ones in webpack * Added colored output for circular import number * Removed comment from .eslintrc.json * Added eslint plugin to webpack * Moved 'buffer' and 'stream-browserify' to devDependencies * Started using promises in webpack tasks * Removed unused dependencies * Updated package-lock.json * Removed eslint plugin from webpack and added circular dependency detection in dev config as well * Removed unrelated changes * Updated production build command * Added ability for webpack to be run with typescript conversion of project in process * added gulp typscript dev dependency * using const * modified console logs on circular imports * missing dev dependency Co-authored-by: Miodec <bartnikjack@gmail.com>
157 lines
3.7 KiB
JavaScript
157 lines
3.7 KiB
JavaScript
const { task, src, dest, series, watch } = require("gulp");
|
|
// const axios = require("axios");
|
|
const concat = require("gulp-concat");
|
|
const del = require("del");
|
|
const vinylPaths = require("vinyl-paths");
|
|
const eslint = require("gulp-eslint-new");
|
|
const sass = require("gulp-sass")(require("dart-sass"));
|
|
const replace = require("gulp-replace");
|
|
const through2 = require("through2");
|
|
const { webpack } = require("webpack");
|
|
const webpackDevConfig = require("./webpack.config.js");
|
|
const webpackProdConfig = require("./webpack-production.config.js");
|
|
const ts = require("gulp-typescript");
|
|
// sass.compiler = require("dart-sass");
|
|
|
|
let eslintConfig = "../.eslintrc.json";
|
|
let tsProject = ts.createProject("tsconfig.json");
|
|
// console.log(tsProject.src())
|
|
|
|
task("clean", function () {
|
|
return src(["./public/"], { allowEmpty: true }).pipe(vinylPaths(del));
|
|
});
|
|
|
|
task("lint", function () {
|
|
return src(["./src/js/**/*.js", "./src/js/**/*.ts"])
|
|
.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("copy-src-contents", function () {
|
|
return src("./src/js/**").pipe(dest("./dist/"));
|
|
});
|
|
|
|
task("transpile-ts", function () {
|
|
return tsProject.src().pipe(tsProject()).js.pipe(dest("dist"));
|
|
});
|
|
|
|
task("webpack", async function () {
|
|
return new Promise((resolve, reject) => {
|
|
webpack(webpackDevConfig, (err, stats) => {
|
|
if (err) {
|
|
return reject(err);
|
|
}
|
|
if (stats.hasErrors()) {
|
|
return reject(new Error(stats.compilation.errors.join("\n")));
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
|
|
task("webpack-production", async function () {
|
|
return new Promise((resolve, reject) => {
|
|
webpack(webpackProdConfig, (err, stats) => {
|
|
if (err) {
|
|
return reject(err);
|
|
}
|
|
if (stats.hasErrors()) {
|
|
return reject(new Error(stats.compilation.errors.join("\n")));
|
|
}
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
|
|
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 () {
|
|
const date = new Date();
|
|
const 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) {
|
|
const date = new Date();
|
|
file.stat.atime = date;
|
|
file.stat.mtime = date;
|
|
cb(null, file);
|
|
})
|
|
)
|
|
.pipe(dest("./public/"));
|
|
});
|
|
|
|
task(
|
|
"compile",
|
|
series(
|
|
"lint",
|
|
"lint-json",
|
|
"copy-src-contents",
|
|
"transpile-ts",
|
|
"webpack",
|
|
"static",
|
|
"sass",
|
|
"updateSwCacheName"
|
|
)
|
|
);
|
|
|
|
task(
|
|
"compile-production",
|
|
series(
|
|
"lint",
|
|
"lint-json",
|
|
"copy-src-contents",
|
|
"transpile-ts",
|
|
"webpack-production",
|
|
"static",
|
|
"sass",
|
|
"updateSwCacheName"
|
|
)
|
|
);
|
|
|
|
task("watch", function () {
|
|
watch("./src/sass/**/*.scss", series("sass"));
|
|
watch(
|
|
["./src/js/**/*.js", "./src/js/**/*.ts"],
|
|
series("lint", "copy-src-contents", "transpile-ts", "webpack")
|
|
);
|
|
watch("./static/**/*.*", series("lint-json", "static"));
|
|
});
|
|
|
|
task("build", series("clean", "compile"));
|
|
task("build-production", series("clean", "compile-production"));
|