commandkit 0.1.11-dev.20250331033059 → 0.1.11-dev.20250402101800

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.
package/dist/index.d.ts CHANGED
@@ -907,6 +907,7 @@ declare const CommandExecutionMode: {
907
907
  };
908
908
  type CommandExecutionMode = (typeof CommandExecutionMode)[keyof typeof CommandExecutionMode];
909
909
  interface ContextParameters<T extends CommandExecutionMode, Args = Record<string, any>> {
910
+ command: LoadedCommand;
910
911
  environment?: CommandKitEnvironment;
911
912
  executionMode: T;
912
913
  interaction: T extends 'chatInput' ? ChatInputCommandInteraction : T extends 'messageContextMenu' ? MessageContextMenuCommandInteraction : T extends 'userContextMenu' ? UserContextMenuCommandInteraction : T extends 'autocomplete' ? AutocompleteInteraction : never;
@@ -954,6 +955,10 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
954
955
  * The client instance.
955
956
  */
956
957
  readonly client: Client;
958
+ /**
959
+ * The command that this context belongs to.
960
+ */
961
+ readonly command: LoadedCommand;
957
962
  private _locale;
958
963
  /**
959
964
  * Creates a new command context.
@@ -1307,7 +1312,7 @@ declare class CommandsRouter {
1307
1312
  */
1308
1313
  interface EventsRouterOptions {
1309
1314
  /** Root directory path where event handlers are located */
1310
- entrypoint: string;
1315
+ entrypoints: string[];
1311
1316
  }
1312
1317
  /**
1313
1318
  * Represents a parsed event with its handlers
@@ -1339,6 +1344,11 @@ declare class EventsRouter {
1339
1344
  * @throws Error if entrypoint is not provided
1340
1345
  */
1341
1346
  constructor(options: EventsRouterOptions);
1347
+ /**
1348
+ * Adds new entrypoints to the router
1349
+ * @param entrypoints - Array of new entrypoint paths
1350
+ */
1351
+ addEntrypoints(entrypoints: string[]): void;
1342
1352
  /**
1343
1353
  * Find a parsed event by its name
1344
1354
  * @param event - Name of the event to find
@@ -1349,7 +1359,7 @@ declare class EventsRouter {
1349
1359
  * Get the entrypoint directory path
1350
1360
  * @returns Entrypoint directory path
1351
1361
  */
1352
- get entrypoint(): string;
1362
+ get entrypoints(): string[];
1353
1363
  /**
1354
1364
  * Checks if the entrypoint path is valid
1355
1365
  */
@@ -1432,12 +1442,18 @@ declare class AppCommandHandler {
1432
1442
  private onMessageCreate;
1433
1443
  private onMessageUpdate;
1434
1444
  readonly commandRunner: AppCommandRunner;
1445
+ readonly externalCommandData: Collection<string, Command>;
1446
+ readonly externalMiddlewareData: Collection<string, Middleware>;
1435
1447
  constructor(commandkit: CommandKit);
1436
1448
  printBanner(): void;
1437
1449
  getCommandsArray(): LoadedCommand[];
1438
1450
  registerCommandHandler(): void;
1439
1451
  prepareCommandRun(source: Interaction | Message$1, cmdName?: string): Promise<PreparedAppCommandExecution | null>;
1440
1452
  reloadCommands(): Promise<void>;
1453
+ addExternalMiddleware(data: Middleware[]): Promise<void>;
1454
+ addExternalCommands(data: Command[]): Promise<void>;
1455
+ registerExternalLoadedMiddleware(data: LoadedMiddleware[]): Promise<void>;
1456
+ registerExternalLoadedCommands(data: LoadedCommand[]): Promise<void>;
1441
1457
  loadCommands(): Promise<void>;
1442
1458
  private loadMiddleware;
1443
1459
  private loadCommand;
@@ -1657,6 +1673,13 @@ type CommandSource = Interaction | Message$1;
1657
1673
  declare function isMessageSource(source: CommandSource): source is Message$1;
1658
1674
  declare function isInteractionSource(source: CommandSource): source is Interaction;
1659
1675
 
1676
+ interface CommandKitHMREvent {
1677
+ event: string;
1678
+ path: string;
1679
+ accept: () => void;
1680
+ preventDefault: () => void;
1681
+ }
1682
+
1660
1683
  declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> extends PluginCommon<T, CommandKitPluginRuntime> {
1661
1684
  /**
1662
1685
  * Called before commands are loaded
@@ -1704,6 +1727,22 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
1704
1727
  * @param execute The function that executes the command
1705
1728
  */
1706
1729
  executeCommand(ctx: CommandKitPluginRuntime, env: CommandKitEnvironment, source: Interaction | Message$1, command: PreparedAppCommandExecution, execute: () => Promise<any>): Promise<boolean>;
1730
+ /**
1731
+ * Called after events router is initialized
1732
+ * @param ctx The context
1733
+ */
1734
+ onEventsRouterInit(ctx: CommandKitPluginRuntime): Promise<void>;
1735
+ /**
1736
+ * Called after commands router is initialized
1737
+ * @param ctx The context
1738
+ */
1739
+ onCommandsRouterInit(ctx: CommandKitPluginRuntime): Promise<void>;
1740
+ /**
1741
+ * Called when HMR event is received
1742
+ * @param ctx The context
1743
+ * @param event The event
1744
+ */
1745
+ performHMR(ctx: CommandKitPluginRuntime, event: CommandKitHMREvent): Promise<void>;
1707
1746
  }
1708
1747
  declare function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin;
1709
1748
 
@@ -1959,6 +1998,8 @@ declare const Logger: LoggerImpl;
1959
1998
  */
1960
1999
  declare const version: string;
1961
2000
 
2001
+ declare function getCurrentDirectory(): string;
2002
+
1962
2003
  /**
1963
2004
  * Creates a command line interface for CommandKit.
1964
2005
  * @param argv The arguments passed to the CLI.
@@ -1966,4 +2007,4 @@ declare const version: string;
1966
2007
  */
1967
2008
  declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
1968
2009
 
1969
- export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, type CommandLocalizationTypeData, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type Location, Logger, type LoggerImpl, type MaybeArray, type MaybeFalsey, MemoryCache, MentionableSelectMenu, MentionableSelectMenuKit, type MentionableSelectMenuKitPredicate, type MentionableSelectMenuProps, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnChannelSelectMenuKitSubmit, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnMentionableSelectMenuKitSubmit, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, type OnRoleSelectMenuKitSubmit, type OnSelectMenuKitEnd, type OnSelectMenuKitSubmit, type OnStringSelectMenuKitSubmit, type OnUserSelectMenuKitSubmit, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveBuilderInteraction, type ResolveKind, type ResolveResult, RoleSelectMenu, RoleSelectMenuKit, type RoleSelectMenuKitPredicate, type RoleSelectMenuProps, type RunCommand, RuntimePlugin, type SelectMenuKitPredicate, type SelectMenuProps, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, StringSelectMenu, StringSelectMenuKit, type StringSelectMenuKitPredicate, StringSelectMenuOption, type StringSelectMenuOptionProps, type StringSelectMenuProps, TextInput, type TextInputProps, type TransformedResult, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandName, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getElement, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
2010
+ export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, type CommandLocalizationTypeData, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type Location, Logger, type LoggerImpl, type MaybeArray, type MaybeFalsey, MemoryCache, MentionableSelectMenu, MentionableSelectMenuKit, type MentionableSelectMenuKitPredicate, type MentionableSelectMenuProps, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnChannelSelectMenuKitSubmit, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnMentionableSelectMenuKitSubmit, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, type OnRoleSelectMenuKitSubmit, type OnSelectMenuKitEnd, type OnSelectMenuKitSubmit, type OnStringSelectMenuKitSubmit, type OnUserSelectMenuKitSubmit, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveBuilderInteraction, type ResolveKind, type ResolveResult, RoleSelectMenu, RoleSelectMenuKit, type RoleSelectMenuKitPredicate, type RoleSelectMenuProps, type RunCommand, RuntimePlugin, type SelectMenuKitPredicate, type SelectMenuProps, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, StringSelectMenu, StringSelectMenuKit, type StringSelectMenuKitPredicate, StringSelectMenuOption, type StringSelectMenuOptionProps, type StringSelectMenuProps, TextInput, type TextInputProps, type TransformedResult, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandName, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getCurrentDirectory, getElement, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
package/dist/index.js CHANGED
@@ -2009,6 +2009,25 @@ var init_RuntimePlugin = __esm({
2009
2009
  async executeCommand(ctx, env, source, command, execute) {
2010
2010
  return false;
2011
2011
  }
2012
+ /**
2013
+ * Called after events router is initialized
2014
+ * @param ctx The context
2015
+ */
2016
+ async onEventsRouterInit(ctx) {
2017
+ }
2018
+ /**
2019
+ * Called after commands router is initialized
2020
+ * @param ctx The context
2021
+ */
2022
+ async onCommandsRouterInit(ctx) {
2023
+ }
2024
+ /**
2025
+ * Called when HMR event is received
2026
+ * @param ctx The context
2027
+ * @param event The event
2028
+ */
2029
+ async performHMR(ctx, event) {
2030
+ }
2012
2031
  };
2013
2032
  __name(_RuntimePlugin, "RuntimePlugin");
2014
2033
  RuntimePlugin = _RuntimePlugin;
@@ -2960,6 +2979,16 @@ ${translationTypes}
2960
2979
  });
2961
2980
 
2962
2981
  // src/utils/utilities.ts
2982
+ function getCurrentDirectory() {
2983
+ if (currentDir) return currentDir;
2984
+ let root = (0, import_node_path2.join)(
2985
+ process.cwd(),
2986
+ COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir
2987
+ );
2988
+ if (!(0, import_node_fs2.existsSync)(root)) root = process.cwd();
2989
+ currentDir = root;
2990
+ return root;
2991
+ }
2963
2992
  function findAppDirectory() {
2964
2993
  if (appDir) return appDir;
2965
2994
  let root = (0, import_node_path2.join)(
@@ -2997,7 +3026,7 @@ function debounce(fn, ms2) {
2997
3026
  });
2998
3027
  };
2999
3028
  }
