2020-04-21 11:23:18 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2020-04-28 09:04:28 +02:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const tsify = require("tsify");
|
|
|
|
const sourcemaps = require("gulp-sourcemaps");
|
|
|
|
const rename = require("gulp-rename");
|
|
|
|
const browserify = require("browserify");
|
|
|
|
const source = require("vinyl-source-stream");
|
|
|
|
const buffer = require("vinyl-buffer");
|
|
|
|
const terser = require("gulp-terser");
|
|
|
|
const eslint = require("gulp-eslint");
|
|
|
|
const babelify = require("babelify");
|
|
|
|
const htmlmin = require("gulp-html-minifier-terser");
|
2020-04-21 11:23:18 +02:00
|
|
|
const htmlvalidator = require("gulp-html");
|
2020-04-15 15:28:42 +02:00
|
|
|
|
|
|
|
const html = () => {
|
2020-04-28 09:04:28 +02:00
|
|
|
return gulp
|
|
|
|
.src("src/index.html")
|
2020-04-15 15:28:42 +02:00
|
|
|
.pipe(htmlvalidator())
|
2020-04-28 09:04:28 +02:00
|
|
|
.pipe(
|
|
|
|
htmlmin({
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseInlineTagWhitespace: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
}),
|
|
|
|
)
|
2020-04-21 11:23:18 +02:00
|
|
|
.pipe(gulp.dest("dist"));
|
|
|
|
};
|
2020-04-15 15:28:42 +02:00
|
|
|
|
|
|
|
const js = () => {
|
2020-04-28 09:04:28 +02:00
|
|
|
gulp
|
|
|
|
.src(["src/**/*.ts", "!node_modules/**"])
|
|
|
|
.pipe(eslint({ quiet: true }))
|
|
|
|
.pipe(
|
|
|
|
eslint.results(results => {
|
|
|
|
// Called once for all ESLint results.
|
|
|
|
console.log("ESLint results:\n");
|
|
|
|
console.log(`Total Errors: ${results.errorCount}`);
|
|
|
|
let output = "";
|
|
|
|
results.forEach(file => {
|
|
|
|
output += file.filePath + "\n";
|
|
|
|
file.messages.forEach(message => {
|
|
|
|
output +=
|
|
|
|
" - " +
|
|
|
|
message.message +
|
|
|
|
" at " +
|
|
|
|
message.line +
|
|
|
|
":" +
|
|
|
|
message.column +
|
|
|
|
"\n";
|
|
|
|
});
|
|
|
|
output += "\n";
|
2020-04-21 11:23:18 +02:00
|
|
|
});
|
2020-04-28 09:04:28 +02:00
|
|
|
console.error(output);
|
|
|
|
}),
|
|
|
|
);
|
2020-04-15 15:28:42 +02:00
|
|
|
|
2020-04-21 11:23:18 +02:00
|
|
|
return browserify("src/index.ts")
|
|
|
|
.plugin(tsify, { noImplicitAny: true, target: "es6" })
|
2020-04-28 09:04:28 +02:00
|
|
|
.transform(babelify, { extensions: [".tsx", ".ts"] })
|
|
|
|
.bundle()
|
|
|
|
.on("error", e => console.error(e))
|
2020-04-21 11:23:18 +02:00
|
|
|
.pipe(source("output.js"))
|
|
|
|
.pipe(gulp.dest("dist"))
|
|
|
|
.pipe(buffer())
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(terser())
|
|
|
|
.pipe(rename({ extname: ".min.js" }))
|
|
|
|
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
|
|
|
|
.pipe(gulp.dest("dist"));
|
|
|
|
};
|
|
|
|
|
|
|
|
const res = () => {
|
2020-04-28 09:04:28 +02:00
|
|
|
return gulp.src("src/res/**/*.*").pipe(gulp.dest("dist"));
|
2020-04-15 15:28:42 +02:00
|
|
|
};
|
|
|
|
|
2020-04-21 11:23:18 +02:00
|
|
|
exports.default = gulp.parallel(js, html, res);
|
|
|
|
|
|
|
|
exports.watch = () => {
|
2020-04-28 09:04:28 +02:00
|
|
|
console.log("Ready for changes!");
|
2020-04-21 11:23:18 +02:00
|
|
|
gulp.watch(["src/**/*.js", "src/**/*.ts"], js);
|
|
|
|
gulp.watch("src/*.html", html);
|
2020-04-28 09:04:28 +02:00
|
|
|
gulp.watch("res/**/*.*", res);
|
2020-04-21 11:23:18 +02:00
|
|
|
};
|
2020-04-28 09:04:28 +02:00
|
|
|
|