Files
discord.js/packages/core/scripts/check-routes.mts
Vlad Frangu 0c1ff5ea29 types(core): use result types instead of direct types (#11140)
* types(core): use result types instead of direct types

fix: import pains

chore: apply suggestion from review

Co-authored-by: Almeida <github@almeidx.dev>

chore: fmt script

chore: requested change

* chore: rename script, fix build

* chore: types

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2025-10-24 15:36:54 +00:00

37 lines
915 B
TypeScript

import { Routes } from 'discord-api-types/v10';
import { glob, readFile } from 'node:fs/promises';
const usedRoutes = new Set<string>();
const ignoredRoutes = new Set([
// Deprecated
'channelPins',
'channelPin',
'guilds',
'guildCurrentMemberNickname',
'guildMFA',
'nitroStickerPacks',
]);
const cwd = new URL('../src/api/', import.meta.url);
for await (const file of glob('**/*.ts', { cwd })) {
const content = await readFile(new URL(file, cwd), 'utf-8');
const routes = content.matchAll(/Routes\.([\w\d_]+)/g);
for (const route of routes) {
usedRoutes.add(route[1]!);
}
}
const unusedRoutes = Object.keys(Routes).filter((route) => !usedRoutes.has(route) && !ignoredRoutes.has(route));
if (unusedRoutes.length > 0) {
console.warn('The following routes are not implemented:');
for (const route of unusedRoutes) {
console.warn(` - ${route}`);
}
} else {
console.log('No missing routes.');
}