UNPKG

plugify-plugins-types-generator

Version:

tool to generate d.ts for plugify plugins by pplugin file (ESM)

26 lines (24 loc) 1.23 kB
import { plugifyNameConvert, plugifyTypeConvert } from "../plugify/parser.js" import { ExportedMethod, PlugifyType } from "../types/plugify.js" import { NameSpaces } from "./namespace.js" export const plugifyMethodsGenerator = (methods: ExportedMethod[], docsViewer: string, docsToItemURL: string) => { return methods .map( (method) => ` /** * @description ${method.description} * * {@link ${docsViewer}${docsToItemURL}#item-${method.name}|Docs} * * ${method.paramTypes.map(param => `@param ${param.name} ${param.description}`).join("\n * ")} */ export function ${plugifyNameConvert(method.funcName)}(${method.paramTypes .map((param) => `${plugifyNameConvert(param.name)}: ${param.prototype?.name // ? currently namespaces only for callbacks to prevent export them ? `typeof ${NameSpaces.Callbacks}.${param.prototype?.name}` : param.enum?.name || plugifyTypeConvert(param.type as PlugifyType)}`) .join(', ')}): ${method.retType.enum?.name || plugifyTypeConvert(method.retType.type as PlugifyType)};` ) .join('\n') }