Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/test-bot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.env
.commandkit
compiled-commandkit.config.mjs
*.db*
*.db*
.workflow-data/
.swc/
2 changes: 2 additions & 0 deletions apps/test-bot/commandkit.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { cache } from '@commandkit/cache';
import { ai } from '@commandkit/ai';
import { tasks, setDriver } from '@commandkit/tasks';
import { BullMQDriver } from '@commandkit/tasks/bullmq';
import { workflowRollupPlugin } from 'workflow/rollup';

noBuildOnly(() => {
setDriver(
Expand All @@ -15,6 +16,7 @@ noBuildOnly(() => {
})();

export default defineConfig({
rolldownPlugins: [workflowRollupPlugin()],
plugins: [
i18n(),
devtools(),
Expand Down
1 change: 1 addition & 0 deletions apps/test-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"discord.js": "catalog:discordjs",
"dotenv": "^16.4.7",
"ms": "^2.1.3",
"workflow": "4.0.1-beta.11",
"zod": "^4.1.1"
},
"devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions apps/test-bot/src/app/commands/greet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { greetUserWorkflow } from '@/workflows/greet/greet.workflow';
import type { CommandData, ChatInputCommand, MessageCommand } from 'commandkit';
import { start } from 'workflow/api';

export const command: CommandData = {
name: 'greet',
description: 'greet command',
};

export const chatInput: ChatInputCommand = async (ctx) => {
await ctx.interaction.reply(`I'm gonna greet you :wink:`);

await start(greetUserWorkflow, [ctx.interaction.user.id]);
};

export const message: MessageCommand = async (ctx) => {
await ctx.message.reply(`I'm gonna greet you :wink:`);

await start(greetUserWorkflow, [ctx.message.author.id]);
};
14 changes: 14 additions & 0 deletions apps/test-bot/src/workflows/greet/greet.workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { sleep } from 'workflow';
import { greetUser } from './steps/greet.step';

export async function greetUserWorkflow(userId: string) {
'use workflow';

await greetUser(userId);

await sleep('5 seconds');

await greetUser(userId, true);

return { success: true };
}
14 changes: 14 additions & 0 deletions apps/test-bot/src/workflows/greet/steps/greet.step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Logger } from 'commandkit';
import { useClient } from 'commandkit/hooks';

export async function greetUser(userId: string, again = false) {
'use step';

const client = useClient<true>();

const user = await client.users.fetch(userId);

const message = again ? 'Hello again!' : 'Hello!';

await user.send(message);
}
38 changes: 38 additions & 0 deletions examples/with-workflow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# dependencies
node_modules

# build output
build
out
dist

# commandkit
.commandkit
dist
compiled-commandkit.config.mjs

# env
**/*.env*
!**/*.env.example*

# logging
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# yarn v2+
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# other
**/*.DS_Store
.temp-example
.workflow-data/
.swc/
16 changes: 16 additions & 0 deletions examples/with-workflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Welcome to CommandKit + TypeScript

> This project was generated by [create-commandkit](https://npmjs.com/package/create-commandkit).

Thanks for choosing CommandKit to build your Discord bot!

## To run this project

```
npx commandkit dev
```

## Useful links

- [Documentation](https://commandkit.dev)
- [Discord](https://ctrl.lol/discord)
1 change: 1 addition & 0 deletions examples/with-workflow/commandkit-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference path="node_modules/commandkit-types/index.d.ts" />
6 changes: 6 additions & 0 deletions examples/with-workflow/commandkit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'commandkit/config';
import { workflowRollupPlugin } from 'workflow/rollup';

export default defineConfig({
rolldownPlugins: [workflowRollupPlugin()],
});
22 changes: 22 additions & 0 deletions examples/with-workflow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "commandkit-basic-ts",
"description": "A CommandKit project using TypeScript",
"version": "0.1.0",
"type": "module",
"private": true,
"main": "dist/index.js",
"scripts": {
"dev": "commandkit dev",
"build": "commandkit build",
"start": "commandkit start"
},
"devDependencies": {
"@types/node": "^24.0.10",
"typescript": "^5.8.3"
},
"dependencies": {
"commandkit": "^1.2.0-rc.12",
"discord.js": "^14.24.0",
"workflow": "^4.0.1-beta.11"
}
}
7 changes: 7 additions & 0 deletions examples/with-workflow/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Client } from 'discord.js';

const client = new Client({
intents: ['Guilds', 'GuildMembers', 'GuildMessages', 'MessageContent'],
});

export default client;
20 changes: 20 additions & 0 deletions examples/with-workflow/src/app/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { ChatInputCommand, MessageCommand, CommandData } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: "Ping the bot to check if it's online.",
};

export const chatInput: ChatInputCommand = async (ctx) => {
const latency = (ctx.client.ws.ping ?? -1).toString();
const response = `Pong! Latency: ${latency}ms`;

await ctx.interaction.reply(response);
};

export const message: MessageCommand = async (ctx) => {
const latency = (ctx.client.ws.ping ?? -1).toString();
const response = `Pong! Latency: ${latency}ms`;

await ctx.message.reply(response);
};
8 changes: 8 additions & 0 deletions examples/with-workflow/src/app/events/clientReady/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { EventHandler } from 'commandkit';
import { Logger } from 'commandkit/logger';

const handler: EventHandler<'clientReady'> = async (client) => {
Logger.info(`Logged in as ${client.user.username}!`);
};

export default handler;
14 changes: 14 additions & 0 deletions examples/with-workflow/src/workflows/greet/greet.workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { sleep } from 'workflow';
import { greetUser } from './steps/greet.step';

export async function greetUserWorkflow(userId: string) {
'use workflow';

await greetUser(userId);

await sleep('5 seconds');

await greetUser(userId, true);

return { success: true };
}
12 changes: 12 additions & 0 deletions examples/with-workflow/src/workflows/greet/steps/greet.step.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useClient } from 'commandkit/hooks';

export async function greetUser(userId: string, again = false) {
'use step';

const client = useClient<true>();
const user = await client.users.fetch(userId);

const message = again ? 'Hello again!' : 'Hello!';

await user.send(message);
}
29 changes: 29 additions & 0 deletions examples/with-workflow/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"moduleResolution": "Node",
"module": "Preserve",
"allowImportingTsExtensions": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"noUncheckedIndexedAccess": true,
"removeComments": true,
"allowJs": true,
"strict": true,
"alwaysStrict": true,
"noEmit": true,
"declaration": false,
"jsx": "react-jsx",
"jsxImportSource": "commandkit",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src", "commandkit.config.ts", "commandkit-env.d.ts"],
"exclude": ["dist", "node_modules", ".commandkit"]
}
12 changes: 7 additions & 5 deletions packages/commandkit/src/cli/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,15 @@ export async function copyLocaleFiles(_from: string, _to: string) {
const destLocalePath = destLocalePaths[srcLocalePaths.indexOf(localePath)];

if (!fs.existsSync(destLocalePath)) {
fs.promises.mkdir(destLocalePath, { recursive: true });
fs.promises.mkdir(destLocalePath, { recursive: true }).catch(() => {});
}

await fs.promises.cp(localePath, destLocalePath, {
recursive: true,
force: true,
});
await fs.promises
.cp(localePath, destLocalePath, {
recursive: true,
force: true,
})
.catch(() => {});
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/create-commandkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ npx create-commandkit@latest --example "https://github.com/user/repo" --example-
- `basic-js` - [examples/basic-js](https://github.com/underctrl-io/commandkit/tree/main/examples/basic-js)
- `basic-ts` - [examples/basic-ts](https://github.com/underctrl-io/commandkit/tree/main/examples/basic-ts)
- `deno-ts` - [examples/deno-ts](https://github.com/underctrl-io/commandkit/tree/main/examples/deno-ts)
- `with-ai` - [examples/with-ai](https://github.com/underctrl-io/commandkit/tree/main/examples/with-ai)
- `with-leveling-system` - [examples/with-leveling-system](https://github.com/underctrl-io/commandkit/tree/main/examples/with-leveling-system)
- `with-workflow` - [examples/with-workflow](https://github.com/underctrl-io/commandkit/tree/main/examples/with-workflow)
- `without-cli` - [examples/without-cli](https://github.com/underctrl-io/commandkit/tree/main/examples/without-cli)
<!-- END_AVAILABLE_EXAMPLES -->

Expand Down
Loading
Loading