Skip to content

Commit db0e081

Browse files
committed
feat: devtools apis
1 parent e8a9acf commit db0e081

39 files changed

Lines changed: 1059 additions & 483 deletions

apps/test-bot/commandkit.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { defineConfig } from 'commandkit';
22
import { legacy } from '@commandkit/legacy';
33
import { i18n } from '@commandkit/i18n';
4+
import { devtools } from '@commandkit/devtools';
45

56
export default defineConfig({
6-
plugins: [i18n(), legacy({ skipBuiltInValidations: true })],
7+
plugins: [i18n(), legacy({ skipBuiltInValidations: true }), devtools()],
78
});

apps/test-bot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
"devDependencies": {
2121
"tsx": "^4.7.0"
2222
}
23-
}
23+
}

apps/test-bot/src/app/commands/random.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ChatInputCommandContext, CommandData, cacheTag, cacheLife } from 'commandkit';
1+
import {
2+
ChatInputCommandContext,
3+
CommandData,
4+
cacheTag,
5+
cacheLife,
6+
} from 'commandkit';
27

38
export const command: CommandData = {
49
name: 'random',
@@ -7,12 +12,12 @@ export const command: CommandData = {
712

813
const random = async () => {
914
'use cache';
10-
15+
1116
cacheTag('random');
1217
cacheLife('1m');
13-
18+
1419
return Math.random();
15-
}
20+
};
1621

1722
export async function chatInput({ interaction }: ChatInputCommandContext) {
1823
await interaction.deferReply();

apps/website/docs/guide/99-helper-functions/01-after.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ It is guaranteed to be called after the command has been executed, regardless of
99
## Usage
1010

1111
```ts
12-
import { after, ChatInputCommand } from "commandkit";
12+
import { after, ChatInputCommand } from 'commandkit';
1313

1414
export const chatInput: ChatInputCommand = async (ctx) => {
15-
after(() => {
16-
// This code will be executed after the command has been executed
17-
console.log("Command has been executed");
18-
});
15+
after(() => {
16+
// This code will be executed after the command has been executed
17+
console.log('Command has been executed');
18+
});
1919

20-
await ctx.interaction.reply({
21-
content: "Hello World",
22-
ephemeral: true
23-
});
24-
}
25-
```
20+
await ctx.interaction.reply({
21+
content: 'Hello World',
22+
ephemeral: true,
23+
});
24+
};
25+
```

apps/website/docs/guide/99-helper-functions/02-stopEvents.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ It is typically used in the context of event handlers to control the flow of exe
99
## Usage
1010

1111
```ts title="./src/app/events/messageCreate/event.ts"
12-
import { stopEvents } from "commandkit";
13-
import { Message } from "discord.js";
12+
import { stopEvents } from 'commandkit';
13+
import { Message } from 'discord.js';
1414

1515
export default async function onMessageCreate(message: Message) {
16-
console.log("Message received:", message.content);
16+
console.log('Message received:', message.content);
1717

18-
// Stop further event handlers of messageCreate from being executed after this point
19-
stopEvents();
20-
// code below will not be executed
18+
// Stop further event handlers of messageCreate from being executed after this point
19+
stopEvents();
20+
// code below will not be executed
2121
}
2222
```
2323

2424
:::info
2525
You must not call `stopEvents()` in try-catch block, otherwise it will not work as expected.
26-
:::
26+
:::

packages/commandkit/spec/cache.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
2-
import CommandKit, {
2+
import {
33
cache,
44
cacheTag,
55
cacheLife,
66
isCachedFunction,
77
invalidate,
88
revalidate,
9-
} from '../src';
10-
import { Client } from 'discord.js';
9+
CommandKit,
10+
// @ts-ignore
11+
} from 'commandkit';
1112
import { setTimeout } from 'node:timers/promises';
13+
import { Client } from 'discord.js';
1214

1315
describe('Cache', () => {
1416
let commandkit!: CommandKit, client!: Client;
1517

16-
beforeAll(() => {
18+
beforeAll(async () => {
1719
client = new Client({
1820
intents: [],
1921
});

packages/commandkit/spec/commandkit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, test } from 'vitest';
2-
import { CommandKit } from '../src/index';
2+
// @ts-ignore
3+
import CommandKit from 'commandkit';
34
import { Client } from 'discord.js';
45

56
describe('CommandKit', () => {

packages/commandkit/vitest.config.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineConfig } from 'vitest/config';
2-
import { cacheDirectivePlugin } from './src/plugins/runtime/builtin/cache/UseCacheTransformer';
2+
import { vite as cacheDirectivePlugin } from 'directive-to-hof';
33
import { join } from 'path';
44

55
export default defineConfig({
@@ -17,20 +17,12 @@ export default defineConfig({
1717
},
1818
},
1919
plugins: [
20-
{
21-
name: 'use-cache',
22-
async transform(code, id) {
23-
const valid = /\.(c|m)?(t|j)sx?$/.test(id);
24-
if (!valid) return null;
25-
26-
const { contents } = await cacheDirectivePlugin(code, { path: id });
27-
28-
return {
29-
code: contents,
30-
map: null,
31-
};
32-
},
33-
},
20+
cacheDirectivePlugin({
21+
directive: 'use cache',
22+
importPath: 'commandkit',
23+
importName: '__SECRET_USE_CACHE_INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
24+
asyncOnly: true,
25+
}),
3426
],
3527
optimizeDeps: {
3628
esbuildOptions: {

packages/devtools-ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"@radix-ui/react-toggle-group": "^1.1.2",
3434
"@radix-ui/react-tooltip": "^1.1.8",
3535
"@tabler/icons-react": "^3.31.0",
36+
"@tanstack/react-query": "^5.75.7",
3637
"@tanstack/react-table": "^8.21.2",
38+
"axios": "^1.9.0",
3739
"class-variance-authority": "0.7.1",
3840
"clsx": "^2.1.1",
3941
"lucide-react": "0.468.0",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import axios from 'axios';
2+
3+
export const axiosClient = axios.create({
4+
baseURL: import.meta.env.VITE_COMMANDKIT_API || '/api',
5+
});
6+
7+
axiosClient.interceptors.request.use((config) => {
8+
const token = localStorage.getItem('access_token');
9+
10+
if (token) {
11+
config.headers.Authorization = `Bearer ${token}`;
12+
}
13+
14+
return config;
15+
});
16+
17+
axiosClient.interceptors.response.use(
18+
(response) => {
19+
return response;
20+
},
21+
(error) => {
22+
if (error.response.status === 401) {
23+
localStorage.removeItem('access_token');
24+
window.location.href = '/';
25+
}
26+
27+
return Promise.reject(error);
28+
},
29+
);

0 commit comments

Comments
 (0)