From a6f7cf78dccd86d6dcd9686df021562515571887 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 8 Sep 2024 22:46:19 +0200 Subject: [PATCH] Updated scripts to use esm syntax Signed-off-by: Taken --- scripts/delete-commands.ts | 21 +++++++++------------ scripts/deploy-commands.ts | 34 ++++++++++++++++------------------ scripts/dev-deploy.ts | 30 ++++++++++++++---------------- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/scripts/delete-commands.ts b/scripts/delete-commands.ts index 7572966..779436a 100644 --- a/scripts/delete-commands.ts +++ b/scripts/delete-commands.ts @@ -3,16 +3,13 @@ import env from "../src/utils/Env" const rest = new REST({ version: "10" }).setToken(env.dev.devtoken) -async function deleteCommands() { - try { - console.log("Started deleting application (/) commands.") - await rest.put( - Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid), - { body: [] } - ) - console.log("Successfully deleted application (/) commands.") - } catch (error) { - console.error(error) - } +try { + console.log("Started deleting application (/) commands.") + await rest.put( + Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid), + { body: [] } + ) + console.log("Successfully deleted application (/) commands.") +} catch (error) { + console.error(error) } -deleteCommands() diff --git a/scripts/deploy-commands.ts b/scripts/deploy-commands.ts index 6e5489c..c868fef 100644 --- a/scripts/deploy-commands.ts +++ b/scripts/deploy-commands.ts @@ -10,29 +10,27 @@ const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWi const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu").filter(file => file.endsWith(".ts")) for (const file of commandFiles) { - const command: ICommand = require(`../src/commands/${file}`) + const { default: command } = await import(`../src/commands/${file}`) as { default: ICommand } commands.push(command.data.toJSON()) } for (const file of contentMenuCommands) { - const command: ICommand = require(`../src/commands-contextmenu/${file}`) + const { default: command } = await import(`../src/commands-contextmenu/${file}`) as { default: ICommand } commands.push(command.data.toJSON()) } -;(async () => { - try { - console.log(color(`Started refreshing ${commands.length} application (/) commands.`, "green")) +try { + console.log(color(`Started refreshing ${commands.length} application (/) commands.`, "green")) - const commandsString = commands.map(command => " " + command.name) - console.log(color(commandsString.join("\n"), "lavender")) + const commandsString = commands.map(command => " " + command.name) + console.log(color(commandsString.join("\n"), "lavender")) - await rest.put( - Routes.applicationCommands(env.dev.clientid), - { body: commands } - ).then(() => { - console.log(color(`Successfully reloaded ${commands.length} application (/) commands.`, "green")) - process.exit(0) - }) - } catch (error) { - console.error(error) - } -})() + await rest.put( + Routes.applicationCommands(env.dev.clientid), + { body: commands } + ).then(() => { + console.log(color(`Successfully reloaded ${commands.length} application (/) commands.`, "green")) + process.exit(0) + }) +} catch (error) { + console.error(error) +} diff --git a/scripts/dev-deploy.ts b/scripts/dev-deploy.ts index e3f7629..ba10029 100644 --- a/scripts/dev-deploy.ts +++ b/scripts/dev-deploy.ts @@ -9,30 +9,28 @@ const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsW const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(".ts")) for (const file of commandFiles) { - const command: ICommand = require(`../src/commands/${file}`) + const { default: command } = await import(`../src/commands/${file}`) as { default: ICommand } if (command.dev) { commands.push(command.data.toJSON()) } } for (const file of contentMenuCommands) { - const command: ICommand = require(`../src/commands-contextmenu/${file}`) + const { default: command } = await import(`../src/commands-contextmenu/${file}`) as { default: ICommand } if (command.dev) { commands.push(command.data.toJSON()) } } -;(async () => { - try { - console.log(`Started refreshing ${commands.length} application (/) commands.`) +try { + console.log(`Started refreshing ${commands.length} application (/) commands.`) - await rest.put( - Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid), - { body: commands } - ).then(() => { - console.log(`Successfully reloaded ${commands.length} application (/) commands.`) - process.exit(0) - }) - } catch (error) { - console.error(error) - } -})() + await rest.put( + Routes.applicationGuildCommands(env.dev.devid, env.dev.guildid), + { body: commands } + ).then(() => { + console.log(`Successfully reloaded ${commands.length} application (/) commands.`) + process.exit(0) + }) +} catch (error) { + console.error(error) +}