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,122 +5,134 @@ const tsProject = ts.createProject("tsconfig.json");
const argv = require("yargs").argv; const argv = require("yargs").argv;
const rimraf = require("rimraf"); const rimraf = require("rimraf");
const plumber = require("gulp-plumber"); const plumber = require("gulp-plumber");
const sourcemaps = require('gulp-sourcemaps'); const sourcemaps = require("gulp-sourcemaps");
const fs=require("fs"); const fs = require("fs");
const swcOptions = { const swcOptions = {
jsc: { jsc: {
parser: { parser: {
syntax: "typescript", syntax: "typescript",
tsx: false, tsx: false,
decorators: true, decorators: true,
dynamicImport: true, dynamicImport: true,
}, },
transform: { transform: {
react: { react: {
runtime: "automatic", runtime: "automatic",
}, },
}, },
target: "es2022", target: "es2022",
loose: false, loose: false,
externalHelpers: false, externalHelpers: false,
keepClassNames: true, keepClassNames: true,
}, },
module: { module: {
type: "es6", type: "es6",
strict: true, strict: true,
strictMode: true, strictMode: true,
lazy: false, lazy: false,
noInterop: false, noInterop: false,
}, },
sourceMaps: true, sourceMaps: true,
minify: false, minify: false,
}; };
gulp.task(
"watch",
gulp.task('watch', function () { function () {
gulp.watch('./src', gulp.series("default")); gulp.watch("./src", gulp.series("default"));
gulp.watch('./translations', gulp.series("default")); gulp.watch("./translations", gulp.series("default"));
}, {debounceDelay: 10}); },
{debounceDelay: 10},
);
// Clean task to delete the dist directory // Clean task to delete the dist directory
gulp.task("clean", (cb) => { gulp.task("clean", (cb) => {
return rimraf.rimraf("dist").then(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 // Task to compile TypeScript files using SWC
gulp.task("scripts", async () => { gulp.task("scripts", async () => {
if (argv.swc) { if (argv.swc) {
return gulp return gulp
.src("src/**/*.ts") .src("src/**/*.ts")
.pipe(sourcemaps.init()) .pipe(sourcemaps.init())
.pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(swc(swcOptions)) .pipe(swc(swcOptions))
.pipe(sourcemaps.write('.')) .pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist")); .pipe(gulp.dest("dist"));
} else if(argv.bunswc){ } else if (argv.bunswc) {
return await new Promise(ret=>{ return await new Promise((ret) => {
exec("bun swc --strip-leading-paths ./src -s -d ./dist/ -C jsc.target=es2022").on('exit', function (code) { exec("bun swc --strip-leading-paths ./src -s -d ./dist/ -C jsc.target=es2022").on(
ret(); "exit",
}); function (code) {
}) ret();
}else { },
console.warn("[WARN] Using TSC compiler, will be slower than SWC"); );
return gulp });
.src("src/**/*.ts") } else {
.pipe(sourcemaps.init()) console.warn("[WARN] Using TSC compiler, will be slower than SWC");
.pipe(plumber()) // Prevent pipe breaking caused by errors return gulp
.pipe(tsProject()) .src("src/**/*.ts")
.pipe(sourcemaps.write('.')) .pipe(sourcemaps.init())
.pipe(gulp.dest("dist")); .pipe(plumber()) // Prevent pipe breaking caused by errors
} .pipe(tsProject())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
}
}); });
// Task to copy HTML files // Task to copy HTML files
gulp.task("copy-html", () => { gulp.task("copy-html", () => {
return gulp return gulp
.src("src/**/*.html") .src("src/**/*.html")
.pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist")); .pipe(gulp.dest("dist"));
}); });
gulp.task("copy-translations", () => { gulp.task("copy-translations", () => {
let langs=fs.readdirSync("translations"); let langs = fs.readdirSync("translations");
langs=langs.filter((e)=>e!=="qqq.json"); langs = langs.filter((e) => e !== "qqq.json");
const langobj={}; const langobj = {};
for(const lang of langs){ for (const lang of langs) {
const json=JSON.parse(fs.readFileSync("translations/"+lang).toString()); const json = JSON.parse(fs.readFileSync("translations/" + lang).toString());
langobj[lang]=json.readableName; langobj[lang] = json.readableName;
} }
if(!fs.existsSync("dist/webpage/translations")) fs.mkdirSync("dist/webpage/translations") 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}`); fs.writeFileSync(
return gulp "dist/webpage/translations/langs.js",
.src("translations/*.json") `const langs=${JSON.stringify(langobj)};export{langs}`,
.pipe(plumber()) // Prevent pipe breaking caused by errors );
.pipe(gulp.dest("dist/webpage/translations")); return gulp
.src("translations/*.json")
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist/webpage/translations"));
}); });
// Task to copy other static assets (e.g., CSS, images) // Task to copy other static assets (e.g., CSS, images)
gulp.task("copy-assets", () => { gulp.task("copy-assets", () => {
return gulp return gulp
.src([ .src(
"src/**/*.css", [
"src/**/*.bin", "src/**/*.css",
"src/**/*.ico", "src/**/*.bin",
"src/**/*.json", "src/**/*.ico",
"src/**/*.js", "src/**/*.json",
"src/**/*.png", "src/**/*.js",
"src/**/*.jpg", "src/**/*.png",
"src/**/*.jpeg", "src/**/*.jpg",
"src/**/*.webp", "src/**/*.jpeg",
"src/**/*.gif", "src/**/*.webp",
"src/**/*.svg", "src/**/*.gif",
"src/**/*.jasf", "src/**/*.svg",
],{encoding:false}) "src/**/*.jasf",
.pipe(plumber()) // Prevent pipe breaking caused by errors "src/**/*.txt",
.pipe(gulp.dest("dist")); ],
{encoding: false},
)
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist"));
}); });
// Default task to run all tasks // Default task to run all tasks
gulp.task( gulp.task(
"default", "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"),
); );