Skip to content

Commit 5881fed

Browse files
committed
feat: migrate command handling to TypeScript and add file extension option for command files
1 parent e22829c commit 5881fed

4 files changed

Lines changed: 13 additions & 104 deletions

File tree

index.js

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

index.ts renamed to src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { REST } from "@discordjs/rest";
22
import { readdirSync } from "node:fs";
33
import path from "node:path";
4-
import { DeleteOptions, DeployOptions } from "./types.js";
4+
import { DeleteOptions, DeployOptions } from "../types.js";
55

66
const Routes = {
77
commands: (appId: string): `/${string}` => {
@@ -33,6 +33,7 @@ export async function deployCommands(
3333
opts: DeployOptions
3434
): Promise<boolean> {
3535
opts.logs = opts.logs ?? true;
36+
const FILE_EXTENSION = opts.fileExtension ?? ".js";
3637
if (!opts.appToken || !opts.appId) {
3738
throw new Error("Missing 'appToken' or 'appId' in 'opts'!");
3839
}
@@ -41,7 +42,7 @@ export async function deployCommands(
4142
let privateCommands = [];
4243

4344
const commandFiles = readdirSync(folderPath).filter((file) =>
44-
file.endsWith(".js")
45+
file.endsWith(FILE_EXTENSION)
4546
);
4647

4748
if (opts.logs)

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"skipLibCheck": true,
1212
"types": [ "node" ]
1313
},
14-
"include": [ "./index.ts" ],
15-
"exclude": [ "node_modules" ]
14+
"include": [ "./src/**/*.ts" ],
15+
"exclude": [ "node_modules", "dist" ]
1616
}

types.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export interface DeployOptions {
1313
* @default true
1414
*/
1515
logs?: boolean;
16+
/**
17+
* The file extension of the command files to be deployed.
18+
*
19+
* This can be useful in development environments where you might use `tsx` which allows you to use TypeScript files directly.
20+
*
21+
* @default ".js"
22+
*/
23+
fileExtension?: `.${string}`;
1624
}
1725

1826
export interface DeleteOptions {

0 commit comments

Comments
 (0)