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