diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1da61d3..2ce1b61 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: - run: npm test - name: Deploy slash commands if: github.event_name == 'push' - run: node --loader ts-node/esm src/deploy-commands.js + run: node src/deploy-commands.js env: DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} APPLICATION_ID: ${{ secrets.APPLICATION_ID }} diff --git a/.github/workflows/typecheck.yml b/.github/workflows/typecheck.yml index 4ea84f3..6ec7f2d 100644 --- a/.github/workflows/typecheck.yml +++ b/.github/workflows/typecheck.yml @@ -1,4 +1,4 @@ -name: TypeScript Check +name: Type Check on: push: diff --git a/README.md b/README.md index 20cbfae..cc511e0 100644 --- a/README.md +++ b/README.md @@ -43,21 +43,15 @@ A Discord bot that allows you to create GitHub issues directly from Discord. Use GITHUB_REPO=username/repository-name ``` -4. **Compile TypeScript** +4. **Register slash commands** ```bash - npx tsc + node src/deploy-commands.js ``` -5. **Register slash commands** - +5. **Start the bot** ```bash - node dist/deploy-commands.js - ``` - -6. **Start the bot** - ```bash - node dist/index.js + node src/index.js ``` ## ⚙️ Configuration @@ -113,30 +107,22 @@ After successful creation, you'll receive a response like: ``` discord-github-bot/ ├── src/ -│ ├── deploy-commands.ts # Register slash commands -│ └── index.ts # Main bot logic +│ ├── deploy-commands.js # Register slash commands +│ └── index.js # Main bot logic ├── package.json -├── tsconfig.json +├── jsconfig.json ├── .env # Environment variables (not in Git) └── README.md ``` ## 🔧 Development -### Compile and watch TypeScript +To automatically reload the bot during development, consider using a tool like `nodemon`: ```bash -npx tsc --watch +npx nodemon src/index.js ``` -### Start the bot in development mode - -```bash -npm run dev -``` - -(Note: add `"dev": "ts-node src/index.ts"` to the npm scripts) - ## 📝 Commands ### `/issue` diff --git a/jsconfig.json b/jsconfig.json index 7284d3b..749fcc5 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -3,7 +3,8 @@ "checkJs": true, "allowJs": true, "target": "ES2022", - "module": "ESNext" + "module": "NodeNext", + "moduleResolution": "nodenext" }, "include": ["src", "test"] } diff --git a/package.json b/package.json index f2a6a81..26c562f 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "NODE_ENV=test node --loader ts-node/esm --test test/*.test.js", - "typecheck": "tsc --noEmit" + "test": "NODE_ENV=test node --test test/*.test.js", + "typecheck": "tsc --noEmit -p jsconfig.json" }, "keywords": [], "author": "", diff --git a/test/index.test.js b/test/index.test.js index bb49558..18393dd 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,7 +1,7 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; process.env.NODE_ENV = 'test'; -import { handleIssueInteraction, handleMessageCreate } from '../src/index.ts'; +import { handleIssueInteraction, handleMessageCreate } from '../src/index.js'; import axios from 'axios'; function createInteraction({ title = 'T', body = 'B' } = {}) { @@ -38,7 +38,7 @@ test('skips if not chat input command', async () => { interaction.isChatInputCommand = () => false; let called = false; const orig = axios.post; - axios.post = async () => { called = true; }; + /** @type {any} */ (axios).post = async () => { called = true; }; await handleIssueInteraction(interaction); axios.post = orig; assert.equal(called, false); @@ -50,7 +50,7 @@ test('skips if command name differs', async () => { interaction.commandName = 'other'; let called = false; const orig = axios.post; - axios.post = async () => { called = true; }; + /** @type {any} */ (axios).post = async () => { called = true; }; await handleIssueInteraction(interaction); axios.post = orig; assert.equal(called, false); @@ -61,9 +61,10 @@ test('creates issue and replies with url', async () => { const interaction = createInteraction({ title: 'hi', body: 'desc' }); process.env.GITHUB_REPO = 'a/b'; process.env.GITHUB_TOKEN = 't'; + /** @type {{url?: string, payload?: any}} */ let received; const orig = axios.post; - axios.post = async (url, payload) => { + /** @type {any} */ (axios).post = async (url, payload) => { received = { url, payload }; return { data: { html_url: 'https://example.com/1' } }; }; @@ -78,7 +79,7 @@ test('creates issue and replies with url', async () => { test('handles axios error', async () => { const interaction = createInteraction(); const orig = axios.post; - axios.post = async () => { throw new Error('fail'); }; + /** @type {any} */ (axios).post = async () => { throw new Error('fail'); }; await handleIssueInteraction(interaction); axios.post = orig; assert.equal(interaction._replies.message, '❌ Fehler beim Erstellen des Issues. Wende dich direkt an Jonas.');