update and format gulp file

This commit is contained in:
MathMan05 2025-01-13 13:15:09 -06:00
parent 61d2fde512
commit 5fad44077c

View file

@ -5,7 +5,7 @@ const tsProject = ts.createProject("tsconfig.json");
const argv = require("yargs").argv;
const rimraf = require("rimraf");
const plumber = require("gulp-plumber");
const sourcemaps = require('gulp-sourcemaps');
const sourcemaps = require("gulp-sourcemaps");
const fs = require("fs");
const swcOptions = {
jsc: {
@ -36,18 +36,20 @@ jsc: {
minify: false,
};
gulp.task('watch', function () {
gulp.watch('./src', gulp.series("default"));
gulp.watch('./translations', gulp.series("default"));
}, {debounceDelay: 10});
gulp.task(
"watch",
function () {
gulp.watch("./src", gulp.series("default"));
gulp.watch("./translations", gulp.series("default"));
},
{debounceDelay: 10},
);
// Clean task to delete the dist directory
gulp.task("clean", (cb) => {
return rimraf.rimraf("dist").then(cb());
});
const exec = require('child_process').exec;
const exec = require("child_process").exec;
// Task to compile TypeScript files using SWC
gulp.task("scripts", async () => {
if (argv.swc) {
@ -56,14 +58,17 @@ gulp.task("clean", (cb) => {
.pipe(sourcemaps.init())
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(swc(swcOptions))
.pipe(sourcemaps.write('.'))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
} else if (argv.bunswc) {
return await new Promise(ret=>{
exec("bun swc --strip-leading-paths ./src -s -d ./dist/ -C jsc.target=es2022").on('exit', function (code) {
return await new Promise((ret) => {
exec("bun swc --strip-leading-paths ./src -s -d ./dist/ -C jsc.target=es2022").on(
"exit",
function (code) {
ret();
},
);
});
})
} else {
console.warn("[WARN] Using TSC compiler, will be slower than SWC");
return gulp
@ -71,7 +76,7 @@ gulp.task("clean", (cb) => {
.pipe(sourcemaps.init())
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(tsProject())
.pipe(sourcemaps.write('.'))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
}
});
@ -91,8 +96,11 @@ for(const lang of langs){
const json = JSON.parse(fs.readFileSync("translations/" + lang).toString());
langobj[lang] = json.readableName;
}
if(!fs.existsSync("dist/webpage/translations")) fs.mkdirSync("dist/webpage/translations")
fs.writeFileSync("dist/webpage/translations/langs.js",`const langs=${JSON.stringify(langobj)};export{langs}`);
if (!fs.existsSync("dist/webpage/translations")) fs.mkdirSync("dist/webpage/translations");
fs.writeFileSync(
"dist/webpage/translations/langs.js",
`const langs=${JSON.stringify(langobj)};export{langs}`,
);
return gulp
.src("translations/*.json")
.pipe(plumber()) // Prevent pipe breaking caused by errors
@ -101,7 +109,8 @@ return gulp
// Task to copy other static assets (e.g., CSS, images)
gulp.task("copy-assets", () => {
return gulp
.src([
.src(
[
"src/**/*.css",
"src/**/*.bin",
"src/**/*.ico",
@ -114,7 +123,10 @@ return gulp
"src/**/*.gif",
"src/**/*.svg",
"src/**/*.jasf",
],{encoding:false})
"src/**/*.txt",
],
{encoding: false},
)
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist"));
});
@ -122,5 +134,5 @@ return gulp
// Default task to run all tasks
gulp.task(
"default",
gulp.series("clean", gulp.parallel("scripts", "copy-html", "copy-assets"), "copy-translations")
gulp.series("clean", gulp.parallel("scripts", "copy-html", "copy-assets"), "copy-translations"),
);