Skip to content

Commit cc1074d

Browse files
committed
add colors
1 parent e60276b commit cc1074d

File tree

7 files changed

+39
-19
lines changed

7 files changed

+39
-19
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "commandkit",
3-
"version": "0.0.9",
2+
"name": "@underctrl/commandkit",
3+
"version": "0.0.10",
44
"license": "MIT",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
@@ -27,6 +27,9 @@
2727
"event handler",
2828
"command validations"
2929
],
30+
"dependencies": {
31+
"colors": "^1.4.0"
32+
},
3033
"devDependencies": {
3134
"discord.js": "^14.12.1",
3235
"tsup": "^7.2.0",

src/CommandKit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { CommandHandler, EventHandler, ValidationHandler } from "./handlers";
22
import { CommandKitData, CommandKitOptions } from "./typings";
3+
import "colors";
34

45
export class CommandKit {
56
#data: CommandKitData;
67

78
constructor({ ...options }: CommandKitOptions) {
89
if (!options.client) {
9-
throw new Error('"client" is required when instantiating CommandKit.');
10+
throw new Error('"client" is required when instantiating CommandKit.'.red);
1011
}
1112

1213
if (options.validationsPath && !options.commandsPath) {
13-
throw new Error('"commandsPath" is required when "validationsPath" is set.');
14+
throw new Error('"commandsPath" is required when "validationsPath" is set.'.red);
1415
}
1516

1617
this.#data = {

src/handlers/command-handler/CommandHandler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getFilePaths } from "../../utils/get-paths";
33
import builtInValidations from "./validations";
44
import registerCommands from "./functions/registerCommands";
55
import handleCommands from "./functions/handleCommands";
6+
import "colors";
67

78
export class CommandHandler {
89
_data: CommandHandlerData;
@@ -34,12 +35,12 @@ export class CommandHandler {
3435
if (commandObj.default) commandObj = commandObj.default;
3536

3637
if (!commandObj.data) {
37-
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "data".`);
38+
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "data".`.yellow);
3839
continue;
3940
}
4041

4142
if (!commandObj.run) {
42-
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`);
43+
console.log(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`.yellow);
4344
continue;
4445
}
4546

src/handlers/command-handler/functions/registerCommands.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Guild, GuildApplicationCommandManager } from "discord.js";
22
import { CommandHandler } from "../CommandHandler";
33
import areSlashCommandsDifferent from "../utils/areSlashCommandsDifferent";
4+
import "colors";
45

56
export default async function registerCommands(commandHandler: CommandHandler) {
67
const client = commandHandler._data.client;
@@ -14,7 +15,7 @@ export default async function registerCommands(commandHandler: CommandHandler) {
1415
const guild = client.guilds.cache.get(devGuildId);
1516

1617
if (!guild) {
17-
console.log(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`);
18+
console.log(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`.yellow);
1819
continue;
1920
}
2021

@@ -38,10 +39,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
3839
const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
3940

4041
if (!targetCommand) {
41-
console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`);
42+
console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`.yellow);
4243
} else {
4344
targetCommand.delete().then(() => {
44-
console.log(`🚮 Deleted command "${command.data.name}" globally.`);
45+
console.log(`🚮 Deleted command "${command.data.name}" globally.`.green);
4546
});
4647
}
4748

@@ -51,10 +52,13 @@ export default async function registerCommands(commandHandler: CommandHandler) {
5152
if (!targetCommand) {
5253
console.log(
5354
`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`
55+
.yellow
5456
);
5557
} else {
5658
targetCommand.delete().then(() => {
57-
console.log(`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`);
59+
console.log(
60+
`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`.green
61+
);
5862
});
5963
}
6064
}
@@ -76,10 +80,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
7680
appGlobalCommand
7781
.edit(commandData)
7882
.then(() => {
79-
console.log(`✅ Edited command "${commandData.name}" globally.`);
83+
console.log(`✅ Edited command "${commandData.name}" globally.`.green);
8084
})
8185
.catch((error) => {
82-
console.log(`❌ Failed to edit command "${commandData.name}" globally.`);
86+
console.log(`❌ Failed to edit command "${commandData.name}" globally.`.red);
8387
console.error(error);
8488
});
8589

@@ -98,11 +102,14 @@ export default async function registerCommands(commandHandler: CommandHandler) {
98102
appGuildCommand
99103
.edit(commandData)
100104
.then(() => {
101-
console.log(`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`);
105+
console.log(
106+
`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`.green
107+
);
102108
})
103109
.catch((error) => {
104110
console.log(
105111
`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
112+
.red
106113
);
107114
console.error(error);
108115
});
@@ -120,6 +127,7 @@ export default async function registerCommands(commandHandler: CommandHandler) {
120127
if (!devGuilds.length) {
121128
console.log(
122129
`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`
130+
.yellow
123131
);
124132
continue;
125133
}
@@ -131,10 +139,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
131139
guild?.commands
132140
.create(command.data)
133141
.then(() => {
134-
console.log(`✅ Registered command "${command.data.name}" in ${guild.name}.`);
142+
console.log(`✅ Registered command "${command.data.name}" in ${guild.name}.`.green);
135143
})
136144
.catch((error) => {
137-
console.log(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`);
145+
console.log(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`.red);
138146
console.error(error);
139147
});
140148
}
@@ -147,10 +155,10 @@ export default async function registerCommands(commandHandler: CommandHandler) {
147155
appCommands
148156
?.create(command.data)
149157
.then(() => {
150-
console.log(`✅ Registered command "${command.data.name}" globally.`);
158+
console.log(`✅ Registered command "${command.data.name}" globally.`.green);
151159
})
152160
.catch((error) => {
153-
console.log(`❌ Failed to register command "${command.data.name}" globally.`);
161+
console.log(`❌ Failed to register command "${command.data.name}" globally.`.red);
154162
console.error(error);
155163
});
156164
}

src/handlers/event-handler/EventHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getFilePaths, getFolderPaths } from "../../utils/get-paths";
22
import { EventHandlerOptions, EventHandlerData } from "./typings";
3+
import "colors";
34

45
export class EventHandler {
56
#data: EventHandlerData;
@@ -38,7 +39,7 @@ export class EventHandler {
3839
const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
3940

4041
if (typeof eventFunction !== "function") {
41-
console.log(`⏩ Ignoring: Event ${compactFilePath} does not export a function.`);
42+
console.log(`⏩ Ignoring: Event ${compactFilePath} does not export a function.`.yellow);
4243
continue;
4344
}
4445

src/handlers/validation-handler/ValidationHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ValidationHandlerData, ValidationHandlerOptions } from "./typings";
22
import { getFilePaths } from "../../utils/get-paths";
3+
import "colors";
34

45
export class ValidationHandler {
56
#data: ValidationHandlerData;
@@ -25,7 +26,7 @@ export class ValidationHandler {
2526
const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
2627

2728
if (typeof validationFunction !== "function") {
28-
console.log(`⏩ Ignoring: Validation ${compactFilePath} does not export a function.`);
29+
console.log(`⏩ Ignoring: Validation ${compactFilePath} does not export a function.`.yellow);
2930
continue;
3031
}
3132

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ chokidar@^3.5.1:
337337
optionalDependencies:
338338
fsevents "~2.3.2"
339339

340+
colors@^1.4.0:
341+
version "1.4.0"
342+
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
343+
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
344+
340345
commander@^4.0.0:
341346
version "4.1.1"
342347
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"

0 commit comments

Comments
 (0)