commandkit 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/index.d.mts +79 -0
  2. package/dist/index.d.ts +79 -1
  3. package/dist/index.js +652 -15
  4. package/dist/index.mjs +616 -0
  5. package/package.json +29 -5
  6. package/.github/workflows/publish.yaml +0 -26
  7. package/CHANGELOG.md +0 -52
  8. package/dist/CommandKit.d.ts +0 -36
  9. package/dist/CommandKit.js +0 -57
  10. package/dist/handlers/command-handler/CommandHandler.d.ts +0 -12
  11. package/dist/handlers/command-handler/CommandHandler.js +0 -62
  12. package/dist/handlers/command-handler/functions/handleCommands.d.ts +0 -2
  13. package/dist/handlers/command-handler/functions/handleCommands.js +0 -50
  14. package/dist/handlers/command-handler/functions/registerCommands.d.ts +0 -2
  15. package/dist/handlers/command-handler/functions/registerCommands.js +0 -135
  16. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.d.ts +0 -1
  17. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.js +0 -17
  18. package/dist/handlers/command-handler/validations/botPermissions.d.ts +0 -1
  19. package/dist/handlers/command-handler/validations/botPermissions.js +0 -17
  20. package/dist/handlers/command-handler/validations/devOnly.d.ts +0 -1
  21. package/dist/handlers/command-handler/validations/devOnly.js +0 -29
  22. package/dist/handlers/command-handler/validations/guildOnly.d.ts +0 -1
  23. package/dist/handlers/command-handler/validations/guildOnly.js +0 -11
  24. package/dist/handlers/command-handler/validations/userPermissions.d.ts +0 -1
  25. package/dist/handlers/command-handler/validations/userPermissions.js +0 -17
  26. package/dist/handlers/event-handler/EventHandler.d.ts +0 -11
  27. package/dist/handlers/event-handler/EventHandler.js +0 -52
  28. package/dist/handlers/index.d.ts +0 -3
  29. package/dist/handlers/index.js +0 -19
  30. package/dist/handlers/validation-handler/ValidationHandler.d.ts +0 -7
  31. package/dist/handlers/validation-handler/ValidationHandler.js +0 -29
  32. package/dist/utils/get-paths.d.ts +0 -3
  33. package/dist/utils/get-paths.js +0 -42
  34. package/tsconfig.json +0 -14
  35. package/typings.d.ts +0 -63
