Skip to content

Commit 2ab6c8d

Browse files
committed
feat: improve cli and more
1 parent 39b5d6f commit 2ab6c8d

File tree

30 files changed

+593
-105
lines changed

30 files changed

+593
-105
lines changed

apps/test-bot/commandkit.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { defineConfig } from 'commandkit';
22
import { legacy } from '@commandkit/legacy';
33

44
export default defineConfig({
5-
plugins: [legacy()],
5+
plugins: [legacy({ skipBuiltInValidations: true })],
66
typedLocales: true,
77
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"command": {
3+
"name": "legacy",
4+
"description": "Pong!"
5+
},
6+
"translations": {
7+
"greet": "Hello there from legacy command, {user}!"
8+
}
9+
}

apps/test-bot/src/commands/legacy.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { CommandData, SlashCommandProps } from '@commandkit/legacy';
2+
import { locale } from '@commandkit/legacy';
3+
4+
export const data: CommandData = {
5+
name: 'legacy',
6+
description: 'Pong!',
7+
};
8+
9+
export async function run({ interaction }: SlashCommandProps) {
10+
const { t } = await locale<'legacy'>();
11+
12+
const message = await t('greet', { user: interaction.user.username });
13+
14+
await interaction.reply(message);
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Logger } from 'commandkit';
2+
3+
export default function onReady() {
4+
Logger.log('Ready from legacy event handler');
5+
}

packages/commandkit/src/CommandKit.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export let commandkit: CommandKit;
3434

3535
export class CommandKit extends EventEmitter {
3636
#started = false;
37-
public readonly eventInterceptor: EventInterceptor;
37+
public eventInterceptor!: EventInterceptor;
3838

3939
public static readonly createElement = createElement;
4040
public static readonly Fragment = Fragment;
@@ -60,7 +60,7 @@ export class CommandKit extends EventEmitter {
6060
* @param options - The default CommandKit configuration.
6161
* @see {@link https://commandkit.js.org/docs/guide/commandkit-setup}
6262
*/
63-
constructor(private options: CommandKitOptions) {
63+
constructor(private readonly options: CommandKitOptions) {
6464
if (CommandKit.instance) {
6565
process.emitWarning(
6666
'CommandKit instance already exists. Having multiple instance in same project is discouraged and it may lead to unexpected behavior.',
@@ -86,7 +86,6 @@ export class CommandKit extends EventEmitter {
8686
options.cacheProvider = new MemoryCache();
8787
}
8888

89-
this.eventInterceptor = new EventInterceptor(options.client);
9089
this.plugins = new CommandKitPluginRuntime(this);
9190

9291
if (!CommandKit.instance) {
@@ -104,6 +103,14 @@ export class CommandKit extends EventEmitter {
104103
async start(token?: string | false) {
105104
if (this.#started) return;
106105

106+
if (!this.options.client) {
107+
throw new Error(
108+
colors.red('"client" is required when starting CommandKit.'),
109+
);
110+
}
111+
112+
this.eventInterceptor = new EventInterceptor(this.client);
113+
107114
if (COMMANDKIT_IS_DEV) {
108115
try {
109116
registerDevHooks(this);

packages/commandkit/src/app/commands/Context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ export class Context<
156156
this.client = commandkit.client;
157157
this.#store = config.store ?? new Map();
158158
this.command = config.command;
159+
160+
if (this.config.environment) {
161+
this.config.environment.setContext(this);
162+
}
159163
}
160164

161165
/**

packages/commandkit/src/app/i18n/DefaultLocalizationStrategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class DefaultLocalizationStrategy implements LocalizationStrategy {
7373
);
7474

7575
const header = `// auto generated file do not edit\nexport {};\ndeclare module 'commandkit' {\n export interface CommandLocalizationTypeData {\n`;
76-
const footer = ` type TranslatableCommandName = keyof CommandLocalizationTypeData\n}\n}`;
76+
const footer = ` }\ntype TranslatableCommandName = keyof CommandLocalizationTypeData\n}`;
7777

7878
const generateType = (locale: Translation) => {
7979
// Create type definition for this command's translations

0 commit comments

Comments
 (0)