

diff --git a/build.ts b/build.ts
index de27c9c..265c359 100644
--- a/build.ts
+++ b/build.ts
@@ -1,20 +1,52 @@
+import { $, build } from 'bun';
import { readdirSync, statSync, writeFileSync } from 'fs';
import { join } from 'path';
+import chalk from 'chalk';
-const directoryPath = join(import.meta.dir, 'public');
-
-function getFiles(directory: string, filesArr?: string[]) {
+function getFiles(baseDir: string, dir?: string, filesArr?: string[]) {
+ dir = dir || baseDir;
filesArr = filesArr || [];
- const files = readdirSync(directory);
+ const files = readdirSync(dir);
for (const file of files) {
- const name = join(directory, file);
+ const name = join(dir, file);
if (statSync(name).isDirectory()) {
- getFiles(name, filesArr);
+ getFiles(baseDir, name, filesArr);
} else {
- filesArr.push(name.replace(new RegExp(`^${directoryPath}`), '').replace(/\/index\.html$/, '/'));
+ filesArr.push(name);
}
}
return filesArr;
}
-writeFileSync(join(directoryPath, 'assets.json'), JSON.stringify(getFiles(directoryPath)));
+console.log(chalk.cyan('Linting code...\n'));
+const lintOutput = await $`bunx eslint ./src/`.nothrow().text();
+if (lintOutput) {
+ console.error(lintOutput);
+ process.exit(1);
+}
+
+console.log(chalk.cyan('Removing old build artifacts...\n'));
+await $`rm -rf ./public/resources/scripts/ ./public/assets.json ./public/sw.js ./public/sw-full.js`.quiet();
+
+console.log(chalk.cyan('Bundling TypeScript and modules...\n'));
+const srcFilesArr = getFiles(join(import.meta.dir, 'src'));
+await build({
+ entrypoints: srcFilesArr,
+ outdir: './public/',
+ root: './src/',
+ minify: true,
+});
+
+console.log(chalk.cyan('Obfuscating JavaScript...\n'));
+await $`bunx javascript-obfuscator ./public/resources/scripts/ --output ./public/resources/scripts/ --options-preset high-obfuscation`.quiet();
+
+console.log(chalk.cyan('Generating assets list...\n'));
+const publicDir = join(import.meta.dir, 'public');
+writeFileSync(
+ join(publicDir, 'assets.json'),
+ JSON.stringify(getFiles(publicDir))
+ .replace(new RegExp(`^${publicDir}`), '')
+ .replace(/\/index\.html$/, '/')
+);
+
+console.log(chalk.green('Build complete!\n'));
diff --git a/bun.lockb b/bun.lockb
index 08f5dea..8c868d3 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/index.ts b/index.ts
index 63a193c..e0ed6fe 100644
--- a/index.ts
+++ b/index.ts
@@ -1,7 +1,7 @@
import { join } from 'path';
import { env } from 'bun';
import express, { json, urlencoded } from 'express';
-import chalk from 'chalk'
+import chalk from 'chalk';
import compression from 'compression';
import cookieParser from 'cookie-parser';
import debug from 'debug';
@@ -30,7 +30,7 @@ app.use(
})
);
-app.use(morgan('combined'));
+app.use(morgan(isDev ? 'dev' : 'combined'));
app.use(json());
app.use(urlencoded({ extended: false }));
diff --git a/package.json b/package.json
index 6c29a3b..ccb7b48 100644
--- a/package.json
+++ b/package.json
@@ -5,10 +5,10 @@
"type": "module",
"scripts": {
"start": "NODE_ENV=production bun run ./index.ts",
- "dev": "NODE_ENV=development DEBUG=app:* bun --watch run ./index.ts",
+ "dev": "NODE_ENV=development DEBUG=app:* bun --hot run ./index.ts",
"lint": "eslint ./src/",
"lint:fix": "eslint --fix ./src/",
- "build": "bun run lint; rm -rf ./public/resources/scripts/ ./public/assets.json; tsc; javascript-obfuscator ./public/resources/scripts/ --output ./public/resources/scripts/ --options-preset high-obfuscation; bun run ./build.ts"
+ "build": "bun run ./build.ts"
},
"dependencies": {
"chalk": "^5.3.0",
@@ -19,6 +19,7 @@
"express": "^4.19.2",
"helmet": "^7.1.0",
"morgan": "^1.10.0",
+ "semver": "^7.6.3",
"serve-favicon": "^2.5.0"
},
"devDependencies": {
@@ -29,12 +30,13 @@
"@types/debug": "^4.1.12",
"@types/errorhandler": "^1.5.3",
"@types/morgan": "^1.9.9",
+ "@types/semver": "^7.5.8",
"@types/serve-favicon": "^2.5.7",
"eslint": "^9.9.1",
"javascript-obfuscator": "^4.1.1",
"typescript-eslint": "^8.3.0"
},
"peerDependencies": {
- "typescript": "^5.0.0"
+ "typescript": "^5.5.4"
}
}
diff --git a/public/home/archive/index.html b/public/home/archive/index.html
index f062734..cc176a1 100644
--- a/public/home/archive/index.html
+++ b/public/home/archive/index.html
@@ -36,7 +36,7 @@
-