package/CHANGELOG.md DELETED
@@ -1,52 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
-
7
- ## [0.0.9] - 2023-08-09
8
-
9
- ### Added
10
-
11
- - Support for developer role IDs
12
- - Ability to skip built-in validations by setting `skipBuiltInValidations` to true inside the `CommandKit` constructor
13
-
14
- ### Changed
15
-
16
- - Change validations to run custom user validations first, then CommandKit's built-in validations.
17
-
18
- ## [0.0.8] - 2023-07-03
19
-
20
- ### Added
21
-
22
- - Support for nested files inside of each event folder.
23
-
24
- ## [0.0.7] - 2023-07-02
25
-
26
- ### Changed
27
-
28
- - Give validation functions access to the full command object (commandObj) excluding the run function (as that is handled by the command handler), as opposed to just the `data` and `options` properties.
29
-
30
- ## [0.0.6] - 2023-07-02
31
-
32
- ### Fixed
33
-
34
- - Fixed a bug where wrong event names were being registered on Windows.
35
-
36
- ## [0.0.5] - 2023-07-02
37
-
38
- ### Added
39
-
40
- - Ability to automatically update application commands (guilds and global) when there's changes to the description or number of options (slash commands only).
41
-
42
- ## [0.0.4] - 2023-07-01
43
-
44
- ### Updated
45
-
46
- - Update package.json with new URLs, scripts, and version
47
-
48
- ## [0.0.3] - 2023-07-01
49
-
50
- ## [0.0.2] - 2023-07-01
51
-
52
- ## [0.0.1] - N/A
@@ -1,36 +0,0 @@
1
- import { CommandKitOptions } from '../typings';
2
- export declare class CommandKit {
3
- private _data;
4
- constructor({ ...options }: CommandKitOptions);
5
- private _init;
6
- get commands(): ({
7
- data: import("@discordjs/builders").SlashCommandBuilder | {
8
- name: string;
9
- name_localizations?: any;
10
- description: string;
11
- dm_permission?: boolean | undefined;
12
- options?: import("discord.js").APIApplicationCommandOption[] | undefined;
13
- };
14
- options?: {
15
- guildOnly?: boolean | undefined;
16
- devOnly?: boolean | undefined;
17
- deleted?: boolean | undefined;
18
- userPermissions?: import("discord.js").PermissionResolvable[] | undefined;
19
- botPermissions?: import("discord.js").PermissionResolvable[] | undefined;
20
- } | undefined;
21
- } | {
22
- data: import("@discordjs/builders").ContextMenuCommandBuilder | {
23
- name: string;
24
- name_localizations?: any;
25
- type: import("@discordjs/builders").ContextMenuCommandType;
26
- dm_permission?: boolean | undefined;
27
- };
28
- options?: {
29
- guildOnly?: boolean | undefined;
30
- devOnly?: boolean | undefined;
31
- deleted?: boolean | undefined;
32
- userPermissions?: import("discord.js").PermissionResolvable[] | undefined;
33
- botPermissions?: import("discord.js").PermissionResolvable[] | undefined;
34
- } | undefined;
35
- })[];
36
- }
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandKit = void 0;
4
- const handlers_1 = require("./handlers");
5
- class CommandKit {
6
- _data;
7
- constructor({ ...options }) {
8
- if (!options.client) {
9
- throw new Error('"client" is required when instantiating CommandKit.');
10
- }
11
- if (options.validationsPath && !options.commandsPath) {
12
- throw new Error('"commandsPath" is required when "validationsPath" is set.');
13
- }
14
- this._data = {
15
- ...options,
16
- commands: [],
17
- };
18
- this._init();
19
- }
20
- _init() {
21
- // Event handler
22
- if (this._data.eventsPath) {
23
- new handlers_1.EventHandler({
24
- client: this._data.client,
25
- eventsPath: this._data.eventsPath,
26
- });
27
- }
28
- // Validation handler
29
- let validationFunctions = [];
30
- if (this._data.validationsPath) {
31
- const validationHandler = new handlers_1.ValidationHandler({
32
- validationsPath: this._data.validationsPath,
33
- });
34
- validationHandler.getValidations().forEach((v) => validationFunctions.push(v));
35
- }
36
- // Command handler
37
- if (this._data.commandsPath) {
38
- const commandHandler = new handlers_1.CommandHandler({
39
- client: this._data.client,
40
- commandsPath: this._data.commandsPath,
41
- devGuildIds: this._data.devGuildIds || [],
42
- devUserIds: this._data.devUserIds || [],
43
- devRoleIds: this._data.devRoleIds || [],
44
- customValidations: validationFunctions,
45
- skipBuiltInValidations: this._data.skipBuiltInValidations || false,
46
- });
47
- this._data.commands = commandHandler.getCommands();
48
- }
49
- }
50
- get commands() {
51
- return this._data.commands.map((cmd) => {
52
- const { run, ...command } = cmd;
53
- return command;
54
- });
55
- }
56
- }
57
- exports.CommandKit = CommandKit;
@@ -1,12 +0,0 @@
1
- import { CommandHandlerData, CommandHandlerOptions } from './typings';
2
- import { ContextCommandObject, SlashCommandObject } from '../../../typings';
3
- export declare class CommandHandler {
4
- _data: CommandHandlerData;
5
- constructor({ ...options }: CommandHandlerOptions);
6
- _init(): void;
7
- _buildCommands(): void;
8
- _buildValidations(): void;
9
- _registerCommands(): void;
10
- _handleCommands(): void;
11
- getCommands(): (SlashCommandObject | ContextCommandObject)[];
12
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CommandHandler = void 0;
7
- const get_paths_1 = require("../../utils/get-paths");
8
- const registerCommands_1 = __importDefault(require("./functions/registerCommands"));
9
- const handleCommands_1 = __importDefault(require("./functions/handleCommands"));
10
- const path_1 = __importDefault(require("path"));
11
- class CommandHandler {
12
- _data;
13
- constructor({ ...options }) {
14
- this._data = {
15
- ...options,
16
- builtInValidations: [],
17
- commands: [],
18
- };
19
- this._init();
20
- }
21
- _init() {
22
- this._buildCommands();
23
- this._buildValidations();
24
- this._registerCommands();
25
- this._handleCommands();
26
- }
27
- _buildCommands() {
28
- const commandFilePaths = (0, get_paths_1.getFilePaths)(this._data.commandsPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
29
- for (const commandFilePath of commandFilePaths) {
30
- const commandObj = require(commandFilePath);
31
- if (!commandObj.data) {
32
- console.log(`⏩ Ignoring: Command ${commandFilePath} does not export "data".`);
33
- continue;
34
- }
35
- if (!commandObj.run) {
36
- console.log(`⏩ Ignoring: Command ${commandFilePath} does not export "run".`);
37
- continue;
38
- }
39
- this._data.commands.push(commandObj);
40
- }
41
- }
42
- _buildValidations() {
43
- const validationFilePaths = (0, get_paths_1.getFilePaths)(path_1.default.join(__dirname, 'validations'), true).filter((path) => path.endsWith('.js'));
44
- for (const validationFilePath of validationFilePaths) {
45
- const validationFunction = require(validationFilePath);
46
- if (typeof validationFunction !== 'function') {
47
- continue;
48
- }
49
- this._data.builtInValidations.push(validationFunction);
50
- }
51
- }
52
- _registerCommands() {
53
- (0, registerCommands_1.default)(this);
54
- }
55
- _handleCommands() {
56
- (0, handleCommands_1.default)(this);
57
- }
58
- getCommands() {
59
- return this._data.commands;
60
- }
61
- }
62
- exports.CommandHandler = CommandHandler;
@@ -1,2 +0,0 @@
1
- import { CommandHandler } from '../CommandHandler';
2
- export default function handleCommands(commandHandler: CommandHandler): void;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function handleCommands(commandHandler) {
4
- const client = commandHandler._data.client;
5
- client.on('interactionCreate', async (interaction) => {
6
- if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
7
- return;
8
- const targetCommand = commandHandler._data.commands.find((cmd) => cmd.data.name === interaction.commandName);
9
- if (!targetCommand)
10
- return;
11
- const { data, options, run, ...rest } = targetCommand;
12
- const commandObj = {
13
- data: targetCommand.data,
14
- options: targetCommand.options,
15
- ...rest,
16
- };
17
- let canRun = true;
18
- for (const validationFunction of commandHandler._data.customValidations) {
19
- const stopValidationLoop = await validationFunction({
20
- interaction,
21
- client,
22
- commandObj,
23
- });
24
- if (stopValidationLoop) {
25
- canRun = false;
26
- break;
27
- }
28
- }
29
- if (!canRun)
30
- return;
31
- // If custom validations pass and !skipBuiltInValidations, run built-in CommandKit validation functions
32
- if (!commandHandler._data.skipBuiltInValidations) {
33
- for (const validation of commandHandler._data.builtInValidations) {
34
- const stopValidationLoop = validation({
35
- targetCommand,
36
- interaction,
37
- handlerData: commandHandler._data,
38
- });
39
- if (stopValidationLoop) {
40
- canRun = false;
41
- break;
42
- }
43
- }
44
- }
45
- if (!canRun)
46
- return;
47
- targetCommand.run({ interaction, client });
48
- });
49
- }
50
- exports.default = handleCommands;
@@ -1,2 +0,0 @@
1
- import { CommandHandler } from '../CommandHandler';
2
- export default function registerCommands(commandHandler: CommandHandler): void;
@@ -1,135 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const areSlashCommandsDifferent_1 = __importDefault(require("../utils/areSlashCommandsDifferent"));
7
- function registerCommands(commandHandler) {
8
- const client = commandHandler._data.client;
9
- const devGuildIds = commandHandler._data.devGuildIds;
10
- const commands = commandHandler._data.commands;
11
- client.once('ready', async () => {
12
- const devGuilds = [];
13
- for (const devGuildId of devGuildIds) {
14
- const guild = client.guilds.cache.get(devGuildId);
15
- if (!guild) {
16
- console.log(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`);
17
- continue;
18
- }
19
- devGuilds.push(guild);
20
- }
21
- const appCommands = client.application?.commands;
22
- await appCommands?.fetch();
23
- const devGuildCommands = [];
24
- for (const guild of devGuilds) {
25
- const guildCommands = guild.commands;
26
- await guildCommands?.fetch();
27
- devGuildCommands.push(guildCommands);
28
- }
29
- for (const command of commands) {
30
- // <!-- Delete command if options.deleted -->
31
- if (command.options?.deleted) {
32
- const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
33
- if (!targetCommand) {
34
- console.log(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`);
35
- }
36
- else {
37
- targetCommand.delete().then(() => {
38
- console.log(`🚮 Deleted command "${command.data.name}" globally.`);
39
- });
40
- }
41
- for (const guildCommands of devGuildCommands) {
42
- const targetCommand = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
43
- if (!targetCommand) {
44
- console.log(`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`);
45
- }
46
- else {
47
- targetCommand.delete().then(() => {
48
- console.log(`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`);
49
- });
50
- }
51
- }
52
- continue;
53
- }
54
- // <!-- Edit command -->
55
- let commandData = command.data;
56
- let editedCommand = false;
57
- // Edit command globally
58
- const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
59
- if (appGlobalCommand) {
60
- const commandsAreDifferent = (0, areSlashCommandsDifferent_1.default)(appGlobalCommand, commandData);
61
- if (commandsAreDifferent) {
62
- appGlobalCommand
63
- .edit(commandData)
64
- .then(() => {
65
- console.log(`✅ Edited command "${commandData.name}" globally.`);
66
- })
67
- .catch((error) => {
68
- console.log(`❌ Failed to edit command "${commandData.name}" globally.`);
69
- console.error(error);
70
- });
71
- editedCommand = true;
72
- }
73
- }
74
- // Edit command in a specific guild
75
- for (const guildCommands of devGuildCommands) {
76
- const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
77
- if (appGuildCommand) {
78
- const commandsAreDifferent = (0, areSlashCommandsDifferent_1.default)(appGuildCommand, commandData);
79
- if (commandsAreDifferent) {
80
- appGuildCommand
81
- .edit(commandData)
82
- .then(() => {
83
- console.log(`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`);
84
- })
85
- .catch((error) => {
86
- console.log(`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`);
87
- console.error(error);
88
- });
89
- editedCommand = true;
90
- }
91
- }
92
- }
93
- if (editedCommand)
94
- continue;
95
- // <!-- Register command -->
96
- // Register command in a specific guild
97
- if (command.options?.devOnly) {
98
- if (!devGuilds.length) {
99
- console.log(`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`);
100
- continue;
101
- }
102
- for (const guild of devGuilds) {
103
- const cmdExists = guild.commands.cache.some((cmd) => cmd.name === command.data.name);
104
- if (cmdExists)
105
- continue;
106
- guild?.commands
107
- .create(command.data)
108
- .then(() => {
109
- console.log(`✅ Registered command "${command.data.name}" in ${guild.name}.`);
110
- })
111
- .catch((error) => {
112
- console.log(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`);
113
- console.error(error);
114
- });
115
- }
116
- }
117
- // Register command globally
118
- else {
119
- const cmdExists = appCommands?.cache.some((cmd) => cmd.name === command.data.name);
120
- if (cmdExists)
121
- continue;
122
- appCommands
123
- ?.create(command.data)
124
- .then(() => {
125
- console.log(`✅ Registered command "${command.data.name}" globally.`);
126
- })
127
- .catch((error) => {
128
- console.log(`❌ Failed to register command "${command.data.name}" globally.`);
129
- console.error(error);
130
- });
131
- }
132
- }
133
- });
134
- }
135
- exports.default = registerCommands;
@@ -1 +0,0 @@
1
- export default function areSlashCommandsDifferent(appCommand: any, localCommand: any): true | undefined;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function areSlashCommandsDifferent(appCommand, localCommand) {
4
- if (!appCommand.options)
5
- appCommand.options = [];
6
- if (!localCommand.options)
7
- localCommand.options = [];
8
- if (!appCommand.description)
9
- appCommand.description = '';
10
- if (!localCommand.description)
11
- localCommand.description = '';
12
- if (localCommand.description !== appCommand.description ||
13
- localCommand.options.length !== appCommand.options.length) {
14
- return true;
15
- }
16
- }
17
- exports.default = areSlashCommandsDifferent;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = ({ interaction, targetCommand }) => {
4
- const botMember = interaction.guild?.members.me;
5
- if (targetCommand.options?.botPermissions && botMember) {
6
- for (const permission of targetCommand.options.botPermissions) {
7
- const hasPermission = botMember.permissions.has(permission);
8
- if (!hasPermission) {
9
- interaction.reply({
10
- content: `❌ I do not have enough permission to execute this command. Required permission: \`${permission}\``,
11
- ephemeral: true,
12
- });
13
- return true;
14
- }
15
- }
16
- }
17
- };
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = ({ interaction, targetCommand, handlerData }) => {
4
- if (targetCommand.options?.devOnly) {
5
- if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
6
- interaction.reply({
7
- content: '❌ This command can only be used inside development servers.',
8
- ephemeral: true,
9
- });
10
- return true;
11
- }
12
- const guildMember = interaction.guild?.members.cache.get(interaction.user.id);
13
- const memberRoles = guildMember?.roles.cache;
14
- let hasDevRole = false;
15
- memberRoles?.forEach((role) => {
16
- if (handlerData.devRoleIds?.includes(role.id)) {
17
- hasDevRole = true;
18
- }
19
- });
20
- const isDevUser = handlerData.devUserIds.includes(interaction.user.id) || hasDevRole;
21
- if (!isDevUser) {
22
- interaction.reply({
23
- content: '❌ This command can only be used by developers.',
24
- ephemeral: true,
25
- });
26
- return true;
27
- }
28
- }
29
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = ({ interaction, targetCommand }) => {
4
- if (targetCommand.options?.guildOnly && !interaction.inGuild()) {
5
- interaction.reply({
6
- content: '❌ This command can only be used inside a server.',
7
- ephemeral: true,
8
- });
9
- return true;
10
- }
11
- };
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = ({ interaction, targetCommand }) => {
4
- const memberPermissions = interaction.memberPermissions;
5
- if (targetCommand.options?.userPermissions && memberPermissions) {
6
- for (const permission of targetCommand.options.userPermissions) {
7
- const hasPermission = memberPermissions.has(permission);
8
- if (!hasPermission) {
9
- interaction.reply({
10
- content: `❌ You do not have enough permission to run this command. Required permission: \`${permission}\``,
11
- ephemeral: true,
12
- });
13
- return true;
14
- }
15
- }
16
- }
17
- };
@@ -1,11 +0,0 @@
1
- import { EventHandlerOptions, EventHandlerData } from './typings';
2
- export declare class EventHandler {
3
- _data: EventHandlerData;
4
- constructor({ ...options }: EventHandlerOptions);
5
- _buildEvents(): void;
6
- _registerEvents(): void;
7
- getEvents(): {
8
- name: string;
9
- functions: Function[];
10
- }[];
11
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventHandler = void 0;
4
- const get_paths_1 = require("../../utils/get-paths");
5
- class EventHandler {
6
- _data;
7
- constructor({ ...options }) {
8
- this._data = {
9
- ...options,
10
- events: [],
11
- };
12
- this._buildEvents();
13
- this._registerEvents();
14
- }
15
- _buildEvents() {
16
- const eventFolderPaths = (0, get_paths_1.getFolderPaths)(this._data.eventsPath);
17
- for (const eventFolderPath of eventFolderPaths) {
18
- const eventName = eventFolderPath.replace(/\\/g, '/').split('/').pop();
19
- const eventFilePaths = (0, get_paths_1.getFilePaths)(eventFolderPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
20
- const eventObj = {
21
- name: eventName,
22
- functions: [],
23
- };
24
- this._data.events.push(eventObj);
25
- for (const eventFilePath of eventFilePaths) {
26
- const eventFunction = require(eventFilePath);
27
- if (typeof eventFunction !== 'function') {
28
- console.log(`Ignoring: Event ${eventFilePath} does not export a function.`);
29
- continue;
30
- }
31
- eventObj.functions.push(eventFunction);
32
- }
33
- }
34
- }
35
- _registerEvents() {
36
- const client = this._data.client;
37
- for (const eventObj of this._data.events) {
38
- client.on(eventObj.name, async (...params) => {
39
- for (const eventFunction of eventObj.functions) {
40
- const stopEventLoop = await eventFunction(...params, client);
41
- if (stopEventLoop) {
42
- break;
43
- }
44
- }
45
- });
46
- }
47
- }
48
- getEvents() {
49
- return this._data.events;
50
- }
51
- }
52
- exports.EventHandler = EventHandler;
@@ -1,3 +0,0 @@
1
- export * from './command-handler/CommandHandler';
2
- export * from './event-handler/EventHandler';
3
- export * from './validation-handler/ValidationHandler';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./command-handler/CommandHandler"), exports);
18
- __exportStar(require("./event-handler/EventHandler"), exports);
19
- __exportStar(require("./validation-handler/ValidationHandler"), exports);
@@ -1,7 +0,0 @@
1
- import { ValidationHandlerData, ValidationHandlerOptions } from './typings';
2
- export declare class ValidationHandler {
3
- _data: ValidationHandlerData;
4
- constructor({ ...options }: ValidationHandlerOptions);
5
- _buildValidations(): void;
6
- getValidations(): Function[];
7
- }
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationHandler = void 0;
4
- const get_paths_1 = require("../../utils/get-paths");
5
- class ValidationHandler {
6
- _data;
7
- constructor({ ...options }) {
8
- this._data = {
9
- ...options,
10
- validations: [],
11
- };
12
- this._buildValidations();
13
- }
14
- _buildValidations() {
15
- const validationFilePaths = (0, get_paths_1.getFilePaths)(this._data.validationsPath, true).filter((path) => path.endsWith('.js') || path.endsWith('.ts'));
16
- for (const validationFilePath of validationFilePaths) {
17
- const validationFunction = require(validationFilePath);
18
- if (typeof validationFunction !== 'function') {
19
- console.log(`Ignoring: Validation ${validationFilePath} does not export a function.`);
20
- continue;
21
- }
22
- this._data.validations.push(validationFunction);
23
- }
24
- }
25
- getValidations() {
26
- return this._data.validations;
27
- }
28
- }
29
- exports.ValidationHandler = ValidationHandler;
@@ -1,3 +0,0 @@
1
- declare function getFilePaths(directory: string, nesting?: boolean): string[];
2
- declare function getFolderPaths(directory: string, nesting?: boolean): string[];
3
- export { getFilePaths, getFolderPaths };