complete move to typescript

This commit is contained in:
Corban-Lee Jones 2025-01-28 13:52:25 +00:00
parent fc424ddec7
commit 5dbb6620c7
12 changed files with 52 additions and 49 deletions

View File

@ -5,8 +5,8 @@
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"tailwind": "npx tailwindcss -i ./src/client/public/css/main.css -o ./src/client/public/css/tailwind.css", "tailwind": "npx tailwindcss -i ./src/client/public/css/main.css -o ./src/client/public/css/tailwind.css",
"build": "npx tsc --project tsconfig.json && npx tsc-alias -p tsconfig.json", "build": "./build.sh",
"dev": "nodemon -r tsconfig-paths/register src/app.ts", "dev": "nodemon -r tsconfig-paths/register ./src/app.ts",
"start": "node dist/app.js" "start": "node dist/app.js"
}, },
"repository": { "repository": {
@ -23,12 +23,15 @@
"ejs": "^3.1.10", "ejs": "^3.1.10",
"ejs-mate": "^4.0.0", "ejs-mate": "^4.0.0",
"express": "^4.21.2", "express": "^4.21.2",
"ncp": "^2.0.0",
"preline": "^2.7.0", "preline": "^2.7.0",
"tsconfig-paths": "^4.2.0" "tsconfig-paths": "^4.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/ejs": "^3.1.5",
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/node": "^22.10.10", "@types/node": "^22.10.10",
"@zerollup/ts-transform-paths": "^1.7.18",
"nodemon": "^3.1.9", "nodemon": "^3.1.9",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",

View File

@ -1,26 +1,25 @@
const express = require("express"); import express from "express";
const engine = require("ejs-mate"); import engine from "ejs-mate";
const dotenv = require("dotenv"); import dotenv from "dotenv";
dotenv.config(); dotenv.config();
import "@bot/bot"; import "@bot/bot";
// import middleware // import middleware
const attachGuilds = require("./server/middleware/attachGuilds"); import { attachGuilds } from "@server/middleware/attachGuilds";
// import routers // import routers
const homeRouter = require("./server/routes/home"); import { router as homeRouter } from "@server/routes/home";
const guildRouter = require("./server/routes/guild"); import { router as guildRouter } from "@server/routes/guild";
const app = express(); const app = express();
app.engine("ejs", engine); app.engine("ejs", engine);
app.set("views", __dirname + "/client/views"); app.set("views", "./src/client/views");
app.set("view engine", "ejs"); app.set("view engine", "ejs");
app.use("/static", express.static(__dirname + "/client/public")); app.use("/static", express.static("./src/client/public"));
app.use("/static/preline.js", express.static(__dirname + "/../node_modules/preline/dist/preline.js")); app.use("/static/preline.js", express.static("./node_modules/preline/dist/preline.js"));
// register middleware // register middleware
app.use(attachGuilds); app.use(attachGuilds);

View File

@ -1,7 +1,7 @@
// const { Client, GatewayIntentBits } = require("discord.js"); // const { Client, GatewayIntentBits } = require("discord.js");
import { Client, GatewayIntentBits, ActivityType } from "discord.js"; import { Client, GatewayIntentBits, ActivityType } from "discord.js";
const client = new Client({ export const client = new Client({
intents: [ intents: [
GatewayIntentBits.Guilds, GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMembers,
@ -18,6 +18,4 @@ client.on("ready", () => {
console.log(`Discord Bot '${client.user.displayName}' is online!`) console.log(`Discord Bot '${client.user.displayName}' is online!`)
}); });
client.login(process.env.BOT_TOKEN); client.login(process.env.BOT_TOKEN);
module.exports = client;

View File

@ -1,6 +1,7 @@
const bot = require("../../bot/bot"); import { Request, Response } from "express";
import { client as bot } from "@bot/bot";
const get = async (request, response) => { export const get = async (request: Request, response: Response) => {
const guildId = request.params.guildId; const guildId = request.params.guildId;
const guild = bot.guilds.cache.get(guildId); const guild = bot.guilds.cache.get(guildId);
@ -13,6 +14,4 @@ const get = async (request, response) => {
title: `${guild.name} - Relay`, title: `${guild.name} - Relay`,
guild: guild, guild: guild,
}); });
}; };
module.exports = { get };

View File

@ -1,9 +1,7 @@
import bot from "@bot/bot"; import { Request, Response } from "express";
const get = async (request, response) => { export const get = async (_request: Request, response: Response) => {
response.render("home", { response.render("home", {
title: "Dashboard - Relay" title: "Dashboard - Relay"
}); });
}; };
module.exports = { get };

View File

@ -1,8 +0,0 @@
const bot = require("../../bot/bot");
const attachGuilds = (request, response, next) => {
response.locals.guilds = bot.guilds.cache.map(guild => guild);
next();
};
module.exports = attachGuilds;

View File

@ -0,0 +1,7 @@
import { Request, Response, NextFunction } from "express";
import { client as bot } from "@bot/bot";
export const attachGuilds = (_request: Request, response: Response, next: NextFunction) => {
response.locals.guilds = bot.guilds.cache.map(guild => guild);
next();
};

View File

@ -1,8 +0,0 @@
const { Router } = require("express");
const controller = require("../controllers/guild");
const router = Router();
router.get("/:guildId", controller.get);
module.exports = router;

View File

@ -0,0 +1,6 @@
import { Router } from "express";
import * as controller from "@server/controllers/guild";
export const router = Router();
router.get("/:guildId", controller.get);

View File

@ -1,8 +1,6 @@
import { Router } from "express"; import { Router } from "express";
import controller from "@server/controllers/home"; import * as controller from "@server/controllers/home";
const router = Router(); export const router = Router();
router.get("/", controller.get); router.get("/", controller.get);
module.exports = router;

1
src/types/ejs-mate.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module "ejs-mate";

View File

@ -30,13 +30,22 @@
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */ "paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
"@/*": ["src/*"],
"@server/*": ["src/server/*"], "@server/*": ["src/server/*"],
"@client/*": ["src/client/*"], "@client/*": ["src/client/*"],
"@bot/*": ["src/bot/*"], "@bot/*": ["src/bot/*"],
"@utils/*": ["src/utils/*"] "@utils/*": ["src/utils/*"],
"@views/*": ["src/client/views/*"],
"@public/*": ["src/client/public/*"],
"@node_modules/*": ["node_modules/*"],
}, },
"plugins": [
{
"transform": "@zerollup/ts-transform-paths"
}
],
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ "typeRoots": ["./node_modules/@types", "./src/types/"], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
@ -112,5 +121,6 @@
/* Completeness */ /* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */
} },
"include": ["src/**/*"]
} }