Added dev script for ts-node
This commit is contained in:
@@ -13,3 +13,5 @@ export type Profile2 = {
|
||||
profileActions: []
|
||||
}
|
||||
}
|
||||
|
||||
export type FileType = "js" | "ts"
|
||||
@@ -1,3 +1,3 @@
|
||||
import { Profile, Profile2 } from "./Profile"
|
||||
import { Profile, Profile2, FileType } from "./Types"
|
||||
|
||||
export { Profile, Profile2 }
|
||||
export { Profile, Profile2, FileType }
|
||||
@@ -8,15 +8,20 @@ import {
|
||||
Routes,
|
||||
} from "discord.js"
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../typings"
|
||||
|
||||
async function autoDeployCommands() {
|
||||
async function autoDeployCommands(fileType: FileType) {
|
||||
const commands = []
|
||||
const commandFiles = fs
|
||||
.readdirSync("./dist/src/commands/")
|
||||
.filter(file => file.endsWith(".js"))
|
||||
const contentMenuCommands = fs
|
||||
.readdirSync("./dist/src/commands-contextmenu/")
|
||||
.filter(file => file.endsWith(".js"))
|
||||
let commandFiles: string[] = []
|
||||
let contentMenuCommands: string[] = []
|
||||
|
||||
if (fileType === "js") {
|
||||
commandFiles = fs.readdirSync("./dist/src/commands/").filter(file => file.endsWith(fileType))
|
||||
contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||
} else if (fileType === "ts") {
|
||||
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
|
||||
contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
|
||||
}
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`)
|
||||
@@ -79,36 +84,34 @@ async function autoDeployCommands() {
|
||||
return
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
console.log(
|
||||
color.colorize(
|
||||
"Commands are different, starting deploy.",
|
||||
"red",
|
||||
),
|
||||
)
|
||||
console.log(color.colorize(currentCmds, "red"))
|
||||
console.log(
|
||||
`Started refreshing ${commands.length} application (/) commands.`,
|
||||
)
|
||||
try {
|
||||
console.log(
|
||||
color.colorize(
|
||||
"Commands are different, starting deploy.",
|
||||
"red",
|
||||
),
|
||||
)
|
||||
console.log(color.colorize(currentCmds, "red"))
|
||||
console.log(
|
||||
`Started refreshing ${commands.length} application (/) commands.`,
|
||||
)
|
||||
|
||||
const data = (await rest.put(
|
||||
Routes.applicationGuildCommands(
|
||||
config.dev.devid!,
|
||||
config.dev.guildid!,
|
||||
),
|
||||
{ body: commands },
|
||||
)) as RESTPutAPIApplicationGuildCommandsJSONBody[]
|
||||
const data = (await rest.put(
|
||||
Routes.applicationGuildCommands(
|
||||
config.dev.devid!,
|
||||
config.dev.guildid!,
|
||||
),
|
||||
{ body: commands },
|
||||
)) as RESTPutAPIApplicationGuildCommandsJSONBody[]
|
||||
|
||||
console.log(color.colorize("New commands deployed.", "green"))
|
||||
console.log(color.colorize(newCmds, "green"))
|
||||
console.log(
|
||||
`Successfully reloaded ${data.length} application (/) commands.`,
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
})()
|
||||
console.log(color.colorize("New commands deployed.", "green"))
|
||||
console.log(color.colorize(newCmds, "green"))
|
||||
console.log(
|
||||
`Successfully reloaded ${data.length} application (/) commands.`,
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
export { autoDeployCommands }
|
||||
|
||||
@@ -35,15 +35,21 @@ export class ExtendedClient extends Client {
|
||||
}
|
||||
|
||||
async start() {
|
||||
loadAllEvents(this)
|
||||
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev") {
|
||||
console.log("Running in development mode.")
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) {
|
||||
console.log("Running in development mode. [ts-node]")
|
||||
loadAllEvents(this, "ts")
|
||||
token = config.dev.devtoken!
|
||||
autoDeployCommands()
|
||||
autoDeployCommands("ts")
|
||||
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
|
||||
console.log("Running in development mode.")
|
||||
loadAllEvents(this, "js")
|
||||
token = config.dev.devtoken!
|
||||
autoDeployCommands("js")
|
||||
} else {
|
||||
console.log("Running in production mode.")
|
||||
loadAllEvents(this, "js")
|
||||
token = config.prod.token!
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@ import { loadContextMenuEvents } from "./eventHandlers/contextmenu"
|
||||
import { loadModalEvents } from "./eventHandlers/modal"
|
||||
import { loadEvents } from "./eventHandlers/events"
|
||||
import { loadAutocompleteEvents } from "./eventHandlers/autocomplete"
|
||||
import { FileType } from "../typings"
|
||||
|
||||
export function loadAllEvents(client: Client) {
|
||||
export function loadAllEvents(client: Client, ft: FileType) {
|
||||
loadEvents(client)
|
||||
loadButtonEvents(client)
|
||||
loadSlashCommandsEvents(client)
|
||||
loadContextMenuEvents(client)
|
||||
loadModalEvents(client)
|
||||
loadAutocompleteEvents(client)
|
||||
loadButtonEvents(client, ft)
|
||||
loadSlashCommandsEvents(client, ft)
|
||||
loadContextMenuEvents(client, ft)
|
||||
loadModalEvents(client, ft)
|
||||
loadAutocompleteEvents(client, ft)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ import { Autocomplete } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../../typings"
|
||||
|
||||
function loadAutocompleteEvents(client: Client) {
|
||||
function loadAutocompleteEvents(client: Client, ft: FileType) {
|
||||
const autocompletePath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
@@ -14,7 +15,7 @@ function loadAutocompleteEvents(client: Client) {
|
||||
)
|
||||
const autocompleteFiles = fs
|
||||
.readdirSync(autocompletePath)
|
||||
.filter(file => file.endsWith(".js"))
|
||||
.filter(file => file.endsWith(ft))
|
||||
|
||||
for (const file of autocompleteFiles) {
|
||||
const filePath = path.join(autocompletePath, file)
|
||||
|
||||
@@ -3,12 +3,13 @@ import { Button } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../../typings"
|
||||
|
||||
function loadButtonEvents(client: Client) {
|
||||
function loadButtonEvents(client: Client, ft: FileType) {
|
||||
const btnPath = path.join(__dirname, "..", "..", "events", "buttons")
|
||||
const btnFiles = fs
|
||||
.readdirSync(btnPath)
|
||||
.filter(file => file.endsWith(".js"))
|
||||
.filter(file => file.endsWith(ft))
|
||||
|
||||
for (const file of btnFiles) {
|
||||
const filePath = path.join(btnPath, file)
|
||||
|
||||
@@ -3,12 +3,11 @@ import { Command } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../../typings"
|
||||
|
||||
function loadSlashCommandsEvents(client: Client) {
|
||||
function loadSlashCommandsEvents(client: Client, ft: FileType) {
|
||||
const cmdPath = path.join(__dirname, "..", "..", "commands")
|
||||
const cmdFiles = fs
|
||||
.readdirSync(cmdPath)
|
||||
.filter(file => file.endsWith(".js"))
|
||||
const cmdFiles = fs .readdirSync(cmdPath) .filter(file => file.endsWith(ft))
|
||||
|
||||
for (const file of cmdFiles) {
|
||||
const filePath = path.join(cmdPath, file)
|
||||
|
||||
@@ -3,8 +3,9 @@ import { ContextMenu } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../../typings"
|
||||
|
||||
function loadContextMenuEvents(client: Client) {
|
||||
function loadContextMenuEvents(client: Client, ft: FileType) {
|
||||
const contextMenuPath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
@@ -13,7 +14,7 @@ function loadContextMenuEvents(client: Client) {
|
||||
)
|
||||
const contextMenuFiles = fs
|
||||
.readdirSync(contextMenuPath)
|
||||
.filter(file => file.endsWith(".js"))
|
||||
.filter(file => file.endsWith(ft))
|
||||
|
||||
for (const file of contextMenuFiles) {
|
||||
const filePath = path.join(contextMenuPath, file)
|
||||
|
||||
@@ -3,12 +3,13 @@ import { Modal } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
import { FileType } from "../../typings"
|
||||
|
||||
function loadModalEvents(client: Client) {
|
||||
function loadModalEvents(client: Client, ft: FileType) {
|
||||
const modalPath = path.join(__dirname, "..", "..", "events", "modals")
|
||||
const modalFiles = fs
|
||||
.readdirSync(modalPath)
|
||||
.filter(file => file.endsWith(".js"))
|
||||
.filter(file => file.endsWith(ft))
|
||||
|
||||
for (const file of modalFiles) {
|
||||
const filePath = path.join(modalPath, file)
|
||||
|
||||
Reference in New Issue
Block a user