diff --git a/gulpfile.cjs b/gulpfile.cjs index 293775b..dc74e35 100644 --- a/gulpfile.cjs +++ b/gulpfile.cjs @@ -1,40 +1,12 @@ 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; const rimraf = require("rimraf"); const plumber = require("gulp-plumber"); const sourcemaps = require("gulp-sourcemaps"); const fs = require("fs"); -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: true, - minify: false, -}; +const {swcDir} = require("@swc/cli"); gulp.task( "watch", @@ -49,25 +21,34 @@ gulp.task( gulp.task("clean", (cb) => { return rimraf.rimraf("dist").then(cb()); }); -const exec = require("child_process").exec; + // Task to compile TypeScript files using SWC gulp.task("scripts", async () => { - if (argv.swc) { - return gulp - .src("src/**/*.ts") - .pipe(sourcemaps.init()) - .pipe(plumber()) // Prevent pipe breaking caused by errors - .pipe(swc(swcOptions)) - .pipe(sourcemaps.write(".")) - .pipe(gulp.dest("dist")); - } else if (argv.bunswc) { + if (argv.swc || 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) { - ret(); + swcDir({ + cliOptions: { + outDir: "./dist", + watch: true, + filenames: ["./src"], + extensions: [".ts"], + stripLeadingPaths: true, + "no-swcrc": true, }, - ); + callbacks: { + onSuccess: (e) => { + ret(); + console.log(e); + }, + onFail: (e) => { + for ([, reason] of e.reasons) { + console.log(reason); + } + ret(); + }, + onWatchReady: () => {}, + }, + }); }); } else { console.warn("[WARN] Using TSC compiler, will be slower than SWC"); diff --git a/package.json b/package.json index e82819f..75c263d 100644 --- a/package.json +++ b/package.json @@ -1,55 +1,54 @@ { - "name": "jankclient", - "version": "0.2.0", - "description": "A SpaceBar Client written in TS HTML and CSS to run, clone the repo and do either `npm start` or `bun start` both bun and node are supported, and both should function as expected. To access Jank Client after init simply go to http://localhost:8080/login and login with your username and password.", - "main": ".dist/index.js", - "type": "module", - "scripts": { - "lint": "eslint .", - "build": "npx gulp", - "start": "node dist/index.js" - }, - "author": "MathMan05", - "license": "GPL-3.0", - "dependencies": { - "compression": "^1.7.4", - "express": "^4.19.2", - "gulp-sourcemaps": "^2.6.5", - "gulp-swc": "^2.2.0", - "prettier": "^3.4.2", - "rimraf": "^6.0.1" - }, - "prettier":{ - "useTabs":true, - "printWidth":100, - "semi":true, - "bracketSpacing":false - }, - "devDependencies": { - "@eslint/js": "^9.10.0", - "@html-eslint/eslint-plugin": "^0.25.0", - "@html-eslint/parser": "^0.27.0", - "@rsbuild/core": "^1.1.4", - "@rsbuild/plugin-node-polyfill": "^1.2.0", - "@stylistic/eslint-plugin": "^2.3.0", - "@stylistic/eslint-plugin-js": "^2.8.0", - "@swc/cli": "^0.5.2", - "@swc/core": "^1.10.1", - "@types/compression": "^1.7.5", - "@types/eslint__js": "^8.42.3", - "@types/express": "^4.17.21", - "@types/node-fetch": "^2.6.11", - "@typescript-eslint/eslint-plugin": "^8.14.0", - "@typescript-eslint/parser": "^8.14.0", - "eslint": "^8.57.1", - "eslint-plugin-html": "^8.1.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.14.0" - } + "name": "jankclient", + "version": "0.2.0", + "description": "A SpaceBar Client written in TS HTML and CSS to run, clone the repo and do either `npm start` or `bun start` both bun and node are supported, and both should function as expected. To access Jank Client after init simply go to http://localhost:8080/login and login with your username and password.", + "main": ".dist/index.js", + "type": "module", + "scripts": { + "lint": "eslint .", + "build": "npx gulp", + "start": "node dist/index.js" + }, + "author": "MathMan05", + "license": "GPL-3.0", + "dependencies": { + "compression": "^1.7.4", + "express": "^4.19.2", + "gulp-sourcemaps": "^2.6.5", + "prettier": "^3.4.2", + "rimraf": "^6.0.1" + }, + "prettier": { + "useTabs": true, + "printWidth": 100, + "semi": true, + "bracketSpacing": false + }, + "devDependencies": { + "@eslint/js": "^9.10.0", + "@html-eslint/eslint-plugin": "^0.25.0", + "@html-eslint/parser": "^0.27.0", + "@rsbuild/core": "^1.1.4", + "@rsbuild/plugin-node-polyfill": "^1.2.0", + "@stylistic/eslint-plugin": "^2.3.0", + "@stylistic/eslint-plugin-js": "^2.8.0", + "@swc/cli": "^0.5.2", + "@swc/core": "^1.10.1", + "@types/compression": "^1.7.5", + "@types/eslint__js": "^8.42.3", + "@types/express": "^4.17.21", + "@types/node-fetch": "^2.6.11", + "@typescript-eslint/eslint-plugin": "^8.14.0", + "@typescript-eslint/parser": "^8.14.0", + "eslint": "^8.57.1", + "eslint-plugin-html": "^8.1.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.14.0" + } }