[bugfix]: Removed eslint.FailOnError()

Gulp watch would exit with 1 in gulp watch. The command had to to be rerun to start gulp again.
This commit is contained in:
corner 2020-04-28 09:04:28 +02:00
parent 483582842a
commit 3f93c9f1dc

View File

@ -1,57 +1,67 @@
/* eslint-disable @typescript-eslint/no-var-requires */ /* eslint-disable @typescript-eslint/no-var-requires */
const gulp = require("gulp"); const gulp = require("gulp");
const tsify = require("tsify"); const tsify = require("tsify");
const sourcemaps = require("gulp-sourcemaps"); const sourcemaps = require("gulp-sourcemaps");
const rename = require("gulp-rename"); const rename = require("gulp-rename");
const browserify = require("browserify"); const browserify = require("browserify");
const source = require("vinyl-source-stream"); const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer"); const buffer = require("vinyl-buffer");
const terser = require("gulp-terser"); const terser = require("gulp-terser");
const eslint = require("gulp-eslint"); const eslint = require("gulp-eslint");
const babelify = require("babelify"); const babelify = require("babelify");
const htmlmin = require("gulp-html-minifier-terser"); const htmlmin = require("gulp-html-minifier-terser");
const htmlvalidator = require("gulp-html"); const htmlvalidator = require("gulp-html");
const imagemin = require('gulp-imagemin');
const gulpif = require('gulp-if');
const clean = require('gulp-dest-clean');
const html = () => { const html = () => {
return gulp.src("src/index.html") return gulp
.src("src/index.html")
.pipe(htmlvalidator()) .pipe(htmlvalidator())
.pipe(htmlmin({ .pipe(
removeComments: true, htmlmin({
collapseWhitespace: true, removeComments: true,
collapseBooleanAttributes: true, collapseWhitespace: true,
collapseInlineTagWhitespace: true, collapseBooleanAttributes: true,
removeRedundantAttributes: true, collapseInlineTagWhitespace: true,
minifyCSS: true removeRedundantAttributes: true,
})) minifyCSS: true,
}),
)
.pipe(gulp.dest("dist")); .pipe(gulp.dest("dist"));
}; };
const js = () => { const js = () => {
gulp.src(["src/**/*.ts", "!node_modules/**"]) gulp
.pipe(eslint({quiet: true})) .src(["src/**/*.ts", "!node_modules/**"])
.pipe(eslint.results(results => { .pipe(eslint({ quiet: true }))
// Called once for all ESLint results. .pipe(
console.log("ESLint results:\n"); eslint.results(results => {
console.log(`Total Errors: ${results.errorCount}`); // Called once for all ESLint results.
let output = ""; console.log("ESLint results:\n");
results.forEach(file => { console.log(`Total Errors: ${results.errorCount}`);
output += file.filePath + "\n"; let output = "";
file.messages.forEach(message => { results.forEach(file => {
output += " - " + message.message + " at " + message.line + ":" + message.column + "\n"; output += file.filePath + "\n";
file.messages.forEach(message => {
output +=
" - " +
message.message +
" at " +
message.line +
":" +
message.column +
"\n";
});
output += "\n";
}); });
output += "\n"; console.error(output);
}); }),
console.error(output); );
}))
.pipe(eslint.failAfterError());
return browserify("src/index.ts") return browserify("src/index.ts")
.plugin(tsify, { noImplicitAny: true, target: "es6" }) .plugin(tsify, { noImplicitAny: true, target: "es6" })
.transform(babelify, { extensions: [ ".tsx", ".ts" ] }) .transform(babelify, { extensions: [".tsx", ".ts"] })
.bundle().on("error", (e) => console.error(e)) .bundle()
.on("error", e => console.error(e))
.pipe(source("output.js")) .pipe(source("output.js"))
.pipe(gulp.dest("dist")) .pipe(gulp.dest("dist"))
.pipe(buffer()) .pipe(buffer())
@ -63,24 +73,15 @@ const js = () => {
}; };
const res = () => { const res = () => {
return gulp.src("src/res/*") return gulp.src("src/res/**/*.*").pipe(gulp.dest("dist"));
.pipe(clean("dist/res"))
.pipe(gulpif(
file => file.basename.match(/\.png|jpg|jpeg|gif|svg/gmi) !== [],
imagemin()
))
.pipe(gulp.dest("dist/res"));
}; };
exports.default = gulp.parallel(js, html, res); exports.default = gulp.parallel(js, html, res);
exports.watch = () => { exports.watch = () => {
console.log("Transpiling current files..."); console.log("Ready for changes!");
js();
html();
res();
console.log("Watching for changes!");
gulp.watch(["src/**/*.js", "src/**/*.ts"], js); gulp.watch(["src/**/*.js", "src/**/*.ts"], js);
gulp.watch("src/*.html", html); gulp.watch("src/*.html", html);
gulp.watch("src/res/*", res); gulp.watch("res/**/*.*", res);
}; };