From be07b20da9c575088300ec36898d87a32f1fddd2 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Thu, 19 Sep 2024 23:55:27 -0400 Subject: [PATCH 1/4] Use SWC by default --- gulpfile.cjs | 43 +++++++++++++++++++++++++++++++++++++++++-- package.json | 2 ++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 2e9f80f..89d11f6 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -1,10 +1,49 @@ const gulp = require("gulp"); const ts = require("gulp-typescript"); +const swc = require("gulp-swc"); const tsProject = ts.createProject("tsconfig.json"); +const argv = require("yargs").argv; -// Task to compile TypeScript files +const swcOptions = { + jsc: { + parser: { + syntax: "typescript", + tsx: false, + decorators: true, + dynamicImport: true, + }, + transform: { + react: { + runtime: "automatic", + }, + }, + target: "es2022", + loose: false, + externalHelpers: false, + keepClassNames: true, + }, + module: { + type: "es6", + strict: true, + strictMode: true, + lazy: false, + noInterop: false, + }, + sourceMaps: "inline", + minify: false, +}; + +// Task to compile TypeScript files using SWC gulp.task("scripts", () => { - return tsProject.src().pipe(tsProject()).js.pipe(gulp.dest("dist")); + if (argv.ts) { + console.warn("[WARN] Using TSC compiler, will be slower than SWC"); + return gulp.src("src/**/*.ts").pipe(tsProject()).pipe(gulp.dest("dist")); + } else { + return gulp + .src("src/**/*.ts") + .pipe(swc(swcOptions)) + .pipe(gulp.dest("dist")); + } }); // Task to copy HTML files diff --git a/package.json b/package.json index f183dfa..0c96608 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,13 @@ "dependencies": { "@html-eslint/parser": "^0.27.0", "@stylistic/eslint-plugin-js": "^2.8.0", + "@swc/core": "^1.7.26", "@typescript-eslint/eslint-plugin": "^8.6.0", "@typescript-eslint/parser": "^8.6.0", "compression": "^1.7.4", "eslint-plugin-html": "^8.1.1", "express": "^4.19.2", + "gulp-swc": "^2.2.0", "node-fetch": "^3.3.2", "ts-to-jsdoc": "^2.2.0" }, From 30b6851f24425e71c17c36df0ee734284f4d1929 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Thu, 19 Sep 2024 23:56:59 -0400 Subject: [PATCH 2/4] Make TSC default --- gulpfile.cjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 89d11f6..695602f 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -35,14 +35,14 @@ const swcOptions = { // Task to compile TypeScript files using SWC gulp.task("scripts", () => { - if (argv.ts) { - console.warn("[WARN] Using TSC compiler, will be slower than SWC"); - return gulp.src("src/**/*.ts").pipe(tsProject()).pipe(gulp.dest("dist")); - } else { + if (argv.swc) { return gulp .src("src/**/*.ts") .pipe(swc(swcOptions)) .pipe(gulp.dest("dist")); + } else { + console.warn("[WARN] Using TSC compiler, will be slower than SWC"); + return gulp.src("src/**/*.ts").pipe(tsProject()).pipe(gulp.dest("dist")); } }); From 6f51acd6675f9fb52c6b65f048d494f8e9faf644 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Fri, 20 Sep 2024 00:04:07 -0400 Subject: [PATCH 3/4] remove dist on install and make most tasks run in parrallel --- gulpfile.cjs | 11 ++++++++++- package.json | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 695602f..047c9b9 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -3,6 +3,7 @@ const ts = require("gulp-typescript"); const swc = require("gulp-swc"); const tsProject = ts.createProject("tsconfig.json"); const argv = require("yargs").argv; +const rimraf = require("rimraf"); const swcOptions = { jsc: { @@ -33,6 +34,11 @@ const swcOptions = { minify: false, }; +// Clean task to delete the dist directory +gulp.task("clean", () => { + return rimraf.rimraf("dist"); +}); + // Task to compile TypeScript files using SWC gulp.task("scripts", () => { if (argv.swc) { @@ -70,4 +76,7 @@ gulp.task("copy-assets", () => { }); // Default task to run all tasks -gulp.task("default", gulp.series("scripts", "copy-html", "copy-assets")); +gulp.task( + "default", + gulp.series("clean", gulp.parallel("scripts", "copy-html", "copy-assets")) +); diff --git a/package.json b/package.json index 0c96608..f19c609 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "express": "^4.19.2", "gulp-swc": "^2.2.0", "node-fetch": "^3.3.2", + "rimraf": "^6.0.1", "ts-to-jsdoc": "^2.2.0" }, "devDependencies": { From c788c03f3d79bbc442ad4d640a62e6edc4f40cd9 Mon Sep 17 00:00:00 2001 From: Scott Gould Date: Fri, 20 Sep 2024 00:11:04 -0400 Subject: [PATCH 4/4] change clean taska bit --- gulpfile.cjs | 18 ++++++++++++++---- package.json | 7 ++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gulpfile.cjs b/gulpfile.cjs index 047c9b9..760ed98 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -4,6 +4,7 @@ const swc = require("gulp-swc"); const tsProject = ts.createProject("tsconfig.json"); const argv = require("yargs").argv; const rimraf = require("rimraf"); +const plumber = require("gulp-plumber"); const swcOptions = { jsc: { @@ -35,8 +36,8 @@ const swcOptions = { }; // Clean task to delete the dist directory -gulp.task("clean", () => { - return rimraf.rimraf("dist"); +gulp.task("clean", (cb) => { + return rimraf.rimraf("dist").then(cb()); }); // Task to compile TypeScript files using SWC @@ -44,17 +45,25 @@ gulp.task("scripts", () => { if (argv.swc) { return gulp .src("src/**/*.ts") + .pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(swc(swcOptions)) .pipe(gulp.dest("dist")); } else { console.warn("[WARN] Using TSC compiler, will be slower than SWC"); - return gulp.src("src/**/*.ts").pipe(tsProject()).pipe(gulp.dest("dist")); + return gulp + .src("src/**/*.ts") + .pipe(plumber()) // Prevent pipe breaking caused by errors + .pipe(tsProject()) + .pipe(gulp.dest("dist")); } }); // Task to copy HTML files gulp.task("copy-html", () => { - return gulp.src("src/**/*.html").pipe(gulp.dest("dist")); + return gulp + .src("src/**/*.html") + .pipe(plumber()) // Prevent pipe breaking caused by errors + .pipe(gulp.dest("dist")); }); // Task to copy other static assets (e.g., CSS, images) @@ -72,6 +81,7 @@ gulp.task("copy-assets", () => { "src/**/*.gif", "src/**/*.svg", ]) + .pipe(plumber()) // Prevent pipe breaking caused by errors .pipe(gulp.dest("dist")); }); diff --git a/package.json b/package.json index f19c609..cead41f 100644 --- a/package.json +++ b/package.json @@ -28,16 +28,17 @@ "devDependencies": { "@eslint/js": "^9.10.0", "@html-eslint/eslint-plugin": "^0.25.0", + "@stylistic/eslint-plugin": "^2.3.0", "@types/compression": "^1.7.5", "@types/eslint__js": "^8.42.3", - "eslint-plugin-sonarjs": "^1.0.4", - "eslint-plugin-unicorn": "^55.0.0", - "@stylistic/eslint-plugin": "^2.3.0", "@types/express": "^4.17.21", "@types/node-fetch": "^2.6.11", "eslint": "^8.57.1", + "eslint-plugin-sonarjs": "^1.0.4", + "eslint-plugin-unicorn": "^55.0.0", "gulp": "^5.0.0", "gulp-copy": "^5.0.0", + "gulp-plumber": "^1.2.1", "gulp-typescript": "^6.0.0-alpha.1", "typescript": "^5.6.2", "typescript-eslint": "^8.6.0"