mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -3,22 +3,22 @@ import { dirname, join, extname, basename, relative } from 'node:path';
|
||||
import jsdoc2md from 'jsdoc-to-markdown';
|
||||
import { type DeclarationReflection, Application, TSConfigReader } from 'typedoc';
|
||||
import type { CLIOptions } from './cli';
|
||||
import { Documentation } from './documentation';
|
||||
import { Documentation } from './documentation.js';
|
||||
import type { RootTypes, ChildTypes, CustomDocs } from './interfaces';
|
||||
|
||||
interface CustomFiles {
|
||||
id?: string;
|
||||
name: string;
|
||||
path?: string;
|
||||
files: {
|
||||
id?: string;
|
||||
name: string;
|
||||
path: string;
|
||||
}[];
|
||||
id?: string;
|
||||
name: string;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export function build({ input, custom: customDocs, root, output, typescript }: CLIOptions) {
|
||||
let data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];
|
||||
let data: (ChildTypes & RootTypes)[] | DeclarationReflection[] = [];
|
||||
if (typescript) {
|
||||
console.log('Parsing Typescript in source files...');
|
||||
const app = new Application();
|
||||
@@ -26,13 +26,14 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
app.bootstrap({ entryPoints: input });
|
||||
const project = app.convert();
|
||||
if (project) {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: Types are lost with this method
|
||||
data = app.serializer.toObject(project).children!;
|
||||
console.log(`${data.length} items parsed.`);
|
||||
}
|
||||
} else {
|
||||
console.log('Parsing JSDocs in source files...');
|
||||
data = jsdoc2md.getTemplateDataSync({ files: input }) as (RootTypes & ChildTypes)[];
|
||||
// eslint-disable-next-line n/no-sync
|
||||
data = jsdoc2md.getTemplateDataSync({ files: input }) as (ChildTypes & RootTypes)[];
|
||||
console.log(`${data.length} JSDoc items parsed.`);
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
if (customDocs) {
|
||||
console.log('Loading custom docs files...');
|
||||
const customDir = dirname(customDocs);
|
||||
const file = readFileSync(customDocs, 'utf-8');
|
||||
const file = readFileSync(customDocs, 'utf8');
|
||||
const data = JSON.parse(file) as CustomFiles[];
|
||||
|
||||
for (const category of data) {
|
||||
@@ -51,23 +52,23 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
files: {},
|
||||
};
|
||||
|
||||
for (const f of category.files) {
|
||||
const fileRootPath = join(dir, f.path);
|
||||
const extension = extname(f.path);
|
||||
const fileId = f.id ?? basename(f.path, extension);
|
||||
const fileData = readFileSync(fileRootPath, 'utf-8');
|
||||
for (const file of category.files) {
|
||||
const fileRootPath = join(dir, file.path);
|
||||
const extension = extname(file.path);
|
||||
const fileId = file.id ?? basename(file.path, extension);
|
||||
const fileData = readFileSync(fileRootPath, 'utf8');
|
||||
custom[categoryId]!.files[fileId] = {
|
||||
name: f.name,
|
||||
name: file.name,
|
||||
type: extension.toLowerCase().replace(/^\./, ''),
|
||||
content: fileData,
|
||||
path: relative(root, fileRootPath).replace(/\\/g, '/'),
|
||||
path: relative(root, fileRootPath).replaceAll('\\', '/'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const fileCount = Object.keys(custom)
|
||||
.map((k) => Object.keys(custom[k]!))
|
||||
.reduce((prev, c) => prev + c.length, 0);
|
||||
.map((key) => Object.keys(custom[key]!))
|
||||
.reduce((prev, content) => prev + content.length, 0);
|
||||
const categoryCount = Object.keys(custom).length;
|
||||
console.log(
|
||||
`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +
|
||||
@@ -82,5 +83,6 @@ export function build({ input, custom: customDocs, root, output, typescript }: C
|
||||
console.log(`Writing to ${output}...`);
|
||||
writeFileSync(output, JSON.stringify(docs.serialize()));
|
||||
}
|
||||
|
||||
console.log('Done!');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user