diff --git a/packages/reciple/src/classes/Config.ts b/packages/reciple/src/classes/Config.ts index b1ac1b03..a2599ee7 100644 --- a/packages/reciple/src/classes/Config.ts +++ b/packages/reciple/src/classes/Config.ts @@ -36,10 +36,20 @@ export interface RecipleConfigJS { export class ConfigReader { public static defaultConfigFile = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../static/config.mjs'); + /** + * Reads the default configuration data, processes it, and returns the resulting configuration string. + * + * @return {Promise} The default configuration data as a string. + */ public static async readDefaultConfig(): Promise { return recursiveDefaults(await import(this.defaultConfigFile))!; } + /** + * Reads the default configuration data, processes it, and returns the resulting configuration string. + * + * @return {Promise} The default configuration data as a string. + */ public static async getDefaultConfigData(): Promise { let defaultConfig = (await readFile(this.defaultConfigFile, 'utf-8')).replaceAll('\r\n', '\n'); @@ -51,6 +61,15 @@ export class ConfigReader { public static async readConfigJS(config: string|{ paths: string[]; default?: string; }, createIfNotExists?: true): Promise; public static async readConfigJS(config: string|{ paths: string[]; default?: string; }, createIfNotExists?: false): Promise; + /** + * Reads a JavaScript configuration file and returns its contents as a `RecipleConfigJS` object. + * If the file does not exist, it can optionally create the file and return a default configuration. + * + * @param {string|{ paths: string[]; default?: string; }} config - The path to the configuration file or an object specifying multiple paths and a default path. + * @param {boolean} [createIfNotExists=true] - Whether to create the configuration file if it does not exist. + * @return {Promise} A promise that resolves to the contents of the configuration file as a `RecipleConfigJS` object, or `null` if the file does not exist and `createIfNotExists` is `false`. + * @throws {RecipleError} If the configuration file does not contain valid data. + */ public static async readConfigJS(config: string|{ paths: string[]; default?: string; }, createIfNotExists: boolean = true): Promise { if (typeof config !== 'string') { let data: RecipleConfigJS|null = null; @@ -78,6 +97,12 @@ export class ConfigReader { return data; } + /** + * Creates a configuration file if it doesn't exist and returns the file path. + * + * @param {string} file - The path to the configuration file. + * @return {Promise} The path of the created or existing configuration file. + */ public static async createConfigJS(file: string): Promise { if (await existsAsync(file)) return file; diff --git a/packages/reciple/src/utils/logger.ts b/packages/reciple/src/utils/logger.ts index 2efb4cc8..78c16fe4 100644 --- a/packages/reciple/src/utils/logger.ts +++ b/packages/reciple/src/utils/logger.ts @@ -4,6 +4,15 @@ import { type RecipleClient } from '../index.js'; import { cli } from './cli.js'; import path from 'node:path'; +/** + * Formats a log message with optional prefix, colored messages, and thread information. + * + * @param {string} message - The log message to format. + * @param {Logger} logger - The logger instance used to get the logger name. + * @param {PartialDeep> & { shards?: boolean; }} config - The logger configuration. + * @param {LoggerLevel} level - The log level. + * @return {string} The formatted log message. + */ export function formatLogMessage(message: string, logger: Logger, config: PartialDeep> & { shards?: boolean; }, level: LoggerLevel): string { const color = (msg: string) => { if (!config.coloredMessages || level === LoggerLevel.INFO) return msg; @@ -30,6 +39,12 @@ export function formatLogMessage(message: string, logger: Logger, config: Partia ) + ` ${message}`; } +/** + * Creates a logger with the specified configuration. + * + * @param {Omit>, 'enabled'> & { shards?: boolean; }} config - The configuration for the logger. + * @return {Promise} The created logger instance. + */ export async function createLogger(config?: Omit>, 'enabled'> & { shards?: boolean; }): Promise { const logger = new Logger({ enableDebugmode: (cli.options.debugmode || config?.debugmode) ?? null, @@ -55,6 +70,12 @@ export async function createLogger(config?: Omit client.logger?.debug(debug)); diff --git a/packages/reciple/src/utils/modules.ts b/packages/reciple/src/utils/modules.ts index 15de1be4..663c2aa2 100644 --- a/packages/reciple/src/utils/modules.ts +++ b/packages/reciple/src/utils/modules.ts @@ -5,6 +5,13 @@ import { existsAsync } from '@reciple/utils'; import micromatch from 'micromatch'; import path from 'node:path'; +/** + * Recursively finds modules in specified directories based on the given configuration. + * + * @param {RecipleConfig['modules']} config - The configuration object containing directories and filters. + * @param {((filename: string) => Awaitable)?} filter - An optional function to filter files. + * @return {Promise} A promise that resolves to an array of module file paths. + */ export async function findModules(config: RecipleConfig['modules'], filter?: (filename: string) => Awaitable): Promise { const modules: string[] = []; const { globby, isDynamicPattern } = await import('globby'); diff --git a/packages/utils/src/classes/PackageUpdateChecker.ts b/packages/utils/src/classes/PackageUpdateChecker.ts index 27553381..b5c70ab8 100644 --- a/packages/utils/src/classes/PackageUpdateChecker.ts +++ b/packages/utils/src/classes/PackageUpdateChecker.ts @@ -46,6 +46,11 @@ export class PackageUpdateChecker extends StrictTypedEmitter = new Collection(); public interval?: NodeJS.Timeout; + /** + * Initializes a new instance of the PackageUpdateChecker class. + * + * @param {PackageUpdateCheckerOptions} options - The options for initializing the class. + */ constructor(options: PackageUpdateCheckerOptions) { super(); @@ -56,6 +61,12 @@ export class PackageUpdateChecker extends StrictTypedEmitter this.checkForAvailableUpdates(), ms).unref(); } + /** + * Stops the interval for checking for available updates. + * + * @return {void} + */ public stopCheckInterval(): void { this.startCheckInterval(0); } + /** + * Asynchronously checks for available updates for each package in the `packages` collection. + * + * @return {Promise} A promise that resolves to an array of `PackageUpdateCheckerUpdateData` objects representing the available updates for each package. + */ public async checkForAvailableUpdates(): Promise { const packageUpdates: PackageUpdateCheckerUpdateData[] = []; @@ -87,6 +108,15 @@ export class PackageUpdateChecker extends StrictTypedEmitter} A promise that resolves to an object containing information about the latest update, including the package name, data, current version, updated version, latest version, and update type. + * @throws {Error} If no version of the package satisfies the given version constraint. + */ public static async checkLatestUpdate(pkg: string, version: string, allowMajor: boolean = false): Promise { const currentSemver = new SemVer(version); @@ -117,6 +147,13 @@ export class PackageUpdateChecker extends StrictTypedEmitter(pkg: string, options?: Options): Promise; public static async fetchPackageData(pkg: string, options?: FullMetadata): Promise; + /** + * Asynchronously fetches package data for the given package name. + * + * @param {string} pkg - The name of the package to fetch data for. + * @param {FullMetadata|Options} [options] - Optional options for fetching package data. + * @return {Promise} A promise that resolves to the fetched package data. + */ public static async fetchPackageData(pkg: string, options?: FullMetadata|Options): Promise { return packageJson(pkg, { ...options, allVersions: true }) as Promise; }