Skip to content

Commit 806e33c

Browse files
authored
Merge pull request #37 from twlite/cli-docs
docs: document cli
2 parents 658791a + 9baa999 commit 806e33c

File tree

5 files changed

+135
-5
lines changed

5 files changed

+135
-5
lines changed

apps/docs/pages/docs/_meta.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"installation": "Installation",
33
"commandkit-setup": "CommandKit Setup",
4+
"commandkit.config.js-options": "commandkit.config.js Options",
45
"command-file-setup": "Commands Setup",
56
"event-file-setup": "Events Setup",
67
"validation-file-setup": "Validations Setup",
78
"buttonkit": "Using ButtonKit",
9+
"using-cli": "Using CommandKit CLI",
810
"using-signals": "Using Signals",
911
"migrating-from-djs-commander": "Migrating from DJS-Commander"
1012
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Callout } from 'nextra/components';
2+
3+
# commandkit.config.js options
4+
5+
<Callout type="warning">
6+
This is currently only available in the [development
7+
version](/docs/installation#development-version) of CommandKit.
8+
</Callout>
9+
10+
CommandKit CLI can be configured using `commandkit.config` file in the root of your project directory (for example, by `package.json`). You can use either of the following files:
11+
12+
- `commandkit.js`
13+
- `commandkit.config.js`
14+
- `commandkit.mjs`
15+
- `commandkit.config.mjs`
16+
- `commandkit.cjs`
17+
- `commandkit.config.cjs`
18+
- `commandkit.json`
19+
- `commandkit.config.json`
20+
21+
Throughout this guide, we'll be using `commandkit.config.mjs` as an example.
22+
23+
The following is the sample configuration required to run your bot:
24+
25+
```js title="commandkit.config.mjs"
26+
import { defineConfig } from 'commandkit';
27+
28+
export default defineConfig({
29+
src: 'src', // The source directory of your project.
30+
main: 'index.mjs', // The JavaScript entry point of your project.
31+
});
32+
```
33+
34+
## Options
35+
36+
### `src`: string
37+
38+
The source directory of the project. This is where your source code lives. This is a required option.
39+
40+
### `main`: string
41+
42+
The JavaScript entry point of your project. This is a required option.
43+
44+
For example, if your source is structured as `src/index.ts`, you'd need to set this option to `index.mjs`. This is because CommandKit always compiles your source code to esm format.
45+
46+
### `watch`: boolean
47+
48+
Whether to watch for file changes or not. This is an optional option. The default value is `true`.
49+
50+
### `outDir`: string
51+
52+
The output directory to emit the production build to. This is an optional option. The default value is `dist`.
53+
54+
### `envExtra`: boolean
55+
56+
Extra env utilities to load. This allows you to load environment variables in different formats, like `Date`, `JSON`, `Boolean`, etc. This is an optional option. The default value is set to `true`.
57+
58+
### `nodeOptions`: string[]
59+
60+
Options to pass to Node.js. This is an optional option. The default value is `[]`.
61+
62+
### `clearRestartLogs`: boolean
63+
64+
Whether or not to clear default restart logs. This is an optional option. The default value is `true`.
65+
66+
#### `minify`: boolean
67+
68+
Whether or not to minify the production build. This is an optional option. The default value is `false`.
69+
70+
### `sourcemap`: boolean | 'inline'
71+
72+
Whether or not to include sourcemaps in the production build. This is an optional option. The default value is `false`.
73+
74+
### `antiCrash`: boolean
75+
76+
Whether or not to inject anti-crash script in the production build. This is an optional option. The default value is `true`.

apps/docs/pages/docs/using-cli.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Callout } from 'nextra/components';
2+
3+
# Using CommandKit CLI
4+
5+
<Callout type="warning">
6+
This is currently only available in the [development
7+
version](/docs/installation#development-version) of CommandKit.
8+
</Callout>
9+
10+
CommandKit CLI allows you to start and build your bot application.
11+
12+
To get a list of the available CLI commands, run the following command inside your project directory:
13+
14+
```sh
15+
npx commandkit --help
16+
```
17+
18+
The output should look something like this:
19+
20+
```sh
21+
Usage: commandkit [options] [command]
22+
23+
Options:
24+
-h, --help display help for command
25+
26+
Commands:
27+
dev [options] Start your bot in development mode.
28+
start [options] Start your bot in production mode after running the build command.
29+
build [options] Build your project for production usage.
30+
help [command] display help for command
31+
```
32+
33+
<Callout type="info">
34+
CommandKit does not perform type checking on your code. You need to do that yourself using{' '}
35+
<code>tsc --noEmit</code> command or any other tool of your choice.
36+
</Callout>
37+
38+
# Available commands
39+
40+
## Build
41+
42+
`commandkit build` creates an optimized production build of your bot application. By default, commandkit emits the build to `dist/` directory in your project. It supports typescript out of the box.
43+
44+
CommandKit also injects anti-crash script in your production build to prevent your bot from crashing due to cases like unhandled promise rejections. Although, it's recommended to handle these cases yourself. You can disable this behavior by setting `antiCrash: false` in your `commandkit.config.js` file.
45+
46+
## Development
47+
48+
`commandkit dev` starts your bot in development mode. It supports hot reloading out of the box to automatically restart your bot when you make changes to your code. CommandKit automatically loads your environment variables from `.env` file in your project directory, without you having to worry about it. It also supports typescript out of the box.
49+
50+
## Production
51+
52+
`commandkit start` starts your bot in production mode. You need to run `commandkit build` before running this command. This command also loads the environment variables from `.env` file in your project directory.

packages/commandkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
],
4040
"dependencies": {
4141
"commander": "^11.1.0",
42+
"dotenv": "^16.3.1",
4243
"ora": "^7.0.1",
4344
"rfdc": "^1.3.0",
4445
"rimraf": "^5.0.5",
@@ -47,7 +48,6 @@
4748
"devDependencies": {
4849
"@types/node": "^20.5.9",
4950
"discord.js": "^14.13.0",
50-
"dotenv": "^16.3.1",
5151
"tsconfig": "workspace:*",
5252
"tsx": "^3.12.8",
5353
"typescript": "^5.1.6"

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)