commandkit 0.1.11-dev.20250327153237 → 0.1.11-dev.20250328083250

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
@@ -582,11 +582,15 @@ interface ApiTranslatableCommandOptions extends TranslatableCommandOptions {
582
582
  name_localizations?: LocalizationMap;
583
583
  description_localizations?: LocalizationMap;
584
584
  }
585
+ interface CommandLocalizationTypeData {
586
+ [key: string]: Record<string, string | null>;
587
+ }
588
+ type TranslatableCommandName = string & {};
585
589
  interface Translation {
586
590
  command: TranslatableCommand;
587
- translations: TranslatableArguments;
591
+ translations: Record<string, string>;
588
592
  }
589
- type TranslatableArguments = Record<string, string>;
593
+ type TranslatableArguments<T extends TranslatableCommandName> = T extends TranslatableCommandName ? CommandLocalizationTypeData[T] extends Record<string, infer ArgType> ? ArgType extends null ? never : Record<string, string> : Record<string, string> : Record<string, string>;
590
594
 
591
595
  interface LocalizationTranslationRequest {
592
596
  locale: Locale;
@@ -612,15 +616,15 @@ interface LocalizationConfig {
612
616
  */
613
617
  target: string;
614
618
  }
615
- type Translator = (translatable: string, args?: TranslatableArguments | undefined) => Promise<TranslationResult>;
616
- declare class Localization {
619
+ type Translator<T extends TranslatableCommandName> = <K extends keyof CommandLocalizationTypeData[T] & string>(key: K, args?: CommandLocalizationTypeData[T][K] extends null ? never : CommandLocalizationTypeData[T][K] extends string ? Record<CommandLocalizationTypeData[T][K], string> : Record<string, string>) => Promise<TranslationResult>;
620
+ declare class Localization<T extends TranslatableCommandName = string> {
617
621
  private readonly commandkit;
618
622
  private readonly config;
619
623
  /**
620
624
  * Translates the given translatable object.
621
625
  * @param translatable The translatable object to translate.
622
626
  */
623
- readonly t: Translator;
627
+ readonly t: Translator<T>;
624
628
  /**
625
629
  * Creates a new localization instance.
626
630
  * @param commandkit The command kit instance.
@@ -917,7 +921,7 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
917
921
  * Forwards the context to another command. The target handler will be the same as current handler.
918
922
  * @param command The command to forward to.
919
923
  */
920
- forwardCommand(command: string): Promise<never>;
924
+ forwardCommand<C extends ResolvableCommand>(command: C): Promise<never>;
921
925
  /**
922
926
  * The execution mode of the command.
923
927
  */
@@ -972,8 +976,9 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
972
976
  /**
973
977
  * Returns the i18n api for this command.
974
978
  * @param locale The locale to use for the i18n api.
979
+ * @template T The command name for type-safe translations. Will provide autocomplete from available translations.
975
980
  */
976
- locale(locale?: Locale): Localization;
981
+ locale<T extends TranslatableCommandName | (string & {}) = string>(locale?: Locale): Localization<T extends TranslatableCommandName ? T : string>;
977
982
  /**
978
983
  * Creates a clone of this context
979
984
  */
@@ -1348,6 +1353,8 @@ interface LoadedCommand {
1348
1353
  data: AppCommand;
1349
1354
  guilds?: string[];
1350
1355
  }
1356
+ type CommandTypeData = string;
1357
+ type ResolvableCommand = CommandTypeData | (string & {});
1351
1358
  interface LoadedMiddleware {
1352
1359
  middleware: Middleware;
1353
1360
  data: AppCommandMiddleware;
@@ -1927,4 +1934,4 @@ declare const version: string;
1927
1934
  */
1928
1935
  declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
1929
1936
 
1930
- export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, 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 CommandObject, type CommandOptions, type CommandProps, CommandsRouter, type CommandsRouterOptions, type CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, Context, type ContextMenuCommandProps, 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, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, type ResolveKind, type ResolveResult, type RunCommand, RuntimePlugin, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TransformedResult, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isRuntimePlugin, makeContextAwareFunction, 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 };
1937
+ export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, 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 CommandLocalizationTypeData, type CommandObject, type CommandOptions, type CommandProps, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, Context, type ContextMenuCommandProps, 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, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, type ResolvableCommand, type ResolveKind, type ResolveResult, type RunCommand, RuntimePlugin, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, 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, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isRuntimePlugin, makeContextAwareFunction, 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
@@ -1971,6 +1971,18 @@ var init_config = __esm({
1971
1971
  }
1972
1972
  });
1973
1973
 
1974
+ // src/utils/constants.ts
1975
+ var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST;
1976
+ var init_constants = __esm({
1977
+ "src/utils/constants.ts"() {
1978
+ "use strict";
1979
+ init_cjs_shims();
1980
+ COMMANDKIT_CACHE_TAG = Symbol("kCommandKitCacheTag");
1981
+ COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
1982
+ COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === "true";
1983
+ }
1984
+ });
1985
+
1974
1986
  // src/app/i18n/DefaultLocalizationStrategy.ts
1975
1987
  var import_promises2, import_node_path, import_node_fs, _DefaultLocalizationStrategy, DefaultLocalizationStrategy;
1976
1988
  var init_DefaultLocalizationStrategy = __esm({
@@ -1981,6 +1993,7 @@ var init_DefaultLocalizationStrategy = __esm({
1981
1993
  import_node_path = require("path");
1982
1994
  init_config();
1983
1995
  import_node_fs = require("fs");
1996
+ init_constants();
1984
1997
  _DefaultLocalizationStrategy = class _DefaultLocalizationStrategy {
1985
1998
  constructor(commandkit2) {
1986
1999
  this.commandkit = commandkit2;
@@ -1989,17 +2002,38 @@ var init_DefaultLocalizationStrategy = __esm({
1989
2002
  async locateTranslation(scope, locale) {
1990
2003
  const localesPath = this.commandkit.getPath("locales");
1991
2004
  if (!localesPath) return null;
1992
- const path2 = (0, import_node_path.join)(localesPath, locale, `${scope}.json`);
1993
- try {
1994
- const data = await (0, import_promises2.readFile)(path2, "utf-8");
1995
- const localeData = JSON.parse(data);
1996
- await this.generateLocaleTypes(localeData);
1997
- return localeData;
1998
- } catch {
1999
- return null;
2005
+ const paths = [".js", ".json", ".mjs", ".cjs"].map(
2006
+ (e) => (0, import_node_path.join)(localesPath, locale, scope) + e
2007
+ );
2008
+ for (const path2 of paths) {
2009
+ if (!(0, import_node_fs.existsSync)(path2)) {
2010
+ continue;
2011
+ }
2012
+ try {
2013
+ let localeData;
2014
+ try {
2015
+ if (path2.endsWith(".json")) {
2016
+ const data = await (0, import_promises2.readFile)(path2, "utf-8");
2017
+ localeData = JSON.parse(data);
2018
+ } else {
2019
+ const { default: data } = await import(`file://${path2}`);
2020
+ localeData = data;
2021
+ }
2022
+ } catch {
2023
+ continue;
2024
+ }
2025
+ if (!localeData) continue;
2026
+ await this.generateLocaleTypes(localeData).catch(() => {
2027
+ });
2028
+ return localeData;
2029
+ } catch {
2030
+ return null;
2031
+ }
2000
2032
  }
2033
+ return null;
2001
2034
  }
2002
2035
  async generateLocaleTypes(localeData) {
2036
+ if (!COMMANDKIT_IS_DEV) return;
2003
2037
  const { typedLocales } = getConfig();
2004
2038
  if (!typedLocales) return;
2005
2039
  const file = (0, import_node_path.join)(
@@ -2009,43 +2043,58 @@ var init_DefaultLocalizationStrategy = __esm({
2009
2043
  "locale_types.d.ts"
2010
2044
  );
2011
2045
  const header = `// auto generated file do not edit
2046
+ export {};
2012
2047
  declare module 'commandkit' {
2013
2048
  export interface CommandLocalizationTypeData {
2014
2049
  `;
2015
- const footer = ` }
2050
+ const footer = ` type TranslatableCommandName = keyof CommandLocalizationTypeData
2051
+ }
2016
2052
  }`;
2017
2053
  const generateType = /* @__PURE__ */ __name((locale) => {
2018
- return `"${locale.command}": ${JSON.stringify(
2019
- Object.entries(locale.translations).map(([key, value]) => {
2020
- const args = value.match(/{([^}]+)}/g);
2021
- if (!args) return `${JSON.stringify(key)}: null`;
2022
- return `${JSON.stringify(key)}: ${args.map((arg) => arg.slice(1, -1)).join(" | ")}`;
2023
- }),
2024
- null,
2025
- 2
2026
- )}`;
2054
+ const commandName = locale.command.name;
2055
+ const translationTypes = Object.entries(locale.translations).map(([key, value]) => {
2056
+ const args = value.match(/{([^}]+)}/g);
2057
+ if (!args) {
2058
+ return ` "${key}": null`;
2059
+ }
2060
+ const argUnion = args.map((arg) => `"${arg.slice(1, -1)}"`).join(" | ");
2061
+ return ` "${key}": ${argUnion}`;
2062
+ }).join(",\n");
2063
+ return ` "${commandName}": {
2064
+ ${translationTypes}
2065
+ }`;
2027
2066
  }, "generateType");
2028
- if (!(0, import_node_fs.existsSync)(file)) {
2029
- const generated = generateType(localeData);
2030
- await (0, import_promises2.writeFile)(file, `${header}${generated}${footer}`);
2031
- } else {
2032
- const data = await (0, import_promises2.readFile)(file, "utf-8");
2033
- const lines = data.split("\n");
2034
- const index = lines.findIndex(
2035
- (line) => line.includes("CommandLocalizationTypeData")
2036
- );
2037
- if (index === -1) {
2038
- for (const locale of this.translations.values()) {
2039
- const generated2 = generateType(locale);
2040
- await (0, import_promises2.writeFile)(file, `${header}${generated2}${footer}`);
2067
+ try {
2068
+ let commandDefinitions = /* @__PURE__ */ new Map();
2069
+ if ((0, import_node_fs.existsSync)(file)) {
2070
+ try {
2071
+ const data = await (0, import_promises2.readFile)(file, "utf-8");
2072
+ const content = data.toString();
2073
+ const regex = /"([^"]+)":\s*\{([^}]*)\}/gs;
2074
+ let match;
2075
+ while ((match = regex.exec(content)) !== null) {
2076
+ const [fullMatch, commandName] = match;
2077
+ if (commandName !== localeData.command.name) {
2078
+ commandDefinitions.set(commandName, fullMatch);
2079
+ }
2080
+ }
2081
+ } catch (err) {
2082
+ console.warn("Could not parse existing type file, creating new one");
2041
2083
  }
2042
- return;
2043
2084
  }
2044
- const start = index + 2;
2045
- const end = lines.findIndex((line) => line.includes("}"));
2046
- const generated = generateType(localeData);
2047
- lines.splice(start, end - start, generated);
2048
- await (0, import_promises2.writeFile)(file, lines.join("\n"));
2085
+ const newCommandType = generateType(localeData);
2086
+ commandDefinitions.set(localeData.command.name, newCommandType);
2087
+ let fileContent = header;
2088
+ const entries = Array.from(commandDefinitions.values());
2089
+ fileContent += entries.join(",\n");
2090
+ fileContent += "\n" + footer;
2091
+ const dir = (0, import_node_path.join)(process.cwd(), "node_modules", "commandkit-types");
2092
+ if (!(0, import_node_fs.existsSync)(dir)) {
2093
+ await (0, import_promises2.mkdir)(dir, { recursive: true });
2094
+ }
2095
+ await (0, import_promises2.writeFile)(file, fileContent);
2096
+ } catch (error) {
2097
+ console.error("Failed to generate locale types:", error);
2049
2098
  }
2050
2099
  }
2051
2100
  async getTranslationStrict(scope, locale) {
@@ -2087,18 +2136,6 @@ declare module 'commandkit' {
2087
2136
  }
2088
2137
  });
2089
2138
 
2090
- // src/utils/constants.ts
2091
- var COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST;
2092
- var init_constants = __esm({
2093
- "src/utils/constants.ts"() {
2094
- "use strict";
2095
- init_cjs_shims();
2096
- COMMANDKIT_CACHE_TAG = Symbol("kCommandKitCacheTag");
2097
- COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
2098
- COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === "true";
2099
- }
2100
- });
2101
-
2102
2139
  // src/utils/utilities.ts
2103
2140
  function findAppDirectory() {
2104
2141
  if (appDir) return appDir;
@@ -3128,13 +3165,17 @@ var init_Context = __esm({
3128
3165
  /**
3129
3166
  * Returns the i18n api for this command.
3130
3167
  * @param locale The locale to use for the i18n api.
3168
+ * @template T The command name for type-safe translations. Will provide autocomplete from available translations.
3131
3169
  */
3132
3170
  locale(locale) {
3133
3171
  const selectedLocale = locale ?? this.getLocale();
3134
- return new Localization(this.commandkit, {
3135
- locale: selectedLocale,
3136
- target: this.getCommandIdentifier()
3137
- });
3172
+ return new Localization(
3173
+ this.commandkit,
3174
+ {
3175
+ locale: selectedLocale,
3176
+ target: this.getCommandIdentifier()
3177
+ }
3178
+ );
3138
3179
  }
3139
3180
  /**
3140
3181
  * Creates a clone of this context
@@ -3348,6 +3389,78 @@ var init_AppCommandRunner = __esm({
3348
3389
  }
3349
3390
  });
3350
3391
 
3392
+ // src/utils/types-package.ts
3393
+ async function generateTypesPackage() {
3394
+ const location = (0, import_node_path3.join)(process.cwd(), "node_modules", "commandkit-types");
3395
+ if (!COMMANDKIT_IS_DEV) return location;
3396
+ const packageJSON = (0, import_node_path3.join)(location, "package.json");
3397
+ const index = (0, import_node_path3.join)(location, "index.js");
3398
+ const types = (0, import_node_path3.join)(location, "index.d.ts");
3399
+ const locale = (0, import_node_path3.join)(location, "locale_types.d.ts");
3400
+ const command = (0, import_node_path3.join)(location, "command.d.ts");
3401
+ const packageJSONContent = {
3402
+ name: "commandkit-types",
3403
+ version: "1.0.0",
3404
+ description: "CommandKit types package",
3405
+ type: "commonjs",
3406
+ main: "index.js",
3407
+ types: "index.d.ts"
3408
+ };
3409
+ const indexContent = `module.exports = {};`;
3410
+ const typesContent = `// Main types index file - imports all type declarations
3411
+ import './locale_types';
3412
+ import './command';
3413
+ export {};
3414
+ `;
3415
+ const localeTypesContent = `// Auto-generated localization types
3416
+ export {};
3417
+ declare module 'commandkit' {
3418
+ interface CommandLocalizationTypeData {
3419
+ // This interface will be populated with localizations
3420
+ }
3421
+
3422
+ type TranslatableCommandName = keyof CommandLocalizationTypeData
3423
+ }`;
3424
+ const commandTypesContent = `// Auto-generated command types
3425
+ export {};
3426
+ declare module 'commandkit' {
3427
+ type CommandTypeData = string
3428
+ }`;
3429
+ await (0, import_promises3.mkdir)(location, { recursive: true }).catch(() => {
3430
+ });
3431
+ await (0, import_promises3.writeFile)(packageJSON, JSON.stringify(packageJSONContent, null, 2));
3432
+ await (0, import_promises3.writeFile)(index, indexContent);
3433
+ await (0, import_promises3.writeFile)(types, typesContent);
3434
+ await (0, import_promises3.writeFile)(locale, localeTypesContent);
3435
+ await (0, import_promises3.writeFile)(command, commandTypesContent);
3436
+ return location;
3437
+ }
3438
+ async function rewriteCommandDeclaration(data) {
3439
+ const commandTypesContent = `// Auto-generated command types
3440
+ declare module 'commandkit' {
3441
+ ${data}
3442
+ }
3443
+ export {};
3444
+ `;
3445
+ const location = (0, import_node_path3.join)(process.cwd(), "node_modules", "commandkit-types");
3446
+ if (!(0, import_node_fs3.existsSync)(location)) return;
3447
+ const type = (0, import_node_path3.join)(location, "command.d.ts");
3448
+ await (0, import_promises3.writeFile)(type, commandTypesContent, { encoding: "utf-8" });
3449
+ }
3450
+ var import_promises3, import_node_path3, import_node_fs3;
3451
+ var init_types_package = __esm({
3452
+ "src/utils/types-package.ts"() {
3453
+ "use strict";
3454
+ init_cjs_shims();
3455
+ import_promises3 = require("fs/promises");
3456
+ import_node_path3 = require("path");
3457
+ init_constants();
3458
+ import_node_fs3 = require("fs");
3459
+ __name(generateTypesPackage, "generateTypesPackage");
3460
+ __name(rewriteCommandDeclaration, "rewriteCommandDeclaration");
3461
+ }
3462
+ });
3463
+
3351
3464
  // src/app/handlers/AppCommandHandler.ts
3352
3465
  var import_discord11, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
3353
3466
  var init_AppCommandHandler = __esm({
@@ -3361,6 +3474,8 @@ var init_AppCommandHandler = __esm({
3361
3474
  init_CommandRegistrar();
3362
3475
  init_Logger();
3363
3476
  init_AppCommandRunner();
3477
+ init_constants();
3478
+ init_types_package();
3364
3479
  commandDataSchema = {
3365
3480
  command: /* @__PURE__ */ __name((c) => c instanceof import_discord11.SlashCommandBuilder || c instanceof import_discord11.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
3366
3481
  chatInput: /* @__PURE__ */ __name((c) => typeof c === "function", "chatInput"),
@@ -3521,6 +3636,13 @@ var init_AppCommandHandler = __esm({
3521
3636
  for (const [id, command] of commands) {
3522
3637
  await this.loadCommand(id, command);
3523
3638
  }
3639
+ if (COMMANDKIT_IS_DEV) {
3640
+ await rewriteCommandDeclaration(
3641
+ `type CommandTypeData = ${Array.from(
3642
+ this.loadedCommands.mapValues((v) => JSON.stringify(v.command.name)).values()
3643
+ ).join(" | ")}`
3644
+ );
3645
+ }
3524
3646
  }
3525
3647
  async loadMiddleware(id, middleware) {
3526
3648
  try {
@@ -3709,14 +3831,14 @@ var init_AppCommandHandler = __esm({
3709
3831
  });
3710
3832
 
3711
3833
  // src/app/router/CommandsRouter.ts
3712
- var import_node_fs3, import_promises3, import_node_path3, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
3834
+ var import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
3713
3835
  var init_CommandsRouter = __esm({
3714
3836
  "src/app/router/CommandsRouter.ts"() {
3715
3837
  "use strict";
3716
3838
  init_cjs_shims();
3717
- import_node_fs3 = require("fs");
3718
- import_promises3 = require("fs/promises");
3719
- import_node_path3 = require("path");
3839
+ import_node_fs4 = require("fs");
3840
+ import_promises4 = require("fs/promises");
3841
+ import_node_path4 = require("path");
3720
3842
  MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
3721
3843
  COMMAND_PATTERN = /^(\w+)\.(m|c)?(j|t)sx?$/;
3722
3844
  CATEGORY_PATTERN = /^\(\w+\)$/;
@@ -3735,7 +3857,7 @@ var init_CommandsRouter = __esm({
3735
3857
  }
3736
3858
  }
3737
3859
  isValidPath() {
3738
- return (0, import_node_fs3.existsSync)(this.options.entrypoint);
3860
+ return (0, import_node_fs4.existsSync)(this.options.entrypoint);
3739
3861
  }
3740
3862
  isCommand(name) {
3741
3863
  return COMMAND_PATTERN.test(name);
@@ -3751,12 +3873,12 @@ var init_CommandsRouter = __esm({
3751
3873
  this.middlewares.clear();
3752
3874
  }
3753
3875
  async scan() {
3754
- const entries = await (0, import_promises3.readdir)(this.options.entrypoint, {
3876
+ const entries = await (0, import_promises4.readdir)(this.options.entrypoint, {
3755
3877
  withFileTypes: true
3756
3878
  });
3757
3879
  for (const entry of entries) {
3758
3880
  if (entry.name.startsWith("_")) continue;
3759
- const fullPath = (0, import_node_path3.join)(this.options.entrypoint, entry.name);
3881
+ const fullPath = (0, import_node_path4.join)(this.options.entrypoint, entry.name);
3760
3882
  if (entry.isDirectory()) {
3761
3883
  const category = this.isCategory(entry.name) ? entry.name.slice(1, -1) : null;
3762
3884
  await this.traverse(fullPath, category);
@@ -3780,7 +3902,7 @@ var init_CommandsRouter = __esm({
3780
3902
  };
3781
3903
  }
3782
3904
  async traverse(path2, category) {
3783
- const entries = await (0, import_promises3.readdir)(path2, {
3905
+ const entries = await (0, import_promises4.readdir)(path2, {
3784
3906
  withFileTypes: true
3785
3907
  });
3786
3908
  for (const entry of entries) {
@@ -3794,11 +3916,11 @@ var init_CommandsRouter = __esm({
3794
3916
  }
3795
3917
  async handle(entry, category = null) {
3796
3918
  const name = entry.name;
3797
- const path2 = (0, import_node_path3.join)(entry.parentPath, entry.name);
3919
+ const path2 = (0, import_node_path4.join)(entry.parentPath, entry.name);
3798
3920
  if (this.isCommand(name)) {
3799
3921
  const command = {
3800
3922
  id: crypto.randomUUID(),
3801
- name: (0, import_node_path3.basename)(path2, (0, import_node_path3.extname)(path2)),
3923
+ name: (0, import_node_path4.basename)(path2, (0, import_node_path4.extname)(path2)),
3802
3924
  path: path2,
3803
3925
  category,
3804
3926
  parentPath: entry.parentPath,
@@ -3809,7 +3931,7 @@ var init_CommandsRouter = __esm({
3809
3931
  } else if (this.isMiddleware(name)) {
3810
3932
  const middleware = {
3811
3933
  id: crypto.randomUUID(),
3812
- name: (0, import_node_path3.basename)(path2, (0, import_node_path3.extname)(path2)),
3934
+ name: (0, import_node_path4.basename)(path2, (0, import_node_path4.extname)(path2)),
3813
3935
  path: path2,
3814
3936
  relativePath: this.replaceEntrypoint(path2),
3815
3937
  parentPath: entry.parentPath
@@ -3829,7 +3951,7 @@ var init_CommandsRouter = __esm({
3829
3951
  });
3830
3952
  }
3831
3953
  replaceEntrypoint(path2) {
3832
- const normalized = (0, import_node_path3.normalize)(path2);
3954
+ const normalized = (0, import_node_path4.normalize)(path2);
3833
3955
  return normalized.replace(this.options.entrypoint, "");
3834
3956
  }
3835
3957
  };
@@ -3839,14 +3961,14 @@ var init_CommandsRouter = __esm({
3839
3961
  });
3840
3962
 
3841
3963
  // src/app/router/EventsRouter.ts
3842
- var import_node_fs4, import_promises4, import_node_path4, _EventsRouter, EventsRouter;
3964
+ var import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
3843
3965
  var init_EventsRouter = __esm({
3844
3966
  "src/app/router/EventsRouter.ts"() {
3845
3967
  "use strict";
3846
3968
  init_cjs_shims();
3847
- import_node_fs4 = require("fs");
3848
- import_promises4 = require("fs/promises");
3849
- import_node_path4 = require("path");
3969
+ import_node_fs5 = require("fs");
3970
+ import_promises5 = require("fs/promises");
3971
+ import_node_path5 = require("path");
3850
3972
  _EventsRouter = class _EventsRouter {
3851
3973
  /**
3852
3974
  * Creates a new EventsRouter instance
@@ -3880,7 +4002,7 @@ var init_EventsRouter = __esm({
3880
4002
  * Checks if the entrypoint path is valid
3881
4003
  */
3882
4004
  isValidPath() {
3883
- return (0, import_node_fs4.existsSync)(this.entrypoint);
4005
+ return (0, import_node_fs5.existsSync)(this.entrypoint);
3884
4006
  }
3885
4007
  /**
3886
4008
  * Clear all parsed events
@@ -3901,10 +4023,10 @@ var init_EventsRouter = __esm({
3901
4023
  * @returns Promise resolving to the events tree
3902
4024
  */
3903
4025
  async scan() {
3904
- const dirs = await (0, import_promises4.readdir)(this.entrypoint, { withFileTypes: true });
4026
+ const dirs = await (0, import_promises5.readdir)(this.entrypoint, { withFileTypes: true });
3905
4027
  for (const dir of dirs) {
3906
4028
  if (dir.isDirectory()) {
3907
- const path2 = (0, import_node_path4.join)(this.entrypoint, dir.name);
4029
+ const path2 = (0, import_node_path5.join)(this.entrypoint, dir.name);
3908
4030
  await this.scanEvent(dir.name, path2, null, [], true);
3909
4031
  }
3910
4032
  }
@@ -3925,18 +4047,18 @@ var init_EventsRouter = __esm({
3925
4047
  * @returns Promise resolving to the parsed event metadata
3926
4048
  */
3927
4049
  async scanEvent(event, path2, _namespace = null, listeners = [], isRoot = false) {
3928
- const files = await (0, import_promises4.readdir)(path2, { withFileTypes: true });
4050
+ const files = await (0, import_promises5.readdir)(path2, { withFileTypes: true });
3929
4051
  const isNamespace = isRoot && /^\(.+\)$/.test(event);
3930
4052
  const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
3931
4053
  for (const file of files) {
3932
4054
  if (file.name.includes("_")) continue;
3933
4055
  if (file.isDirectory()) {
3934
- const nextPath = (0, import_node_path4.join)(path2, file.name);
4056
+ const nextPath = (0, import_node_path5.join)(path2, file.name);
3935
4057
  await this.scanEvent(file.name, nextPath, namespace, listeners);
3936
4058
  continue;
3937
4059
  }
3938
4060
  if (file.isFile() && /\.(m|c)?(j|t)sx?$/.test(file.name)) {
3939
- listeners.push((0, import_node_path4.join)(file.parentPath, file.name));
4061
+ listeners.push((0, import_node_path5.join)(file.parentPath, file.name));
3940
4062
  }
3941
4063
  }
3942
4064
  if (!isNamespace) {
@@ -4111,54 +4233,6 @@ var init_AppEventsHandler = __esm({
4111
4233
  }
4112
4234
  });
4113
4235
 
4114
- // src/utils/types-package.ts
4115
- async function generateTypesPackage() {
4116
- const location = (0, import_node_path5.join)(process.cwd(), "node_modules", "commandkit-types");
4117
- const packageJSON = (0, import_node_path5.join)(location, "package.json");
4118
- const index = (0, import_node_path5.join)(location, "index.js");
4119
- const types = (0, import_node_path5.join)(location, "index.d.ts");
4120
- const locale = (0, import_node_path5.join)(location, "locale.d.ts");
4121
- const command = (0, import_node_path5.join)(location, "command.d.ts");
4122
- const exists = (0, import_node_fs5.existsSync)(packageJSON);
4123
- if (exists) return location;
4124
- const packageJSONContent = {
4125
- name: "commandkit-types",
4126
- version: "1.0.0",
4127
- description: "CommandKit types package",
4128
- type: "commonjs",
4129
- main: "index.js",
4130
- types: "index.d.ts"
4131
- };
4132
- const indexContent = `module.exports = {};`;
4133
- const typesContent = `import { CommandLocalizationTypeData } from './locale.d.ts';
4134
- import { CommandTypeData } from './command.d.ts';
4135
-
4136
- declare module 'commandkit' {
4137
- export interface CommandKitTypeReferences {
4138
- locale: CommandLocalizationTypeData;
4139
- command: CommandTypeData;
4140
- }
4141
- }`;
4142
- await (0, import_promises5.mkdir)(location, { recursive: true });
4143
- await (0, import_promises5.writeFile)(packageJSON, JSON.stringify(packageJSONContent, null, 2));
4144
- await (0, import_promises5.writeFile)(index, indexContent);
4145
- await (0, import_promises5.writeFile)(types, typesContent);
4146
- await (0, import_promises5.writeFile)(locale, "");
4147
- await (0, import_promises5.writeFile)(command, "");
4148
- return location;
4149
- }
4150
- var import_node_fs5, import_promises5, import_node_path5;
4151
- var init_types_package = __esm({
4152
- "src/utils/types-package.ts"() {
4153
- "use strict";
4154
- init_cjs_shims();
4155
- import_node_fs5 = require("fs");
4156
- import_promises5 = require("fs/promises");
4157
- import_node_path5 = require("path");
4158
- __name(generateTypesPackage, "generateTypesPackage");
4159
- }
4160
- });
4161
-
4162
4236
  // src/cli/common.ts
4163
4237
  function write(message) {
4164
4238
  process.stdout.write(message);
@@ -4664,7 +4738,7 @@ var init_version = __esm({
4664
4738
  "use strict";
4665
4739
  init_cjs_shims();
4666
4740
  version = /* @__MACRO__ $version */
4667
- "0.1.11-dev.20250327153237";
4741
+ "0.1.11-dev.20250328083250";
4668
4742
  }
4669
4743
  });
4670
4744
 
@@ -4757,6 +4831,8 @@ async function buildApplication({
4757
4831
  esbuildPluginList.push(...esbuildPlugins.map(fromEsbuildPlugin));
4758
4832
  }
4759
4833
  try {
4834
+ const dest = isDev ? ".commandkit" : config.distDir;
4835
+ await (0, import_rimraf2.rimraf)(dest);
4760
4836
  await (0, import_tsup.build)({
4761
4837
  esbuildPlugins: esbuildPluginList,
4762
4838
  watch: false,
@@ -4780,7 +4856,7 @@ async function buildApplication({
4780
4856
  name: "CommandKit",
4781
4857
  sourcemap: true,
4782
4858
  target: "node16",
4783
- outDir: isDev ? ".commandkit" : config.distDir,
4859
+ outDir: dest,
4784
4860
  entry: [
4785
4861
  "src",
4786
4862
  `!${config.distDir}`,
@@ -4825,7 +4901,7 @@ await main();
4825
4901
  const dist = isDev ? ".commandkit" : distDir || "dist";
4826
4902
  await (0, import_promises6.writeFile)((0, import_node_path10.join)(configPath, dist, "index.js"), code);
4827
4903
  }
4828
- var import_tsup, import_promises6, import_node_path10, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
4904
+ var import_tsup, import_promises6, import_node_path10, import_rimraf2, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
4829
4905
  var init_build = __esm({
4830
4906
  "src/cli/build.ts"() {
4831
4907
  "use strict";
@@ -4836,6 +4912,7 @@ var init_build = __esm({
4836
4912
  import_promises6 = require("fs/promises");
4837
4913
  import_node_path10 = require("path");
4838
4914
  init_env();
4915
+ import_rimraf2 = require("rimraf");
4839
4916
  __name(buildApplication, "buildApplication");
4840
4917
  envScript = /* @__PURE__ */ __name((dev) => `// --- Environment Variables Loader ---
4841
4918
  const $env = [${(dev ? devEnvFileArgs : prodEnvFileArgs).map((p) => `"${p}"`).join(", ")}];
@@ -5303,6 +5380,9 @@ init_plugins();
5303
5380
 
5304
5381
  // src/cli/init.ts
5305
5382
  init_cjs_shims();
5383
+ var import_node_fs10 = require("fs");
5384
+ var import_promises8 = require("fs/promises");
5385
+ var import_node_path11 = require("path");
5306
5386
  async function bootstrapCommandkitCLI(argv, options) {
5307
5387
  process.title = "CommandKit CLI";
5308
5388
  const { Command } = await import("commander");
@@ -5350,6 +5430,11 @@ async function bootstrapCommandkitCLI(argv, options) {
5350
5430
  }
5351
5431
  });
5352
5432
  await program.parseAsync(argv, options);
5433
+ const types = (0, import_node_path11.join)(process.cwd(), "node_modules", "commandkit-types");
5434
+ if (!(0, import_node_fs10.existsSync)(types)) {
5435
+ await (0, import_promises8.mkdir)(types, { recursive: true }).catch(() => {
5436
+ });
5437
+ }
5353
5438
  }
5354
5439
  __name(bootstrapCommandkitCLI, "bootstrapCommandkitCLI");
5355
5440