Migrate to Babel

main
Mari 2 years ago
parent fe448ce99c
commit 013fcdc57c
  1. 3
      .gitignore
  2. 11
      babel.config.json
  3. 9
      jest.config.ts
  4. 8575
      package-lock.json
  5. 7
      package.json
  6. 8
      src/commands/bot/index.ts
  7. 114
      src/commands/bot/rebuild.ts
  8. 14
      src/commands/bot/restart.ts
  9. 12
      src/commands/bot/shutdown.ts
  10. 16
      src/commands/character/create.ts
  11. 4
      src/commands/character/index.ts
  12. 10
      src/commands/index.spec.ts
  13. 6
      src/commands/index.ts
  14. 1
      src/ipc/restart.ts
  15. 8
      src/main.ts
  16. 6
      tsconfig.json

3
.gitignore vendored

@ -18,4 +18,5 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.idea
/.idea
/output.log

@ -0,0 +1,11 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
],
"sourceMaps": true
}

@ -102,7 +102,7 @@ export default {
// notifyMode: "failure-change",
// A preset that is used as a base for Jest's configuration
preset: 'ts-jest',
// preset: 'ts-jest',
// Run tests from one or more projects
// projects: undefined,
@ -161,9 +161,10 @@ export default {
// ],
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "/node_modules/"
// ],
testPathIgnorePatterns: [
"/node_modules/",
"/build/",
],
// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

8575
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -20,8 +20,15 @@
"ts-postgres": "^1.3.0"
},
"devDependencies": {
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
"@babel/preset-env": "^7.19.3",
"@babel/preset-typescript": "^7.18.6",
"@tsconfig/node18": "^1.0.1",
"@types/pg": "^8.6.5",
"babel-jest": "^29.1.2",
"jest": "^29.1.2",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",

@ -1,8 +1,8 @@
import {BaseChatInputCommandData, CommandWithSubcommandsData} from "../types.js"
import {BaseChatInputCommandData, CommandWithSubcommandsData} from "../types"
import {ApplicationCommandType} from "discord.js"
import {commandBotRestart} from "./restart.js"
import {commandBotShutdown} from "./shutdown.js"
import {commandBotRebuild} from "./rebuild.js"
import {commandBotRestart} from "./restart"
import {commandBotShutdown} from "./shutdown"
import {commandBotRebuild} from "./rebuild"
class BotCommandData extends CommandWithSubcommandsData {
readonly baseDefinition: BaseChatInputCommandData = {

@ -1,13 +1,13 @@
import {adminId, SubcommandData} from "../types.js"
import {adminId, SubcommandData} from "../types"
import {
ActivityType,
ApplicationCommandOptionType,
ApplicationCommandSubCommandData,
ChatInputCommandInteraction,
} from "discord.js"
import {wrappedRestart} from "../../ipc/restart.js"
import {spawn} from "child_process"
import {defaultPresence} from "../../defaultPresence.js"
import {wrappedRestart} from "../../ipc/restart"
import {fork} from "child_process"
import {defaultPresence} from "../../defaultPresence"
import {resolve as resolvePath} from "path"
class RebuildCommand extends SubcommandData {
@ -20,8 +20,56 @@ class RebuildCommand extends SubcommandData {
async execute(b: ChatInputCommandInteraction): Promise<void> {
const user = b.user || b.member
if (!!user && user.id === adminId) {
await b.reply("Mmm... let's see... this goes here...")
await b.reply({
content: "I dunno... Let's check if this will work...",
ephemeral: true,
})
const self = b.client.user
self.setPresence({
status: "online",
afk: false,
activities: [
{
type: ActivityType.Playing,
name: "A Test of Your Codes",
},
],
})
try {
await new Promise<void>((resolve, reject) => {
const result = fork(resolvePath("./node_modules/jest-cli/bin/jest"), {
execPath: process.execPath,
execArgv: process.execArgv,
cwd: process.cwd(),
stdio: "inherit",
detached: true,
})
result.disconnect()
result.on("error", (ex) => {
reject(ex)
})
result.on("exit", (code) => {
if (code !== 0) {
reject(`Bad exit code ${code}`)
} else {
resolve()
}
})
})
} catch (ex) {
console.log(ex)
self.setPresence(defaultPresence)
await b.followUp({
content: "Oh no... It's not working... Oh well...",
ephemeral: true,
})
return
}
await b.followUp({
content: "Mmm... let's see... this goes here...",
ephemeral: true,
})
self.setPresence({
status: "online",
afk: false,
@ -34,12 +82,49 @@ class RebuildCommand extends SubcommandData {
})
try {
await new Promise<void>((resolve, reject) => {
const result = spawn(resolvePath("./node_modules/.bin/tsc"), {
const result = fork(resolvePath("./node_modules/typescript/bin/tsc"), {
execPath: process.execPath,
execArgv: process.execArgv,
cwd: process.cwd(),
stdio: "inherit",
detached: true,
shell: true,
})
result.disconnect()
result.on("error", (ex) => {
reject(ex)
})
result.on("exit", (code) => {
if (code !== 0) {
reject(`Bad exit code ${code}`)
} else {
resolve()
}
})
})
} catch (ex) {
console.log(ex)
self.setPresence(defaultPresence)
await b.followUp({
ephemeral: true,
content: "I dunno... how to fit these together....",
})
return
}
await b.followUp({
content: "Hmm hmm~ Annnd some gluuue...",
ephemeral: true,
})
try {
await new Promise<void>((resolve, reject) => {
const result = fork(resolvePath("./node_modules/@babel/cli/bin/babel"),
["src", "--out-dir", "build", "--extensions", ".ts"], {
execPath: process.execPath,
execArgv: process.execArgv,
cwd: process.cwd(),
stdio: "inherit",
detached: true,
})
result.disconnect()
result.on("error", (ex) => {
reject(ex)
})
@ -54,7 +139,10 @@ class RebuildCommand extends SubcommandData {
} catch (ex) {
console.log(ex)
self.setPresence(defaultPresence)
await b.followUp("Oops... I think it's broke...")
await b.followUp({
ephemeral: true,
content: "Oops... I think it's broken... Sowwy...",
})
return
}
self.setPresence({
@ -67,10 +155,16 @@ class RebuildCommand extends SubcommandData {
},
],
})
await b.followUp("Phewwww... now I'll just... take a quick nap after all that hard work...")
await b.followUp({
ephemeral: true,
content: "Phewwww... now I'll just... take a quick nap after all that hard work...",
})
await wrappedRestart(b)
} else {
await b.reply("Heeey... I don't gotta do what you say...")
await b.reply({
ephemeral: true,
content: "Heeey... I don't gotta do what you say...",
})
}
}
}

@ -1,11 +1,11 @@
import {adminId, SubcommandData} from "../types.js"
import {adminId, SubcommandData} from "../types"
import {
ActivityType,
ApplicationCommandOptionType,
ApplicationCommandSubCommandData,
ChatInputCommandInteraction,
} from "discord.js"
import {wrappedRestart} from "../../ipc/restart.js"
import {wrappedRestart} from "../../ipc/restart"
class RestartCommand extends SubcommandData {
readonly definition: ApplicationCommandSubCommandData = {
@ -17,7 +17,10 @@ class RestartCommand extends SubcommandData {
async execute(b: ChatInputCommandInteraction): Promise<void> {
const user = b.user || b.member
if (!!user && user.id === adminId) {
await b.reply("Yaaaawwn... Okay... Just a quick nap then...")
await b.reply({
ephemeral: true,
content: "Yaaaawwn... Okay... Just a quick nap then...",
})
const self = b.client.user
self.setPresence({
status: "idle",
@ -31,7 +34,10 @@ class RestartCommand extends SubcommandData {
})
await wrappedRestart(b)
} else {
await b.reply("Heeey... I don't gotta do what you say...")
await b.reply({
ephemeral: true,
content: "Heeey... I don't gotta do what you say...",
})
}
}
}

@ -1,4 +1,4 @@
import {adminId, SubcommandData} from "../types.js"
import {adminId, SubcommandData} from "../types"
import {ApplicationCommandOptionType, ApplicationCommandSubCommandData, ChatInputCommandInteraction} from "discord.js"
class ShutdownCommand extends SubcommandData {
@ -11,7 +11,10 @@ class ShutdownCommand extends SubcommandData {
async execute(b: ChatInputCommandInteraction): Promise<void> {
const user = b.user || b.member
if (!!user && user.id === adminId) {
await b.reply("Good night =w=")
await b.reply({
ephemeral: true,
content: "Good night =w=",
})
const self = b.client.user
self.presence.set({
status: "invisible",
@ -19,7 +22,10 @@ class ShutdownCommand extends SubcommandData {
})
b.client.destroy()
} else {
await b.reply("Heeey... I don't gotta do what you say...")
await b.reply({
ephemeral: true,
content: "Heeey... I don't gotta do what you say...",
})
}
}
}

@ -1,23 +1,29 @@
import {ApplicationCommandOptionType, ApplicationCommandSubCommandData, ChatInputCommandInteraction} from "discord.js"
import {SubcommandData} from "../types.js"
import {SubcommandData} from "../types"
class CharacterCreateCommandData extends SubcommandData {
readonly definition: ApplicationCommandSubCommandData = {
name: "create",
type: ApplicationCommandOptionType.Subcommand,
description: "Creates a new character. Activates them on the current server.",
description: "Begins the process of creating a new character.",
options: [
{
name: "template",
name: "name",
type: ApplicationCommandOptionType.String,
description: "Optionally, an existing character of yours to use as a template.",
autocomplete: true,
description: "The character's name.",
required: false,
},
{
name: "title",
type: ApplicationCommandOptionType.String,
description: "A title for your character, optionally starting or ending with an ellipsis (...).",
required: false,
},
],
}
async execute(b: ChatInputCommandInteraction) {
await b.deferReply({ephemeral: true})
await b.reply("Okaaaay, I'll make you a character ❤\n\nRight after this nap...")
}
}

@ -1,6 +1,6 @@
import {ApplicationCommandOptionType, ApplicationCommandSubCommandData, ApplicationCommandType} from "discord.js"
import {commandCharacterCreate} from "./create.js"
import {BaseChatInputCommandData, CommandWithSubcommandsData} from "../types.js"
import {commandCharacterCreate} from "./create"
import {BaseChatInputCommandData, CommandWithSubcommandsData} from "../types"
class CharacterCommandData extends CommandWithSubcommandsData {
readonly baseDefinition: BaseChatInputCommandData = {

@ -0,0 +1,10 @@
import {commandDefinitions} from "./index"
import {describe, expect, test} from "@jest/globals"
describe("command definitions", () => {
test("has no descriptions over 100 characters", () => {
expect(commandDefinitions)
.not
.toContain(expect.objectContaining({"description": expect.stringMatching(/.{101,}/)}))
})
})

@ -6,9 +6,9 @@ import {
ChatInputCommandInteraction,
Collection,
} from "discord.js"
import {commandCharacter} from "./character/index.js"
import {CommandData} from "./types.js"
import {commandBot} from "./bot/index.js"
import {commandCharacter} from "./character/index"
import {CommandData} from "./types"
import {commandBot} from "./bot/index"
const commands: CommandData[] = [
commandCharacter,

@ -135,6 +135,7 @@ export async function doRestart(client: Client, appId: string, token: string,
return new Promise((resolve, reject) => {
const child = fork(process.argv[1], process.argv.slice(2), {
execPath: process.execPath,
execArgv: process.execArgv,
cwd: process.cwd(),
detached: true,
stdio: "inherit",

@ -1,9 +1,9 @@
import {BaseInteraction, Client} from "discord.js"
import {config} from "dotenv"
import {isChatInputCommand} from "./types/interactions.js"
import {commandDefinitions, executeCommand, storeCachedCommands} from "./commands/index.js"
import {checkIsRestart, reportFailed, reportReady, reportStarted} from "./ipc/restart.js"
import {defaultPresence} from "./defaultPresence.js"
import {isChatInputCommand} from "./types/interactions"
import {commandDefinitions, executeCommand, storeCachedCommands} from "./commands/index"
import {checkIsRestart, reportFailed, reportReady, reportStarted} from "./ipc/restart"
import {defaultPresence} from "./defaultPresence"
async function main() {
await checkIsRestart()

@ -4,8 +4,9 @@
"lib": [
"esnext"
],
"noEmit": true,
"allowJs": true,
"skipLibCheck": false,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
@ -15,7 +16,7 @@
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"isolatedModules": true,
"outDir": "build",
"sourceMap": true
},
@ -24,6 +25,5 @@
],
"exclude": [
"node_modules/**",
"**/*.spec.ts"
]
}

Loading…
Cancel
Save