nuxt-discord 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,7 +10,6 @@ A Nuxt module for building Discord bots with slash commands, featuring hot modul
10
10
 
11
11
  - 🤖 **Discord Bot Integration** - Seamlessly integrate Discord.js with your Nuxt application
12
12
  - ⚡ **Slash Commands** - Type-safe slash command definitions with automatic registration
13
- - 🔥 **Hot Module Replacement** - Real-time command updates during development
14
13
  - 🎯 **Auto-sync** - Automatically sync commands with Discord's servers
15
14
  - 🖥️ **Web Interface** - Beautiful UI for managing and viewing slash commands
16
15
  - 🔄 **Real-time Updates** - WebSocket-based live updates in development
@@ -66,6 +65,8 @@ export default function ping() {
66
65
  }
67
66
  ```
68
67
 
68
+ Defining a command this way this module automatically deduces the name and description from the JSDoc comments. The command name is inferred following this set of priorities: `describeCommand` macro > `@name` JSDoc tag > function name > file name.
69
+
69
70
  ### Commands with Parameters
70
71
 
71
72
  ```ts
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "configKey": "discord",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useLogger, createResolver, installModule, extendPages, updateTemplates, addVitePlugin, isIgnored, addServerTemplate, addTemplate, addTypeTemplate, defineNuxtModule, addServerScanDir, addImports } from '@nuxt/kit';
2
2
  import { ApplicationCommandOptionType, GatewayIntentBits } from 'discord.js';
3
3
  import { globSync, readFileSync, existsSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
4
5
  import ts from 'typescript';
5
6
  import { listen } from 'listhen';
6
7
  import { WebSocketServer } from 'ws';
@@ -171,9 +172,11 @@ function processCommandFile(ctx, file) {
171
172
  ctx.logger.warn(`No command definition found for ${file}`);
172
173
  return;
173
174
  }
175
+ const { name } = path.parse(file);
174
176
  const command = {
175
177
  path: file,
176
- options: []
178
+ options: [],
179
+ name
177
180
  };
178
181
  if ((ts.isFunctionDeclaration(commandDefinition) || ts.isFunctionExpression(commandDefinition)) && !!commandDefinition.name && ts.isIdentifier(commandDefinition.name) && commandDefinition.name.escapedText) {
179
182
  command.name = commandDefinition.name.escapedText;
@@ -188,15 +191,15 @@ function processCommandFile(ctx, file) {
188
191
  return;
189
192
  }
190
193
  for (const param of commandDefinition.parameters) {
191
- const name = param.name.getText(sourceFile);
194
+ const name2 = param.name.getText(sourceFile);
192
195
  let type = param.type?.getText(sourceFile);
193
196
  if (!type || !(type in typeIdentifierToEnum)) {
194
- ctx.logger.warn(`Unknown slash command option type: ${type} for parameter ${name} in ${file}, defaulting to string`);
197
+ ctx.logger.warn(`Unknown slash command option type: ${type} for parameter ${name2} in ${file}, defaulting to string`);
195
198
  type = "string";
196
199
  }
197
- const jsdocDescription = jsDocTags.find((tag) => ts.isJSDocParameterTag(tag) && tag.name.getText() === name)?.comment?.toString() ?? "";
200
+ const jsdocDescription = jsDocTags.find((tag) => ts.isJSDocParameterTag(tag) && tag.name.getText() === name2)?.comment?.toString() ?? "";
198
201
  command.options.push({
199
- name,
202
+ name: name2,
200
203
  // TODO: remove this type assertion
201
204
  type: typeIdentifierToEnum[type],
202
205
  description: jsdocDescription,
@@ -362,7 +362,7 @@ function propsEqual(a, b, props) {
362
362
  return true;
363
363
  }
364
364
  function optionEqual(a, b) {
365
- if (a.name !== b.name || a.description !== b.description || a.required !== b.required || a.type !== b.type) {
365
+ if (a.name !== b.name || a.description !== b.description || a.required !== !!b.required || a.type !== b.type) {
366
366
  return false;
367
367
  }
368
368
  if (!!("choices" in a && a.choices) !== !!("choices" in b && b.choices)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "type": "module",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "description": "A Nuxt module for building Discord bots",
6
6
  "author": "Jize Zou <jeffzou2001@gmail.com> (https://github.com/zojize)",
7
7
  "license": "MIT",
@@ -81,7 +81,6 @@
81
81
  "lint": "eslint .",
82
82
  "test": "vitest run",
83
83
  "test:watch": "vitest watch",
84
- "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
85
- "postinstall": "npx simple-git-hooks"
84
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
86
85
  }
87
86
  }