Merge pull request #7 from nxbat/build-optimisation
(build): Switch to esbuild & transpile to commonjs.
This commit is contained in:
Generated
+545
-386
File diff suppressed because it is too large
Load Diff
+5
-6
@@ -1,14 +1,13 @@
|
||||
{
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "9.27.0",
|
||||
"@stylistic/eslint-plugin": "4.2.0",
|
||||
"@types/express": "5.0.2",
|
||||
"@types/express-session": "1.18.1",
|
||||
"copyfiles": "2.4.1",
|
||||
"eslint": "9.27.0",
|
||||
"rimraf": "6.0.1",
|
||||
"tsc-alias": "1.8.17",
|
||||
"tsx": "4.19.4",
|
||||
"tsx": "4.22.4",
|
||||
"typescript": "5.8.3",
|
||||
"typescript-eslint": "8.32.1"
|
||||
},
|
||||
@@ -28,8 +27,8 @@
|
||||
"scripts": {
|
||||
"dev": "tsx watch --enable-source-maps src/index.ts",
|
||||
"start": "node dist/index.js",
|
||||
"build": "npm run clean && npx tsc && npx tsc-alias && npm run copyfiles",
|
||||
"clean": "npx rimraf dist",
|
||||
"copyfiles": "npx copyfiles -u 1 \"./src/**/*.html\" ./dist"
|
||||
"build": "npm run clean && node scripts/build.js && npm run copyfiles",
|
||||
"clean": "rimraf dist",
|
||||
"copyfiles": "copyfiles -u 1 \"./src/**/*.html\" ./dist"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const esbuild = require('esbuild');
|
||||
|
||||
esbuild.buildSync({
|
||||
entryPoints: ['src/**/*.ts'],
|
||||
outdir: 'dist',
|
||||
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
minify: true
|
||||
});
|
||||
@@ -1,7 +1,6 @@
|
||||
import path, { dirname } from 'path';
|
||||
import path from 'path';
|
||||
import { open, Database as SqliteDatabase } from 'sqlite';
|
||||
import sqlite3 from 'sqlite3';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { Message } from '../events';
|
||||
import { AppealMessage, Ban, GithubUserMapping, GuildArraySetting, GuildSetting, GuildSettings, KnowledgebaseItem, LoggedMessage, Note, PrivateHelpTicket, RoleButton, TicketMessage, TicketPhrase } from '../types';
|
||||
import { serializeMessage, wait } from '../utils';
|
||||
@@ -33,7 +32,6 @@ export class Database {
|
||||
}
|
||||
|
||||
private static async ensure() {
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const schema = readFileSync(path.join(__dirname, '..', '..', 'sql', 'structure.sql'), { encoding: 'utf-8' });
|
||||
await Database.db.exec(schema);
|
||||
console.log('SQLite database ensured');
|
||||
@@ -42,7 +40,6 @@ export class Database {
|
||||
private static async migrate() {
|
||||
console.log('Starting database migrations');
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
await Database.db.migrate({
|
||||
migrationsPath: path.join(__dirname, '..', '..', 'sql', 'migrations')
|
||||
});
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Client } from 'discord.js';
|
||||
import fs from 'fs';
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
import path from 'path';
|
||||
import { Handler } from '../types';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT_DIR = path.resolve(__dirname, '..');
|
||||
|
||||
export async function loadHandlersFrom(dir: string, handlerArray: Handler[]): Promise<void> {
|
||||
@@ -12,7 +10,8 @@ export async function loadHandlersFrom(dir: string, handlerArray: Handler[]): Pr
|
||||
|
||||
const files = fs.readdirSync(`${ROOT_DIR}/${dir}`).filter(file => file.endsWith('.js') || file.endsWith('.ts'));
|
||||
for (const file of files) {
|
||||
handlerArray.push((await import(pathToFileURL(`${ROOT_DIR}/${dir}/${file}`).href)).default);
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
handlerArray.push(require(`${ROOT_DIR}/${dir}/${file}`).default);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { Client, REST, RESTPostAPIApplicationCommandsJSONBody, Routes } from 'discord.js';
|
||||
import fs from 'fs';
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath, pathToFileURL } from 'url';
|
||||
import path from 'path';
|
||||
import { config } from '../config';
|
||||
import { Command } from '../types';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const ROOT_DIR = path.resolve(__dirname, '..');
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN!);
|
||||
@@ -22,7 +20,8 @@ export async function refreshCommands(client: Client) {
|
||||
for (const [folderName, files] of Object.entries(commandFiles)) {
|
||||
for (const file of files) {
|
||||
const p = `${ROOT_DIR}/${folderName}/${file}`;
|
||||
const command: Command = (await import(pathToFileURL(p).href)).default;
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const command: Command = require(p).default;
|
||||
|
||||
if (!command) {
|
||||
console.warn(`File at ${p} has no export. Skipping registering.`);
|
||||
|
||||
@@ -5,8 +5,7 @@ import express, { Request, Response } from 'express';
|
||||
import session from 'express-session';
|
||||
import fs from 'fs';
|
||||
import MemoryStore from 'memorystore';
|
||||
import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import path from 'path';
|
||||
import { config } from '../config';
|
||||
import { Database } from '../shared/Database';
|
||||
import { AltData, comprehensiveAltLookupFromE621, DiscordOAuth2 } from '../utils';
|
||||
@@ -26,8 +25,6 @@ const DEV_BASE_URL = `http://localhost:${config.PORT}`;
|
||||
const PROD_BASE_URL = 'https://discord.e621.net';
|
||||
|
||||
const OAUTH_SCOPES = ['identify', 'guilds.join'];
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PAGE_TEMPLATE = fs.readFileSync(path.join(__dirname, 'templates', 'page.html'), { encoding: 'utf-8' });
|
||||
|
||||
const oauth = new DiscordOAuth2({
|
||||
|
||||
+8
-18
@@ -1,25 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "bundler",
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"inlineSourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"noImplicitAny": false,
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ES2021.String"],
|
||||
"skipLibCheck": true,
|
||||
"lib": [
|
||||
"ES2021.String"
|
||||
]
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules"],
|
||||
"tsc-alias": {
|
||||
"resolveFullPaths": true,
|
||||
"verbose": false
|
||||
"inlineSourceMap": true,
|
||||
"forceConsistentCasingInFileNames": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user