3000
- var import_node_fs2, import_node_path2, appDir;
3029
+ var import_node_fs2, import_node_path2, appDir, currentDir;
3001
3030
  var init_utilities = __esm({
3002
3031
  "src/utils/utilities.ts"() {
3003
3032
  "use strict";
@@ -3007,6 +3036,8 @@ var init_utilities = __esm({
3007
3036
  init_constants();
3008
3037
  init_config();
3009
3038
  appDir = null;
3039
+ currentDir = null;
3040
+ __name(getCurrentDirectory, "getCurrentDirectory");
3010
3041
  __name(findAppDirectory, "findAppDirectory");
3011
3042
  __name(debounce, "debounce");
3012
3043
  }
@@ -3821,12 +3852,17 @@ var init_Context = __esm({
3821
3852
  * The client instance.
3822
3853
  */
3823
3854
  __publicField(this, "client");
3855
+ /**
3856
+ * The command that this context belongs to.
3857
+ */
3858
+ __publicField(this, "command");
3824
3859
  __privateAdd(this, _store);
3825
3860
  __publicField(this, "_locale", null);
3826
3861
  this.interaction = config.interaction;
3827
3862
  this.message = config.message;
3828
3863
  this.client = commandkit2.client;
3829
3864
  __privateSet(this, _store, config.store ?? /* @__PURE__ */ new Map());
3865
+ this.command = config.command;
3830
3866
  }
3831
3867
  /**
3832
3868
  * The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
@@ -4126,6 +4162,7 @@ var init_AppCommandRunner = __esm({
4126
4162
  env.variables.set("currentCommandName", prepared.command.command.name);
4127
4163
  env.variables.set("execHandlerKind", executionMode);
4128
4164
  const ctx = new MiddlewareContext(commandkit2, {
4165
+ command: prepared.command,
4129
4166
  environment: env,
4130
4167
  executionMode,
4131
4168
  interaction: !(source instanceof import_discord15.Message) ? source : null,
@@ -4374,6 +4411,8 @@ var init_AppCommandHandler = __esm({
4374
4411
  onMessageCreate = null;
4375
4412
  onMessageUpdate = null;
4376
4413
  commandRunner = new AppCommandRunner(this);
4414
+ externalCommandData = new import_discord16.Collection();
4415
+ externalMiddlewareData = new import_discord16.Collection();
4377
4416
  printBanner() {
4378
4417
  const categorizedCommands = this.getCommandsArray().reduce(
4379
4418
  (acc, cmd) => {
@@ -4500,7 +4539,8 @@ var init_AppCommandHandler = __esm({
4500
4539
  return null;
4501
4540
  }
4502
4541
  } else {
4503
- if (!source.isCommand()) return null;
4542
+ const isAnyCommand = source.isChatInputCommand() || source.isAutocomplete() || source.isContextMenuCommand();
4543
+ if (!isAnyCommand) return null;
4504
4544
  cmdName = source.commandName;
4505
4545
  }
4506
4546
  }
@@ -4508,7 +4548,7 @@ var init_AppCommandHandler = __esm({
4508
4548
  if (!commandId) return null;
4509
4549
  const loadedCommand = this.loadedCommands.get(commandId);
4510
4550
  if (!loadedCommand) return null;
4511
- if (source instanceof import_discord16.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
4551
+ if ((source instanceof import_discord16.CommandInteraction || source instanceof import_discord16.AutocompleteInteraction) && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
4512
4552
  return null;
4513
4553
  }
4514
4554
  const middlewares = [];
@@ -4529,18 +4569,48 @@ var init_AppCommandHandler = __esm({
4529
4569
  this.loadedMiddlewares.clear();
4530
4570
  this.commandNameToId.clear();
4531
4571
  this.subcommandPathToId.clear();
4572
+ this.externalCommandData.clear();
4573
+ this.externalMiddlewareData.clear();
4532
4574
  await this.loadCommands();
4533
4575
  }
4576
+ async addExternalMiddleware(data) {
4577
+ for (const middleware of data) {
4578
+ if (!middleware.id) continue;
4579
+ this.externalMiddlewareData.set(middleware.id, middleware);
4580
+ }
4581
+ }
4582
+ async addExternalCommands(data) {
4583
+ for (const command of data) {
4584
+ if (!command.id) continue;
4585
+ this.externalCommandData.set(command.id, command);
4586
+ }
4587
+ }
4588
+ async registerExternalLoadedMiddleware(data) {
4589
+ for (const middleware of data) {
4590
+ this.loadedMiddlewares.set(middleware.middleware.id, middleware);
4591
+ }
4592
+ }
4593
+ async registerExternalLoadedCommands(data) {
4594
+ for (const command of data) {
4595
+ this.loadedCommands.set(command.command.id, command);
4596
+ this.commandNameToId.set(command.command.name, command.command.id);
4597
+ }
4598
+ }
4534
4599
  async loadCommands() {
4600
+ await this.commandkit.plugins.execute((ctx, plugin) => {
4601
+ return plugin.onBeforeCommandsLoad(ctx);
4602
+ });
4535
4603
  const commandsRouter = this.commandkit.commandsRouter;
4536
4604
  if (!commandsRouter) {
4537
4605
  throw new Error("Commands router has not yet initialized");
4538
4606
  }
4539
4607
  const { commands, middlewares } = commandsRouter.getData();
4540
- for (const [id, middleware] of middlewares) {
4608
+ const combinedCommands = this.externalCommandData.size ? commands.concat(this.externalCommandData) : commands;
4609
+ const combinedMiddlewares = this.externalMiddlewareData.size ? middlewares.concat(this.externalMiddlewareData) : middlewares;
4610
+ for (const [id, middleware] of combinedMiddlewares) {
4541
4611
  await this.loadMiddleware(id, middleware);
4542
4612
  }
4543
- for (const [id, command] of commands) {
4613
+ for (const [id, command] of combinedCommands) {
4544
4614
  await this.loadCommand(id, command);
4545
4615
  }
4546
4616
  if (COMMANDKIT_IS_DEV) {
@@ -4550,6 +4620,9 @@ var init_AppCommandHandler = __esm({
4550
4620
  ).join(" | ")}`
4551
4621
  );
4552
4622
  }
4623
+ await this.commandkit.plugins.execute((ctx, plugin) => {
4624
+ return plugin.onAfterCommandsLoad(ctx);
4625
+ });
4553
4626
  }
4554
4627
  async loadMiddleware(id, middleware) {
4555
4628
  try {
@@ -4888,12 +4961,25 @@ var init_EventsRouter = __esm({
4888
4961
  */
4889
4962
  constructor(options) {
4890
4963
  this.options = options;
4891
- if (!options.entrypoint) {
4964
+ var _a;
4965
+ if (options.entrypoints) {
4966
+ options.entrypoints = Array.from(new Set(options.entrypoints));
4967
+ }
4968
+ if (!((_a = options.entrypoints) == null ? void 0 : _a.length)) {
4892
4969
  throw new Error("Entrypoint directory must be provided");
4893
4970
  }
4894
4971
  }
4895
4972
  /** Internal storage of parsed events */
4896
4973
  events = new import_discord18.Collection();
4974
+ /**
4975
+ * Adds new entrypoints to the router
4976
+ * @param entrypoints - Array of new entrypoint paths
4977
+ */
4978
+ addEntrypoints(entrypoints) {
4979
+ this.options.entrypoints = Array.from(
4980
+ /* @__PURE__ */ new Set([...this.options.entrypoints, ...entrypoints])
4981
+ );
4982
+ }
4897
4983
  /**
4898
4984
  * Find a parsed event by its name
4899
4985
  * @param event - Name of the event to find
@@ -4906,14 +4992,14 @@ var init_EventsRouter = __esm({
4906
4992
  * Get the entrypoint directory path
4907
4993
  * @returns Entrypoint directory path
4908
4994
  */
4909
- get entrypoint() {
4910
- return this.options.entrypoint;
4995
+ get entrypoints() {
4996
+ return this.options.entrypoints;
4911
4997
  }
4912
4998
  /**
4913
4999
  * Checks if the entrypoint path is valid
4914
5000
  */
4915
5001
  isValidPath() {
4916
- return (0, import_node_fs5.existsSync)(this.entrypoint);
5002
+ return this.entrypoints.every((entrypoint) => (0, import_node_fs5.existsSync)(entrypoint));
4917
5003
  }
4918
5004
  /**
4919
5005
  * Clear all parsed events
@@ -4934,11 +5020,13 @@ var init_EventsRouter = __esm({
4934
5020
  * @returns Promise resolving to the events tree
4935
5021
  */
4936
5022
  async scan() {
4937
- const dirs = await (0, import_promises5.readdir)(this.entrypoint, { withFileTypes: true });
4938
- for (const dir of dirs) {
4939
- if (dir.isDirectory()) {
4940
- const path2 = (0, import_node_path5.join)(this.entrypoint, dir.name);
4941
- await this.scanEvent(dir.name, path2, null, [], true);
5023
+ for (const entrypoint of this.entrypoints) {
5024
+ const dirs = await (0, import_promises5.readdir)(entrypoint, { withFileTypes: true });
5025
+ for (const dir of dirs) {
5026
+ if (dir.isDirectory()) {
5027
+ const path2 = (0, import_node_path5.join)(entrypoint, dir.name);
5028
+ await this.scanEvent(dir.name, path2, null, [], true);
5029
+ }
4942
5030
  }
4943
5031
  }
4944
5032
  return Object.fromEntries(this.events);
@@ -5010,6 +5098,9 @@ var init_AppEventsHandler = __esm({
5010
5098
  await this.loadEvents();
5011
5099
  }
5012
5100
  async loadEvents() {
5101
+ await this.commandkit.plugins.execute((ctx, plugin) => {
5102
+ return plugin.onBeforeEventsLoad(ctx);
5103
+ });
5013
5104
  const router = this.commandkit.eventsRouter;
5014
5105
  const events = await router.scan();
5015
5106
  for (const event of Object.values(events)) {
@@ -5044,6 +5135,9 @@ var init_AppEventsHandler = __esm({
5044
5135
  );
5045
5136
  }
5046
5137
  this.registerAllClientEvents();
5138
+ await this.commandkit.plugins.execute((ctx, plugin) => {
5139
+ return plugin.onAfterEventsLoad(ctx);
5140
+ });
5047
5141
  }
5048
5142
  unregisterAll() {
5049
5143
  this.unregisterAllClientListeners();
@@ -5259,13 +5353,30 @@ var init_loader = __esm({
5259
5353
  // src/utils/dev-hooks.ts
5260
5354
  function registerDevHooks(commandkit2) {
5261
5355
  if (!COMMANDKIT_IS_DEV) return;
5262
- process.on("message", (message) => {
5356
+ process.on("message", async (message) => {
5263
5357
  if (typeof message !== "object" || message === null) return;
5264
5358
  const { event, path: path2 } = message;
5265
5359
  if (!event) return;
5266
5360
  if (process.env.COMMANDKIT_DEBUG_HMR === "true") {
5267
5361
  Logger.info(`Received HMR event: ${event}${path2 ? ` for ${path2}` : ""}`);
5268
5362
  }
5363
+ let accepted = false, prevented = false;
5364
+ const hmrEvent = {
5365
+ accept() {
5366
+ accepted = true;
5367
+ },
5368
+ preventDefault() {
5369
+ prevented = false;
5370
+ },
5371
+ path: path2,
5372
+ event
5373
+ };
5374
+ await commandkit2.plugins.execute(async (ctx, plugin) => {
5375
+ var _a;
5376
+ if (accepted) return;
5377
+ await ((_a = plugin.performHMR) == null ? void 0 : _a.call(plugin, ctx, hmrEvent));
5378
+ });
5379
+ if (prevented) return;
5269
5380
  switch (event) {
5270
5381
  case "reload-commands":
5271
5382
  commandkit2.commandHandler.reloadCommands();
@@ -5579,16 +5690,19 @@ var init_CommandKit = __esm({
5579
5690
  this.commandsRouter = new CommandsRouter({
5580
5691
  entrypoint: commandsPath
5581
5692
  });
5693
+ await this.plugins.execute((ctx, plugin) => {
5694
+ return plugin.onCommandsRouterInit(ctx);
5695
+ });
5582
5696
  this.eventsRouter = new EventsRouter({
5583
- entrypoint: events
5697
+ entrypoints: [events]
5698
+ });
5699
+ await this.plugins.execute((ctx, plugin) => {
5700
+ return plugin.onEventsRouterInit(ctx);
5584
5701
  });
5585
5702
  await __privateMethod(this, _CommandKit_instances, initEvents_fn).call(this);
5586
5703
  await __privateMethod(this, _CommandKit_instances, initCommands_fn).call(this);
5587
5704
  }, "#init");
5588
5705
  initCommands_fn = /* @__PURE__ */ __name(async function() {
5589
- await this.plugins.execute((ctx, plugin) => {
5590
- return plugin.onBeforeCommandsLoad(ctx);
5591
- });
5592
5706
  if (this.commandsRouter.isValidPath()) {
5593
5707
  const result = await this.commandsRouter.scan();
5594
5708
  if (COMMANDKIT_IS_DEV) {
@@ -5599,22 +5713,13 @@ var init_CommandKit = __esm({
5599
5713
  }
5600
5714
  }
5601
5715
  await this.commandHandler.loadCommands();
5602
- await this.plugins.execute((ctx, plugin) => {
5603
- return plugin.onAfterCommandsLoad(ctx);
5604
- });
5605
5716
  this.commandHandler.printBanner();
5606
5717
  }, "#initCommands");
5607
5718
  initEvents_fn = /* @__PURE__ */ __name(async function() {
5608
- await this.plugins.execute((ctx, plugin) => {
5609
- return plugin.onBeforeEventsLoad(ctx);
5610
- });
5611
5719
  if (this.eventsRouter.isValidPath()) {
5612
5720
  await this.eventsRouter.scan();
5613
5721
  }
5614
5722
  await this.eventHandler.loadEvents();
5615
- await this.plugins.execute((ctx, plugin) => {
5616
- return plugin.onAfterEventsLoad(ctx);
5617
- });
5618
5723
  }, "#initEvents");
5619
5724
  __name(_CommandKit, "CommandKit");
5620
5725
  __publicField(_CommandKit, "createElement", createElement);
@@ -5635,7 +5740,7 @@ var init_version = __esm({
5635
5740
  "use strict";
5636
5741
  init_cjs_shims();
5637
5742
  version = /* @__MACRO__ $version */
5638
- "0.1.11-dev.20250331033059";
5743
+ "0.1.11-dev.20250402101800";
5639
5744
  }
5640
5745
  });
5641
5746
 
@@ -6236,6 +6341,7 @@ __export(index_exports, {
6236
6341
  getCommandKit: () => getCommandKit,
6237
6342
  getConfig: () => getConfig,
6238
6343
  getContext: () => getContext,
6344
+ getCurrentDirectory: () => getCurrentDirectory,
6239
6345
  getElement: () => getElement,
6240
6346
  invalidate: () => invalidate,
6241
6347
  isCachedFunction: () => isCachedFunction,
@@ -6303,6 +6409,7 @@ init_Logger();
6303
6409
  init_router();
6304
6410
  init_version();
6305
6411
  init_plugins();
6412
+ init_utilities();
6306
6413
 
6307
6414
  // src/cli/init.ts
6308
6415
  init_cjs_shims();
@@ -6427,6 +6534,7 @@ var index_default = CommandKit;
6427
6534
  getCommandKit,
6428
6535
  getConfig,
6429
6536
  getContext,
6537
+ getCurrentDirectory,
6430
6538
  getElement,
6431
6539
  invalidate,
6432
6540
  isCachedFunction,