Skip to content

Commit 51fbe2f

Browse files
committed
add lint + format scripts
1 parent be43aba commit 51fbe2f

File tree

21 files changed

+233
-156
lines changed

21 files changed

+233
-156
lines changed

.github/workflows/lint.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
build:
10+
name: 🔍 Lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: 📚 Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: 🟢 Node
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 16
20+
registry-url: https://registry.npmjs.org
21+
22+
- name: 🍳 Prepare
23+
run: npm install
24+
25+
- name: ✨ Lint
26+
run: npm run lint

.github/workflows/publish.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ jobs:
1111
steps:
1212
- name: 📚 Checkout
1313
uses: actions/checkout@v3
14-
- name: 🟢 node
14+
15+
- name: 🟢 Node
1516
uses: actions/setup-node@v2
1617
with:
1718
node-version: 16
1819
registry-url: https://registry.npmjs.org
20+
1921
- name: 🍳 Prepare
2022
run: |
2123
npm install
2224
npm run build
25+
2326
- name: 🚚 Publish
2427
run: npm publish
2528
env:

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/node_modules
2+
/dist
3+
.DS_Store
4+
.vscode
5+
README.md
6+
yarn.lock

.prettierrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 100,
33
"tabWidth": 4,
4-
"singleQuote": true
4+
"singleQuote": true,
5+
"arrowParens": "always"
56
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
}
1414
},
1515
"scripts": {
16-
"lint": "tsc",
17-
"build": "yarn lint && tsup"
16+
"lint": "tsc && prettier --check ./ --config .prettierrc.json --ignore-path=.prettierignore",
17+
"build": "yarn lint && tsup",
18+
"format": "prettier --write ./ --config .prettierrc.json"
1819
},
1920
"repository": {
2021
"type": "git",
@@ -31,7 +32,8 @@
3132
"colors": "^1.4.0"
3233
},
3334
"devDependencies": {
34-
"discord.js": "^14.12.1",
35+
"discord.js": "^14.13.0",
36+
"prettier": "^3.0.2",
3537
"tsup": "^7.2.0",
3638
"typescript": "^5.1.6"
3739
},

src/CommandKit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export class CommandKit {
1111
}
1212

1313
if (options.validationsPath && !options.commandsPath) {
14-
throw new Error(colors.red('"commandsPath" is required when "validationsPath" is set.'));
14+
throw new Error(
15+
colors.red('"commandsPath" is required when "validationsPath" is set.'),
16+
);
1517
}
1618

1719
this.#data = {

