commandkit 0.1.11-dev.20250327153237 → 0.1.11-dev.20250328085113
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 +16 -9
- package/dist/index.js +213 -127
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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:
|
|
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 = (
|
|
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:
|
|
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;
|
|
@@ -1663,7 +1670,7 @@ interface CommandKitConfiguration {
|
|
|
1663
1670
|
localizationStrategy: LocalizationStrategy;
|
|
1664
1671
|
getMessageCommandPrefix: (message: Message$1) => Awaitable<string | string[]>;
|
|
1665
1672
|
}
|
|
1666
|
-
declare let commandkit:
|
|
1673
|
+
declare let commandkit: CommandKit;
|
|
1667
1674
|
declare class CommandKit extends EventEmitter {
|
|
1668
1675
|
#private;
|
|
1669
1676
|
private options;
|
|
@@ -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
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
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
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
return
|
|
2023
|
-
}
|
|
2024
|
-
|
|
2025
|
-
|
|
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
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
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
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
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(
|
|
3135
|
-
|
|
3136
|
-
|
|
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
|
|
@@ -3267,7 +3308,8 @@ var init_AppCommandRunner = __esm({
|
|
|
3267
3308
|
setCommandRunner: /* @__PURE__ */ __name((fn2) => {
|
|
3268
3309
|
runCommand = fn2;
|
|
3269
3310
|
}, "setCommandRunner")
|
|
3270
|
-
}
|
|
3311
|
+
},
|
|
3312
|
+
messageCommandParser: prepared.messageCommandParser
|
|
3271
3313
|
});
|
|
3272
3314
|
for (const middleware of prepared.middlewares) {
|
|
3273
3315
|
await middleware.data.beforeExecute(ctx);
|
|
@@ -3348,6 +3390,78 @@ var init_AppCommandRunner = __esm({
|
|
|
3348
3390
|
}
|
|
3349
3391
|
});
|
|
3350
3392
|
|
|
3393
|
+
// src/utils/types-package.ts
|
|
3394
|
+
async function generateTypesPackage() {
|
|
3395
|
+
const location = (0, import_node_path3.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
3396
|
+
if (!COMMANDKIT_IS_DEV) return location;
|
|
3397
|
+
const packageJSON = (0, import_node_path3.join)(location, "package.json");
|
|
3398
|
+
const index = (0, import_node_path3.join)(location, "index.js");
|
|
3399
|
+
const types = (0, import_node_path3.join)(location, "index.d.ts");
|
|
3400
|
+
const locale = (0, import_node_path3.join)(location, "locale_types.d.ts");
|
|
3401
|
+
const command = (0, import_node_path3.join)(location, "command.d.ts");
|
|
3402
|
+
const packageJSONContent = {
|
|
3403
|
+
name: "commandkit-types",
|
|
3404
|
+
version: "1.0.0",
|
|
3405
|
+
description: "CommandKit types package",
|
|
3406
|
+
type: "commonjs",
|
|
3407
|
+
main: "index.js",
|
|
3408
|
+
types: "index.d.ts"
|
|
3409
|
+
};
|
|
3410
|
+
const indexContent = `module.exports = {};`;
|
|
3411
|
+
const typesContent = `// Main types index file - imports all type declarations
|
|
3412
|
+
import './locale_types';
|
|
3413
|
+
import './command';
|
|
3414
|
+
export {};
|
|
3415
|
+
`;
|
|
3416
|
+
const localeTypesContent = `// Auto-generated localization types
|
|
3417
|
+
export {};
|
|
3418
|
+
declare module 'commandkit' {
|
|
3419
|
+
interface CommandLocalizationTypeData {
|
|
3420
|
+
// This interface will be populated with localizations
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
type TranslatableCommandName = keyof CommandLocalizationTypeData
|
|
3424
|
+
}`;
|
|
3425
|
+
const commandTypesContent = `// Auto-generated command types
|
|
3426
|
+
export {};
|
|
3427
|
+
declare module 'commandkit' {
|
|
3428
|
+
type CommandTypeData = string
|
|
3429
|
+
}`;
|
|
3430
|
+
await (0, import_promises3.mkdir)(location, { recursive: true }).catch(() => {
|
|
3431
|
+
});
|
|
3432
|
+
await (0, import_promises3.writeFile)(packageJSON, JSON.stringify(packageJSONContent, null, 2));
|
|
3433
|
+
await (0, import_promises3.writeFile)(index, indexContent);
|
|
3434
|
+
await (0, import_promises3.writeFile)(types, typesContent);
|
|
3435
|
+
await (0, import_promises3.writeFile)(locale, localeTypesContent);
|
|
3436
|
+
await (0, import_promises3.writeFile)(command, commandTypesContent);
|
|
3437
|
+
return location;
|
|
3438
|
+
}
|
|
3439
|
+
async function rewriteCommandDeclaration(data) {
|
|
3440
|
+
const commandTypesContent = `// Auto-generated command types
|
|
3441
|
+
declare module 'commandkit' {
|
|
3442
|
+
${data}
|
|
3443
|
+
}
|
|
3444
|
+
export {};
|
|
3445
|
+
`;
|
|
3446
|
+
const location = (0, import_node_path3.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
3447
|
+
if (!(0, import_node_fs3.existsSync)(location)) return;
|
|
3448
|
+
const type = (0, import_node_path3.join)(location, "command.d.ts");
|
|
3449
|
+
await (0, import_promises3.writeFile)(type, commandTypesContent, { encoding: "utf-8" });
|
|
3450
|
+
}
|
|
3451
|
+
var import_promises3, import_node_path3, import_node_fs3;
|
|
3452
|
+
var init_types_package = __esm({
|
|
3453
|
+
"src/utils/types-package.ts"() {
|
|
3454
|
+
"use strict";
|
|
3455
|
+
init_cjs_shims();
|
|
3456
|
+
import_promises3 = require("fs/promises");
|
|
3457
|
+
import_node_path3 = require("path");
|
|
3458
|
+
init_constants();
|
|
3459
|
+
import_node_fs3 = require("fs");
|
|
3460
|
+
__name(generateTypesPackage, "generateTypesPackage");
|
|
3461
|
+
__name(rewriteCommandDeclaration, "rewriteCommandDeclaration");
|
|
3462
|
+
}
|
|
3463
|
+
});
|
|
3464
|
+
|
|
3351
3465
|
// src/app/handlers/AppCommandHandler.ts
|
|
3352
3466
|
var import_discord11, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
|
|
3353
3467
|
var init_AppCommandHandler = __esm({
|
|
@@ -3361,6 +3475,8 @@ var init_AppCommandHandler = __esm({
|
|
|
3361
3475
|
init_CommandRegistrar();
|
|
3362
3476
|
init_Logger();
|
|
3363
3477
|
init_AppCommandRunner();
|
|
3478
|
+
init_constants();
|
|
3479
|
+
init_types_package();
|
|
3364
3480
|
commandDataSchema = {
|
|
3365
3481
|
command: /* @__PURE__ */ __name((c) => c instanceof import_discord11.SlashCommandBuilder || c instanceof import_discord11.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
|
|
3366
3482
|
chatInput: /* @__PURE__ */ __name((c) => typeof c === "function", "chatInput"),
|
|
@@ -3521,6 +3637,13 @@ var init_AppCommandHandler = __esm({
|
|
|
3521
3637
|
for (const [id, command] of commands) {
|
|
3522
3638
|
await this.loadCommand(id, command);
|
|
3523
3639
|
}
|
|
3640
|
+
if (COMMANDKIT_IS_DEV) {
|
|
3641
|
+
await rewriteCommandDeclaration(
|
|
3642
|
+
`type CommandTypeData = ${Array.from(
|
|
3643
|
+
this.loadedCommands.mapValues((v) => JSON.stringify(v.command.name)).values()
|
|
3644
|
+
).join(" | ")}`
|
|
3645
|
+
);
|
|
3646
|
+
}
|
|
3524
3647
|
}
|
|
3525
3648
|
async loadMiddleware(id, middleware) {
|
|
3526
3649
|
try {
|
|
@@ -3709,14 +3832,14 @@ var init_AppCommandHandler = __esm({
|
|
|
3709
3832
|
});
|
|
3710
3833
|
|
|
3711
3834
|
// src/app/router/CommandsRouter.ts
|
|
3712
|
-
var
|
|
3835
|
+
var import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
3713
3836
|
var init_CommandsRouter = __esm({
|
|
3714
3837
|
"src/app/router/CommandsRouter.ts"() {
|
|
3715
3838
|
"use strict";
|
|
3716
3839
|
init_cjs_shims();
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3840
|
+
import_node_fs4 = require("fs");
|
|
3841
|
+
import_promises4 = require("fs/promises");
|
|
3842
|
+
import_node_path4 = require("path");
|
|
3720
3843
|
MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
3721
3844
|
COMMAND_PATTERN = /^(\w+)\.(m|c)?(j|t)sx?$/;
|
|
3722
3845
|
CATEGORY_PATTERN = /^\(\w+\)$/;
|
|
@@ -3735,7 +3858,7 @@ var init_CommandsRouter = __esm({
|
|
|
3735
3858
|
}
|
|
3736
3859
|
}
|
|
3737
3860
|
isValidPath() {
|
|
3738
|
-
return (0,
|
|
3861
|
+
return (0, import_node_fs4.existsSync)(this.options.entrypoint);
|
|
3739
3862
|
}
|
|
3740
3863
|
isCommand(name) {
|
|
3741
3864
|
return COMMAND_PATTERN.test(name);
|
|
@@ -3751,12 +3874,12 @@ var init_CommandsRouter = __esm({
|
|
|
3751
3874
|
this.middlewares.clear();
|
|
3752
3875
|
}
|
|
3753
3876
|
async scan() {
|
|
3754
|
-
const entries = await (0,
|
|
3877
|
+
const entries = await (0, import_promises4.readdir)(this.options.entrypoint, {
|
|
3755
3878
|
withFileTypes: true
|
|
3756
3879
|
});
|
|
3757
3880
|
for (const entry of entries) {
|
|
3758
3881
|
if (entry.name.startsWith("_")) continue;
|
|
3759
|
-
const fullPath = (0,
|
|
3882
|
+
const fullPath = (0, import_node_path4.join)(this.options.entrypoint, entry.name);
|
|
3760
3883
|
if (entry.isDirectory()) {
|
|
3761
3884
|
const category = this.isCategory(entry.name) ? entry.name.slice(1, -1) : null;
|
|
3762
3885
|
await this.traverse(fullPath, category);
|
|
@@ -3780,7 +3903,7 @@ var init_CommandsRouter = __esm({
|
|
|
3780
3903
|
};
|
|
3781
3904
|
}
|
|
3782
3905
|
async traverse(path2, category) {
|
|
3783
|
-
const entries = await (0,
|
|
3906
|
+
const entries = await (0, import_promises4.readdir)(path2, {
|
|
3784
3907
|
withFileTypes: true
|
|
3785
3908
|
});
|
|
3786
3909
|
for (const entry of entries) {
|
|
@@ -3794,11 +3917,11 @@ var init_CommandsRouter = __esm({
|
|
|
3794
3917
|
}
|
|
3795
3918
|
async handle(entry, category = null) {
|
|
3796
3919
|
const name = entry.name;
|
|
3797
|
-
const path2 = (0,
|
|
3920
|
+
const path2 = (0, import_node_path4.join)(entry.parentPath, entry.name);
|
|
3798
3921
|
if (this.isCommand(name)) {
|
|
3799
3922
|
const command = {
|
|
3800
3923
|
id: crypto.randomUUID(),
|
|
3801
|
-
name: (0,
|
|
3924
|
+
name: (0, import_node_path4.basename)(path2, (0, import_node_path4.extname)(path2)),
|
|
3802
3925
|
path: path2,
|
|
3803
3926
|
category,
|
|
3804
3927
|
parentPath: entry.parentPath,
|
|
@@ -3809,7 +3932,7 @@ var init_CommandsRouter = __esm({
|
|
|
3809
3932
|
} else if (this.isMiddleware(name)) {
|
|
3810
3933
|
const middleware = {
|
|
3811
3934
|
id: crypto.randomUUID(),
|
|
3812
|
-
name: (0,
|
|
3935
|
+
name: (0, import_node_path4.basename)(path2, (0, import_node_path4.extname)(path2)),
|
|
3813
3936
|
path: path2,
|
|
3814
3937
|
relativePath: this.replaceEntrypoint(path2),
|
|
3815
3938
|
parentPath: entry.parentPath
|
|
@@ -3829,7 +3952,7 @@ var init_CommandsRouter = __esm({
|
|
|
3829
3952
|
});
|
|
3830
3953
|
}
|
|
3831
3954
|
replaceEntrypoint(path2) {
|
|
3832
|
-
const normalized = (0,
|
|
3955
|
+
const normalized = (0, import_node_path4.normalize)(path2);
|
|
3833
3956
|
return normalized.replace(this.options.entrypoint, "");
|
|
3834
3957
|
}
|
|
3835
3958
|
};
|
|
@@ -3839,14 +3962,14 @@ var init_CommandsRouter = __esm({
|
|
|
3839
3962
|
});
|
|
3840
3963
|
|
|
3841
3964
|
// src/app/router/EventsRouter.ts
|
|
3842
|
-
var
|
|
3965
|
+
var import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
|
|
3843
3966
|
var init_EventsRouter = __esm({
|
|
3844
3967
|
"src/app/router/EventsRouter.ts"() {
|
|
3845
3968
|
"use strict";
|
|
3846
3969
|
init_cjs_shims();
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3970
|
+
import_node_fs5 = require("fs");
|
|
3971
|
+
import_promises5 = require("fs/promises");
|
|
3972
|
+
import_node_path5 = require("path");
|
|
3850
3973
|
_EventsRouter = class _EventsRouter {
|
|
3851
3974
|
/**
|
|
3852
3975
|
* Creates a new EventsRouter instance
|
|
@@ -3880,7 +4003,7 @@ var init_EventsRouter = __esm({
|
|
|
3880
4003
|
* Checks if the entrypoint path is valid
|
|
3881
4004
|
*/
|
|
3882
4005
|
isValidPath() {
|
|
3883
|
-
return (0,
|
|
4006
|
+
return (0, import_node_fs5.existsSync)(this.entrypoint);
|
|
3884
4007
|
}
|
|
3885
4008
|
/**
|
|
3886
4009
|
* Clear all parsed events
|
|
@@ -3901,10 +4024,10 @@ var init_EventsRouter = __esm({
|
|
|
3901
4024
|
* @returns Promise resolving to the events tree
|
|
3902
4025
|
*/
|
|
3903
4026
|
async scan() {
|
|
3904
|
-
const dirs = await (0,
|
|
4027
|
+
const dirs = await (0, import_promises5.readdir)(this.entrypoint, { withFileTypes: true });
|
|
3905
4028
|
for (const dir of dirs) {
|
|
3906
4029
|
if (dir.isDirectory()) {
|
|
3907
|
-
const path2 = (0,
|
|
4030
|
+
const path2 = (0, import_node_path5.join)(this.entrypoint, dir.name);
|
|
3908
4031
|
await this.scanEvent(dir.name, path2, null, [], true);
|
|
3909
4032
|
}
|
|
3910
4033
|
}
|
|
@@ -3925,18 +4048,18 @@ var init_EventsRouter = __esm({
|
|
|
3925
4048
|
* @returns Promise resolving to the parsed event metadata
|
|
3926
4049
|
*/
|
|
3927
4050
|
async scanEvent(event, path2, _namespace = null, listeners = [], isRoot = false) {
|
|
3928
|
-
const files = await (0,
|
|
4051
|
+
const files = await (0, import_promises5.readdir)(path2, { withFileTypes: true });
|
|
3929
4052
|
const isNamespace = isRoot && /^\(.+\)$/.test(event);
|
|
3930
4053
|
const namespace = isNamespace ? event.slice(1, -1) : _namespace ?? null;
|
|
3931
4054
|
for (const file of files) {
|
|
3932
4055
|
if (file.name.includes("_")) continue;
|
|
3933
4056
|
if (file.isDirectory()) {
|
|
3934
|
-
const nextPath = (0,
|
|
4057
|
+
const nextPath = (0, import_node_path5.join)(path2, file.name);
|
|
3935
4058
|
await this.scanEvent(file.name, nextPath, namespace, listeners);
|
|
3936
4059
|
continue;
|
|
3937
4060
|
}
|
|
3938
4061
|
if (file.isFile() && /\.(m|c)?(j|t)sx?$/.test(file.name)) {
|
|
3939
|
-
listeners.push((0,
|
|
4062
|
+
listeners.push((0, import_node_path5.join)(file.parentPath, file.name));
|
|
3940
4063
|
}
|
|
3941
4064
|
}
|
|
3942
4065
|
if (!isNamespace) {
|
|
@@ -4111,54 +4234,6 @@ var init_AppEventsHandler = __esm({
|
|
|
4111
4234
|
}
|
|
4112
4235
|
});
|
|
4113
4236
|
|
|
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
4237
|
// src/cli/common.ts
|
|
4163
4238
|
function write(message) {
|
|
4164
4239
|
process.stdout.write(message);
|
|
@@ -4664,7 +4739,7 @@ var init_version = __esm({
|
|
|
4664
4739
|
"use strict";
|
|
4665
4740
|
init_cjs_shims();
|
|
4666
4741
|
version = /* @__MACRO__ $version */
|
|
4667
|
-
"0.1.11-dev.
|
|
4742
|
+
"0.1.11-dev.20250328085113";
|
|
4668
4743
|
}
|
|
4669
4744
|
});
|
|
4670
4745
|
|
|
@@ -4757,6 +4832,8 @@ async function buildApplication({
|
|
|
4757
4832
|
esbuildPluginList.push(...esbuildPlugins.map(fromEsbuildPlugin));
|
|
4758
4833
|
}
|
|
4759
4834
|
try {
|
|
4835
|
+
const dest = isDev ? ".commandkit" : config.distDir;
|
|
4836
|
+
await (0, import_rimraf2.rimraf)(dest);
|
|
4760
4837
|
await (0, import_tsup.build)({
|
|
4761
4838
|
esbuildPlugins: esbuildPluginList,
|
|
4762
4839
|
watch: false,
|
|
@@ -4780,7 +4857,7 @@ async function buildApplication({
|
|
|
4780
4857
|
name: "CommandKit",
|
|
4781
4858
|
sourcemap: true,
|
|
4782
4859
|
target: "node16",
|
|
4783
|
-
outDir:
|
|
4860
|
+
outDir: dest,
|
|
4784
4861
|
entry: [
|
|
4785
4862
|
"src",
|
|
4786
4863
|
`!${config.distDir}`,
|
|
@@ -4825,7 +4902,7 @@ await main();
|
|
|
4825
4902
|
const dist = isDev ? ".commandkit" : distDir || "dist";
|
|
4826
4903
|
await (0, import_promises6.writeFile)((0, import_node_path10.join)(configPath, dist, "index.js"), code);
|
|
4827
4904
|
}
|
|
4828
|
-
var import_tsup, import_promises6, import_node_path10, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
|
|
4905
|
+
var import_tsup, import_promises6, import_node_path10, import_rimraf2, envScript, requireScript, antiCrashScript, wrapInAsyncIIFE;
|
|
4829
4906
|
var init_build = __esm({
|
|
4830
4907
|
"src/cli/build.ts"() {
|
|
4831
4908
|
"use strict";
|
|
@@ -4836,6 +4913,7 @@ var init_build = __esm({
|
|
|
4836
4913
|
import_promises6 = require("fs/promises");
|
|
4837
4914
|
import_node_path10 = require("path");
|
|
4838
4915
|
init_env();
|
|
4916
|
+
import_rimraf2 = require("rimraf");
|
|
4839
4917
|
__name(buildApplication, "buildApplication");
|
|
4840
4918
|
envScript = /* @__PURE__ */ __name((dev) => `// --- Environment Variables Loader ---
|
|
4841
4919
|
const $env = [${(dev ? devEnvFileArgs : prodEnvFileArgs).map((p) => `"${p}"`).join(", ")}];
|
|
@@ -5303,6 +5381,9 @@ init_plugins();
|
|
|
5303
5381
|
|
|
5304
5382
|
// src/cli/init.ts
|
|
5305
5383
|
init_cjs_shims();
|
|
5384
|
+
var import_node_fs10 = require("fs");
|
|
5385
|
+
var import_promises8 = require("fs/promises");
|
|
5386
|
+
var import_node_path11 = require("path");
|
|
5306
5387
|
async function bootstrapCommandkitCLI(argv, options) {
|
|
5307
5388
|
process.title = "CommandKit CLI";
|
|
5308
5389
|
const { Command } = await import("commander");
|
|
@@ -5350,6 +5431,11 @@ async function bootstrapCommandkitCLI(argv, options) {
|
|
|
5350
5431
|
}
|
|
5351
5432
|
});
|
|
5352
5433
|
await program.parseAsync(argv, options);
|
|
5434
|
+
const types = (0, import_node_path11.join)(process.cwd(), "node_modules", "commandkit-types");
|
|
5435
|
+
if (!(0, import_node_fs10.existsSync)(types)) {
|
|
5436
|
+
await (0, import_promises8.mkdir)(types, { recursive: true }).catch(() => {
|
|
5437
|
+
});
|
|
5438
|
+
}
|
|
5353
5439
|
}
|
|
5354
5440
|
__name(bootstrapCommandkitCLI, "bootstrapCommandkitCLI");
|
|
5355
5441
|
|