From e70cd8b1a93c909070d42f99f3096eee7febcca3 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 19 Nov 2023 16:27:30 +0100 Subject: [PATCH] Updated autodeploy script and added preety-log --- package-lock.json | 86 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++ utils/autodeploy.js | 28 ++++++++++++--- 3 files changed, 112 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e642534..4eaf5d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,9 @@ "discord.js": "^14.8.0", "dotenv": "^16.0.3", "mongoose": "^7.0.1" + }, + "devDependencies": { + "log-beautify": "^1.2.0" } }, "node_modules/@discordjs/builders": { @@ -173,6 +176,21 @@ "npm": ">=7.0.0" } }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -207,6 +225,43 @@ "node": ">=10.16.0" } }, + "node_modules/chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/color-regex": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/color-regex/-/color-regex-1.0.2.tgz", + "integrity": "sha512-TBRKov2oivOPjISo/P3HwHzAm39b4g5Ggx+wJqjLrUcJ9EW2WjqO4j81Xo9Jzeu3Z2u+x9nx2A/Pt8ZSYd/d3Q==", + "dev": true + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -324,6 +379,15 @@ "node": ">= 6" } }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/ip": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", @@ -347,6 +411,16 @@ "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", "integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==" }, + "node_modules/log-beautify": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/log-beautify/-/log-beautify-1.2.0.tgz", + "integrity": "sha512-730dy7bmL9LcrX9q0ybM+M2eqynzmPqG5bilgs1k2hXsX0ad9RKf3lCMoSDVn8uDjYd9mlJkPXWnIDWpOmzTNw==", + "dev": true, + "dependencies": { + "chalk": "^3.0.0", + "color-regex": "^1.0.2" + } + }, "node_modules/magic-bytes.js": { "version": "1.0.17", "resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.0.17.tgz", @@ -528,6 +602,18 @@ "node": ">=10.0.0" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", diff --git a/package.json b/package.json index cb96c7a..c722372 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,8 @@ "discord.js": "^14.8.0", "dotenv": "^16.0.3", "mongoose": "^7.0.1" + }, + "devDependencies": { + "log-beautify": "^1.2.0" } } diff --git a/utils/autodeploy.js b/utils/autodeploy.js index ddaaed5..0a58730 100644 --- a/utils/autodeploy.js +++ b/utils/autodeploy.js @@ -1,10 +1,17 @@ const { REST, Routes } = require('discord.js'); +const log = require('log-beautify') const fs = require('fs'); require('dotenv').config(); const token = process.env.DEVTOKEN; const clientId = process.env.DEVID; const guildId = process.env.GUILDID; +log.useSymbols = false +log.setColors({ + newCmds: "#b4befe", + currentCmds: "#f38ba8" +}) + async function autoDeployCommands() { const commands = []; const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); @@ -17,14 +24,12 @@ async function autoDeployCommands() { commands.push(command.data.toJSON()); } } - for (const file of contentMenuCommands) { const command = require(`../commands-contextmenu/${file}`); if (command.dev) { commands.push(command.data.toJSON()); } } - for (const file of commandsTesting) { const command = require(`../commands-testing/${file}`); if (command.dev) { @@ -44,7 +49,6 @@ async function autoDeployCommands() { description: command.description, } }) - const newCommandsInfo = commands.map(command => { return { name: command.name, @@ -52,13 +56,26 @@ async function autoDeployCommands() { } }) - if (JSON.stringify(currentCommandsInfo) === JSON.stringify(newCommandsInfo)) { - console.log('Commands are the same, skipping deploy.') + const sortedCurrentCommandsInfo = currentCommandsInfo.sort((a, b) => a.name.localeCompare(b.name)) + const sortedNewCommandsInfo = newCommandsInfo.sort((a, b) => a.name.localeCompare(b.name)) + + const newCmds = sortedNewCommandsInfo.map(cmd => { + return " " + cmd.name + " was registered." + }).join('\n') + const currentCmds = sortedCurrentCommandsInfo.map(cmd => { + return " " + cmd.name + " was unregistered." + }).join('\n') + + if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) { + log.success('Commands are the same, skipping deploy.') + log.newCmds(newCmds) return } (async () => { try { + log.warning('Commands are different, starting deploy.') + log.currentCmds(currentCmds) console.log(`Started refreshing ${commands.length} application (/) commands.`); const data = await rest.put( @@ -66,6 +83,7 @@ async function autoDeployCommands() { { body: commands }, ); + log.newCmds(newCmds) console.log(`Successfully reloaded ${data.length} application (/) commands.`); } catch (error) { console.error(error);