src/handlers/command-handler/CommandHandler.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class CommandHandler {
2626

2727
async #buildCommands() {
2828
const commandFilePaths = getFilePaths(this._data.commandsPath, true).filter(
29-
(path) => path.endsWith('.js') || path.endsWith('.ts')
29+
(path) => path.endsWith('.js') || path.endsWith('.ts'),
3030
);
3131

3232
for (const commandFilePath of commandFilePaths) {
@@ -39,12 +39,18 @@ export class CommandHandler {
3939
if (commandObj.default) commandObj = commandObj.default;
4040

4141
if (!commandObj.data) {
42-
console.log(colors.yellow(`⏩ Ignoring: Command ${compactFilePath} does not export "data".`));
42+
console.log(
43+
colors.yellow(
44+
`⏩ Ignoring: Command ${compactFilePath} does not export "data".`,
45+
),
46+
);
4347
continue;
4448
}
4549

4650
if (!commandObj.run) {
47-
console.log(colors.yellow(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`));
51+
console.log(
52+
colors.yellow(`⏩ Ignoring: Command ${compactFilePath} does not export "run".`),
53+
);
4854
continue;
4955
}
5056

src/handlers/command-handler/functions/handleCommands.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { CommandHandler } from "../CommandHandler";
1+
import { CommandHandler } from '../CommandHandler';
22

33
export default function handleCommands(commandHandler: CommandHandler) {
44
const client = commandHandler._data.client;
55

6-
client.on("interactionCreate", async (interaction) => {
6+
client.on('interactionCreate', async (interaction) => {
77
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand()) return;
88

9-
const targetCommand = commandHandler._data.commands.find((cmd) => cmd.data.name === interaction.commandName);
9+
const targetCommand = commandHandler._data.commands.find(
10+
(cmd) => cmd.data.name === interaction.commandName,
11+
);
1012

1113
if (!targetCommand) return;
1214

src/handlers/command-handler/functions/registerCommands.ts

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export default async function registerCommands(commandHandler: CommandHandler) {
1616

1717
if (!guild) {
1818
console.log(
19-
colors.yellow(`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`)
19+
colors.yellow(
20+
`⏩ Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`,
21+
),
2022
);
2123
continue;
2224
}
@@ -38,33 +40,41 @@ export default async function registerCommands(commandHandler: CommandHandler) {
3840
for (const command of commands) {
3941
// <!-- Delete command if options.deleted -->
4042
if (command.options?.deleted) {
41-
const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
43+
const targetCommand = appCommands?.cache.find(
44+
(cmd) => cmd.name === command.data.name,
45+
);
4246

4347
if (!targetCommand) {
4448
console.log(
45-
colors.yellow(`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`)
49+
colors.yellow(
50+
`⏩ Ignoring: Command "${command.data.name}" is globally marked as deleted.`,
51+
),
4652
);
4753
} else {
4854
targetCommand.delete().then(() => {
49-
console.log(colors.green(`🚮 Deleted command "${command.data.name}" globally.`));
55+
console.log(
56+
colors.green(`🚮 Deleted command "${command.data.name}" globally.`),
57+
);
5058
});
5159
}
5260

5361
for (const guildCommands of devGuildCommands) {
54-
const targetCommand = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
62+
const targetCommand = guildCommands.cache.find(
63+
(cmd) => cmd.name === command.data.name,
64+
);
5565

5666
if (!targetCommand) {
5767
console.log(
5868
colors.yellow(
59-
`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`
60-
)
69+
`⏩ Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`,
70+
),
6171
);
6272
} else {
6373
targetCommand.delete().then(() => {
6474
console.log(
6575
colors.green(
66-
`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`
67-
)
76+
`🚮 Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`,
77+
),
6878
);
6979
});
7080
}
@@ -78,19 +88,30 @@ export default async function registerCommands(commandHandler: CommandHandler) {
7888
let editedCommand = false;
7989

8090
// Edit command globally
81-
const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
91+
const appGlobalCommand = appCommands?.cache.find(
92+
(cmd) => cmd.name === command.data.name,
93+
);
8294

8395
if (appGlobalCommand) {
84-
const commandsAreDifferent = areSlashCommandsDifferent(appGlobalCommand, commandData);
96+
const commandsAreDifferent = areSlashCommandsDifferent(
97+
appGlobalCommand,
98+
commandData,
99+
);
85100

86101
if (commandsAreDifferent) {
87102
appGlobalCommand
88103
.edit(commandData)
89104
.then(() => {
90-
console.log(colors.green(`✅ Edited command "${commandData.name}" globally.`));
105+
console.log(
106+
colors.green(`✅ Edited command "${commandData.name}" globally.`),
107+
);
91108
})
92109
.catch((error) => {
93-
console.log(colors.red(`❌ Failed to edit command "${commandData.name}" globally.`));
110+
console.log(
111+
colors.red(
112+
`❌ Failed to edit command "${commandData.name}" globally.`,
113+
),
114+
);
94115
console.error(error);
95116
});
96117

@@ -100,26 +121,31 @@ export default async function registerCommands(commandHandler: CommandHandler) {
100121

101122
// Edit command in a specific guild
102123
for (const guildCommands of devGuildCommands) {
103-
const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
124+
const appGuildCommand = guildCommands.cache.find(
125+
(cmd) => cmd.name === commandData.name,
126+
);
104127

105128
if (appGuildCommand) {
106-
const commandsAreDifferent = areSlashCommandsDifferent(appGuildCommand, commandData);
129+
const commandsAreDifferent = areSlashCommandsDifferent(
130+
appGuildCommand,
131+
commandData,
132+
);
107133

108134
if (commandsAreDifferent) {
109135
appGuildCommand
110136
.edit(commandData)
111137
.then(() => {
112138
console.log(
113139
colors.green(
114-
`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`
115-
)
140+
`✅ Edited command "${commandData.name}" in ${guildCommands.guild.name}.`,
141+
),
116142
);
117143
})
118144
.catch((error) => {
119145
console.log(
120146
colors.red(
121-
`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
122-
)
147+
`❌ Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`,
148+
),
123149
);
124150
console.error(error);
125151
});
@@ -137,24 +163,32 @@ export default async function registerCommands(commandHandler: CommandHandler) {
137163
if (!devGuilds.length) {
138164
console.log(
139165
colors.yellow(
140-
`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`
141-
)
166+
`⏩ Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`,
167+
),
142168
);
143169
continue;
144170
}
145171

146172
for (const guild of devGuilds) {
147-
const cmdExists = guild.commands.cache.some((cmd) => cmd.name === command.data.name);
173+
const cmdExists = guild.commands.cache.some(
174+
(cmd) => cmd.name === command.data.name,
175+
);
148176
if (cmdExists) continue;
149177

150178
guild?.commands
151179
.create(command.data)
152180
.then(() => {
153-
console.log(colors.green(`✅ Registered command "${command.data.name}" in ${guild.name}.`));
181+
console.log(
182+
colors.green(
183+
`✅ Registered command "${command.data.name}" in ${guild.name}.`,
184+
),
185+
);
154186
})
155187
.catch((error) => {
156188
console.log(
157-
colors.red(`❌ Failed to register command "${command.data.name}" in ${guild.name}.`)
189+
colors.red(
190+
`❌ Failed to register command "${command.data.name}" in ${guild.name}.`,
191+
),
158192
);
159193
console.error(error);
160194
});
@@ -168,10 +202,16 @@ export default async function registerCommands(commandHandler: CommandHandler) {
168202
appCommands
169203
?.create(command.data)
170204
.then(() => {
171-
console.log(colors.green(`✅ Registered command "${command.data.name}" globally.`));
205+
console.log(
206+
colors.green(`✅ Registered command "${command.data.name}" globally.`),
207+
);
172208
})
173209
.catch((error) => {
174-
console.log(colors.red(`❌ Failed to register command "${command.data.name}" globally.`));
210+
console.log(
211+
colors.red(
212+
`❌ Failed to register command "${command.data.name}" globally.`,
213+
),
214+
);
175215
console.error(error);
176216
});
177217
}

src/handlers/command-handler/typings.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ChatInputCommandInteraction, Client, ContextMenuCommandInteraction } from "discord.js";
2-
import { ContextCommandObject, SlashCommandObject } from "../../typings";
1+
import { ChatInputCommandInteraction, Client, ContextMenuCommandInteraction } from 'discord.js';
2+
import { ContextCommandObject, SlashCommandObject } from '../../typings';
33

44
export interface CommandHandlerOptions {
55
client: Client;

0 commit comments

Comments
 (0)