Skip to content

Commit

Permalink
docs: document cli
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Dec 9, 2023
1 parent 658791a commit 6705fcd
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 7 deletions.
4 changes: 3 additions & 1 deletion apps/docs/pages/docs/_meta.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"installation": "Installation",
"commandkit-setup": "CommandKit Setup",
"commandkit.config.js-options": "CommandKit Config Options",
"command-file-setup": "Commands Setup",
"event-file-setup": "Events Setup",
"validation-file-setup": "Validations Setup",
"buttonkit": "Using ButtonKit",
"using-cli": "Using CommandKit CLI",
"using-signals": "Using Signals",
"migrating-from-djs-commander": "Migrating from DJS-Commander"
}
}
76 changes: 76 additions & 0 deletions apps/docs/pages/docs/commandkit.config.js-options.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Callout } from 'nextra/components';

# commandkit.config.js options

<Callout type="warning">
This is currently only available in the [development
version](/docs/installation#development-version) of CommandKit.
</Callout>

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:

- `commandkit.js`
- `commandkit.config.js`
- `commandkit.mjs`
- `commandkit.config.mjs`
- `commandkit.cjs`
- `commandkit.config.cjs`
- `commandkit.json`
- `commandkit.config.json`

Throughout this guide, we'll be using `commandkit.config.mjs` as an example.

The following is the sample configuration required to run your bot:

```js title="commandkit.config.mjs"
import { defineConfig } from 'commandkit';

export default defineConfig({
src: 'src', // The source directory of your project.
main: 'index.mjs', // The JavaScript entry point of your project.
});
```

## Options

### `src`: string

The source directory of the project. This is where your source code lives. This is a required option.

### `main`: string

The JavaScript entry point of your project. This is a required option.

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.

### `watch`: boolean

Whether to watch for file changes or not. This is an optional option. The default value is `true`.

### `outDir`: string

The output directory to emit the production build to. This is an optional option. The default value is `dist`.

### `envExtra`: boolean

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`.

### `nodeOptions`: string[]

Options to pass to Node.js. This is an optional option. The default value is `[]`.

### `clearRestartLogs`: boolean

Whether or not to clear default restart logs. This is an optional option. The default value is `true`.

#### `minify`: boolean

Whether or not to minify the production build. This is an optional option. The default value is `false`.

### `sourcemap`: boolean | 'inline'

Whether or not to include sourcemaps in the production build. This is an optional option. The default value is `false`.

### `antiCrash`: boolean

Whether or not to inject anti-crash script in the production build. This is an optional option. The default value is `true`.
52 changes: 52 additions & 0 deletions apps/docs/pages/docs/using-cli.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Callout } from 'nextra/components';

# Using CommandKit CLI

<Callout type="warning">
This is currently only available in the [development
version](/docs/installation#development-version) of CommandKit.
</Callout>

CommandKit CLI allows you to start and build your bot application.

To get a list of the available CLI commands, run the following command inside your project directory:

```sh
npx commandkit --help
```

The output should look something like this:

```sh
Usage: commandkit [options] [command]

Options:
-h, --help display help for command

Commands:
dev [options] Start your bot in development mode.
start [options] Start your bot in production mode after running the build command.
build [options] Build your project for production usage.
help [command] display help for command
```

<Callout type="info">
CommandKit does not perform type checking on your code. You need to do that yourself using{' '}
<code>tsc --noEmit</code> command or any other tool of your choice.
</Callout>

# Available commands

## Build

`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.

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.

## Development

`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.

## Production

`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.
4 changes: 2 additions & 2 deletions packages/commandkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
],
"dependencies": {
"commander": "^11.1.0",
"dotenv": "^16.3.1",
"ora": "^7.0.1",
"rfdc": "^1.3.0",
"rimraf": "^5.0.5",
Expand All @@ -47,12 +48,11 @@
"devDependencies": {
"@types/node": "^20.5.9",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"tsconfig": "workspace:*",
"tsx": "^3.12.8",
"typescript": "^5.1.6"
},
"peerDependencies": {
"discord.js": "^14"
}
}
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6705fcd

Please sign in to comment.