From e9ff15085c3646c6b4b7e5d5b5815de02d39a728 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:01:51 +0100 Subject: [PATCH 1/8] don't compile tests --- .dockerignore | 2 -- package.json | 2 +- tsconfig.json | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9cddb1c..e00420a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,5 +5,3 @@ !package-lock.json !LICENSE !tsconfig.json - -src/tests/ diff --git a/package.json b/package.json index 229b936..ebf1c78 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "lint": "npx eslint src", "format-check": "npx prettier --check src", "format-write": "npx prettier --write src", - "test": "npm run compile && npx jest" + "test": "npx jest" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 333de2e..21419eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -102,5 +102,5 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["./**/*.ts", "./src/locales/*.json"] + "exclude": ["./src/tests"] } -- 2.45.2 From c98fa2dd5694eb4272e96966f1efda9c6f662d83 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:03:48 +0100 Subject: [PATCH 2/8] update async-queue --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index dfe19ce..cff92cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1454,9 +1454,9 @@ } }, "node_modules/@sapphire/async-queue": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.3.tgz", - "integrity": "sha512-x7zadcfJGxFka1Q3f8gCts1F0xMwCKbZweM85xECGI0hBTeIZJGGCrHgLggihBoprlQ/hBmDR5LKfIPqnmHM3w==", + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.4.tgz", + "integrity": "sha512-id65RxAx34DCk8KAVTPWwcephJSkStiS9M15F87+zvK2gK47wf7yeRIo8WiuKeXQS6bsyo/uQ/t0QW1cLmSb+A==", "license": "MIT", "engines": { "node": ">=v14.0.0", -- 2.45.2 From a550a8bc3f6197eccbf3dbcdcafd92d0b3e2ce22 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:04:14 +0100 Subject: [PATCH 3/8] add sql directory to dist --- package.json | 2 +- src/events/loader.ts | 4 ++-- src/index.ts | 4 ++-- src/load.ts | 8 ++++---- src/utils/client.ts | 3 ++- src/utils/db.ts | 4 +++- src/utils/misc.ts | 3 +++ 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index ebf1c78..14a7b91 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Bot discord", "main": "src/index.js", "scripts": { - "compile": "rm -r dist 2> /dev/null; npx tsc", + "compile": "rm -r dist 2> /dev/null; npx tsc; cp -r ./src/sql ./dist/sql", "main": "npm run compile && node ./dist/index.js", "debug": "npx tsnd --respawn ./src/index.ts", "lint": "npx eslint src", diff --git a/src/events/loader.ts b/src/events/loader.ts index 5557ccf..a6c8bcf 100644 --- a/src/events/loader.ts +++ b/src/events/loader.ts @@ -1,10 +1,10 @@ import { PlayerEvents, useMainPlayer } from "discord-player"; import { Client } from "discord.js"; import { readdir } from "fs/promises"; -import { splitFilenameExtensions } from "../utils/misc"; +import { isDev, splitFilenameExtensions } from "../utils/misc"; /** Load all the events */ -export default async (client: Client, isDev: boolean) => { +export default async (client: Client) => { const events_categories = (await readdir(__dirname, { withFileTypes: true })) .filter((element) => element.isDirectory()) .map((element) => element.name); diff --git a/src/index.ts b/src/index.ts index 835ce0b..6f55a29 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -const isDev = process.env.NODE_ENV !== "production"; +import { isDev } from "./utils/misc"; /** Load the app */ const start_app = () => { - import("./load").then((l) => l.run(isDev).catch((error) => console.error(error))); + import("./load").then((l) => l.run().catch((error) => console.error(error))); }; // Load .env if not in prod diff --git a/src/load.ts b/src/load.ts index ff68b03..fbfbedf 100644 --- a/src/load.ts +++ b/src/load.ts @@ -4,15 +4,15 @@ import loadEvents from "./events/loader"; import loadModals from "./modals/loader"; import loadClient, { quit } from "./utils/client"; -import { logStart } from "./utils/misc"; +import { isDev, logStart } from "./utils/misc"; /** Run the bot */ -export const run = async (isDev: boolean) => { +export const run = async () => { console.log("Starting Botanique..."); // Client Discord.JS const client_name = "Client"; - await loadClient(isDev) + await loadClient() .then(async (client) => { if (isDev) { // Attach debugging listeners @@ -21,7 +21,7 @@ export const run = async (isDev: boolean) => { // Events Discord.JS and Player const events_name = "Events"; - await loadEvents(client, isDev) + await loadEvents(client) .then(() => console.log(logStart(events_name, true))) .catch((err) => { console.error(err); diff --git a/src/utils/client.ts b/src/utils/client.ts index 2ab5276..92f25ae 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -6,9 +6,10 @@ import "../modules/client"; import { loadLocales } from "./locales"; import { YoutubeiExtractor } from "discord-player-youtubei"; import { readSQL } from "./db"; +import { isDev } from "./misc"; /** Creation of the client and definition of its properties */ -export default async (isDev: boolean) => { +export default async () => { const activities = isDev ? [] : [{ name: "/help", type: ActivityType.Watching }]; const client: Client = new Client({ diff --git a/src/utils/db.ts b/src/utils/db.ts index 5d3aa4b..9566da6 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -1,7 +1,9 @@ import fs from "node:fs"; +import { isDev } from "./misc"; export const readSQL = (path: string) => { - const dir = "./src/sql/"; + const root = isDev ? "./src" : "./dist"; + const dir = root + "/sql/"; if (!path.startsWith(dir)) { path = dir + path; } diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 79195e9..72342f6 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,5 +1,8 @@ import { GuildMember } from "discord.js"; +/** Check if we are in the dev environnement */ +export const isDev = process.env.NODE_ENV !== "production"; + /** * Log module status * @param {string} name Module name -- 2.45.2 From 76d19dec6e1bd1d2b2e8284b2382796f9d4e849a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:04:22 +0100 Subject: [PATCH 4/8] re-add include --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 21419eb..3d15a10 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -102,5 +102,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, + "include": ["./**/*.ts", "./src/locales/*.json"], "exclude": ["./src/tests"] } -- 2.45.2 From 0a2e8972f423e95eb1a4f891857b58ec7f56442a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:09:12 +0100 Subject: [PATCH 5/8] && --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14a7b91..3907e61 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Bot discord", "main": "src/index.js", "scripts": { - "compile": "rm -r dist 2> /dev/null; npx tsc; cp -r ./src/sql ./dist/sql", + "compile": "rm -r dist 2> /dev/null; npx tsc && cp -r ./src/sql ./dist/sql", "main": "npm run compile && node ./dist/index.js", "debug": "npx tsnd --respawn ./src/index.ts", "lint": "npx eslint src", -- 2.45.2 From d017e30180b2292275c8222574e752d8e92bbbfa Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:16:47 +0100 Subject: [PATCH 6/8] compile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 07d99b9..2bd7ad2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ COPY --chown=node:node . . ENV NODE_ENV=production RUN npm ci --omit=dev && \ - npx tsc && \ + npm run compile && \ rm -r src/ tsconfig.json && \ npm uninstall typescript @types/sqlite3 && \ npm cache clean --force -- 2.45.2 From c23b9c6c1fbe7c4791b04b1fa0a4e4d542d1083a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:18:28 +0100 Subject: [PATCH 7/8] clean install --- .forgejo/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/pr-check.yml b/.forgejo/workflows/pr-check.yml index f25c930..bacf8c7 100644 --- a/.forgejo/workflows/pr-check.yml +++ b/.forgejo/workflows/pr-check.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Install dependencies - run: npm install + run: npm ci - name: Run lint run: npm run lint -- 2.45.2 From d6a60f1a1f9f663a0c1bc54a2ffb575e1723dbb9 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Nov 2024 18:20:46 +0100 Subject: [PATCH 8/8] ignore tests folder --- .eslintignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintignore b/.eslintignore index 1521c8b..45c4419 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ dist +tests -- 2.45.2