complete move to typescript
This commit is contained in:
parent
fc424ddec7
commit
5dbb6620c7
@ -5,8 +5,8 @@
|
||||
"scripts": {
|
||||
"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",
|
||||
"build": "npx tsc --project tsconfig.json && npx tsc-alias -p tsconfig.json",
|
||||
"dev": "nodemon -r tsconfig-paths/register src/app.ts",
|
||||
"build": "./build.sh",
|
||||
"dev": "nodemon -r tsconfig-paths/register ./src/app.ts",
|
||||
"start": "node dist/app.js"
|
||||
},
|
||||
"repository": {
|
||||
@ -23,12 +23,15 @@
|
||||
"ejs": "^3.1.10",
|
||||
"ejs-mate": "^4.0.0",
|
||||
"express": "^4.21.2",
|
||||
"ncp": "^2.0.0",
|
||||
"preline": "^2.7.0",
|
||||
"tsconfig-paths": "^4.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ejs": "^3.1.5",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/node": "^22.10.10",
|
||||
"@zerollup/ts-transform-paths": "^1.7.18",
|
||||
"nodemon": "^3.1.9",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"ts-node": "^10.9.2",
|
||||
|
19
src/app.ts
19
src/app.ts
@ -1,26 +1,25 @@
|
||||
const express = require("express");
|
||||
const engine = require("ejs-mate");
|
||||
const dotenv = require("dotenv");
|
||||
import express from "express";
|
||||
import engine from "ejs-mate";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
import "@bot/bot";
|
||||
|
||||
// import middleware
|
||||
const attachGuilds = require("./server/middleware/attachGuilds");
|
||||
import { attachGuilds } from "@server/middleware/attachGuilds";
|
||||
|
||||
// import routers
|
||||
const homeRouter = require("./server/routes/home");
|
||||
const guildRouter = require("./server/routes/guild");
|
||||
|
||||
import { router as homeRouter } from "@server/routes/home";
|
||||
import { router as guildRouter } from "@server/routes/guild";
|
||||
|
||||
const app = express();
|
||||
|
||||
app.engine("ejs", engine);
|
||||
app.set("views", __dirname + "/client/views");
|
||||
app.set("views", "./src/client/views");
|
||||
app.set("view engine", "ejs");
|
||||
|
||||
app.use("/static", express.static(__dirname + "/client/public"));
|
||||
app.use("/static/preline.js", express.static(__dirname + "/../node_modules/preline/dist/preline.js"));
|
||||
app.use("/static", express.static("./src/client/public"));
|
||||
app.use("/static/preline.js", express.static("./node_modules/preline/dist/preline.js"));
|
||||
|
||||
// register middleware
|
||||
app.use(attachGuilds);
|
||||
|
@ -1,7 +1,7 @@
|
||||
// const { Client, GatewayIntentBits } = require("discord.js");
|
||||
import { Client, GatewayIntentBits, ActivityType } from "discord.js";
|
||||
|
||||
const client = new Client({
|
||||
export const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
@ -18,6 +18,4 @@ client.on("ready", () => {
|
||||
console.log(`Discord Bot '${client.user.displayName}' is online!`)
|
||||
});
|
||||
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
|
||||
module.exports = client;
|
||||
client.login(process.env.BOT_TOKEN);
|
@ -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 guild = bot.guilds.cache.get(guildId);
|
||||
|
||||
@ -13,6 +14,4 @@ const get = async (request, response) => {
|
||||
title: `${guild.name} - Relay`,
|
||||
guild: guild,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { get };
|
||||
};
|
@ -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", {
|
||||
title: "Dashboard - Relay"
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { get };
|
||||
|
@ -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;
|
7
src/server/middleware/attachGuilds.ts
Normal file
7
src/server/middleware/attachGuilds.ts
Normal 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();
|
||||
};
|
@ -1,8 +0,0 @@
|
||||
const { Router } = require("express");
|
||||
const controller = require("../controllers/guild");
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/:guildId", controller.get);
|
||||
|
||||
module.exports = router;
|
6
src/server/routes/guild.ts
Normal file
6
src/server/routes/guild.ts
Normal 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);
|
@ -1,8 +1,6 @@
|
||||
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);
|
||||
|
||||
module.exports = router;
|
||||
router.get("/", controller.get);
|
1
src/types/ejs-mate.d.ts
vendored
Normal file
1
src/types/ejs-mate.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare module "ejs-mate";
|
@ -30,13 +30,22 @@
|
||||
// "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. */
|
||||
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
"@/*": ["src/*"],
|
||||
"@server/*": ["src/server/*"],
|
||||
"@client/*": ["src/client/*"],
|
||||
"@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. */
|
||||
// "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. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
@ -112,5 +121,6 @@
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user