Skip to content

Commit 6b48a30

Browse files
committed
feat: individual exports
1 parent b5e16b0 commit 6b48a30

File tree

17 files changed

+159
-13
lines changed

17 files changed

+159
-13
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { Logger } from 'commandkit';
12
import { Client } from 'discord.js';
23

34
export default function ReadyEvent(client: Client<true>) {
4-
console.log(`Successfully logged in as ${client.user?.tag}`);
5+
Logger.log(`Successfully logged in as ${client.user?.tag}`);
56
}

packages/commandkit/components.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist/components/index.js');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/components/index';

packages/commandkit/config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { defineConfig } = require('./dist/config/config.js');
2+
3+
module.exports = {
4+
defineConfig,
5+
};

packages/commandkit/config.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { defineConfig, CommandKitConfiguration as Config } from './dist/index';

packages/commandkit/hooks.cjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { useEnvironment, getContext, getCommandKit } = require('./dist/context/async-context.js');
2+
const { getEventWorkerContext } = require('./dist/app/events/EventWorkerContext.js');
3+
4+
function useAnyEnvironment() {
5+
const commandCtx = getContext();
6+
if (commandCtx) return commandCtx;
7+
8+
const eventWorkerCtx = getEventWorkerContext();
9+
if (eventWorkerCtx) return eventWorkerCtx;
10+
11+
throw new Error('No environment found. This hook must be used within a CommandKit environment.');
12+
}
13+
14+
function useClient() {
15+
const { client } = useAnyEnvironment().commandkit;
16+
return client;
17+
}
18+
19+
function useCommandKit() {
20+
try {
21+
const { commandkit } = useAnyEnvironment();
22+
return commandkit;
23+
} catch {
24+
return getCommandKit(true);
25+
}
26+
}
27+
28+
function useCommand() {
29+
return useEnvironment().context.command;
30+
}
31+
32+
function useEvent() {
33+
const eventCtx = getEventWorkerContext();
34+
35+
if (!eventCtx) {
36+
throw new Error('No event context found. This hook must be used within an event worker environment.');
37+
}
38+
39+
return eventCtx.data;
40+
}
41+
42+
module.exports = {
43+
useAnyEnvironment,
44+
useClient,
45+
useCommandKit,
46+
useCommand,
47+
useEvent,
48+
};

packages/commandkit/hooks.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type {
2+
LoadedCommand,
3+
CommandKit,
4+
ParsedEvent,
5+
CommandKitEnvironment,
6+
EventWorkerContext,
7+
} from './dist/index.js';
8+
import type { Client } from 'discord.js';
9+
10+
export function useAnyEnvironment(): CommandKitEnvironment | EventWorkerContext;
11+
12+
export function useClient<Ready extends boolean = boolean>(): Client<Ready>;
13+
14+
export function useCommandKit(): CommandKit;
15+
16+
export function useCommand(): LoadedCommand;
17+
18+
export function useEvent(): ParsedEvent;

packages/commandkit/jsx-runtime.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { jsx, jsxs, Fragment } = require('./dist/index.js');
1+
const { jsx, jsxs, Fragment } = require('./dist/components/common/element.js');
22

33
module.exports = {
44
jsx,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { jsx, jsxs, Fragment } from './dist/index';
1+
export { jsx, jsxs, Fragment } from './dist/components/common/element';

packages/commandkit/jsx-runtime.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)