{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join, extname, basename, relative } from 'node:path';\nimport jsdoc2md from 'jsdoc-to-markdown';\nimport { type DeclarationReflection, Application, TSConfigReader } from 'typedoc';\nimport type { CLIOptions } from './cli';\nimport { Documentation } from './documentation';\nimport type { RootTypes, ChildTypes, CustomDocs } from './interfaces';\n\ninterface CustomFiles {\n\tid?: string;\n\tname: string;\n\tpath?: string;\n\tfiles: {\n\t\tid?: string;\n\t\tname: string;\n\t\tpath: string;\n\t}[];\n}\n\nexport function build({ input, custom: customDocs, root, output, typescript }: CLIOptions) {\n\tlet data: (RootTypes & ChildTypes)[] | DeclarationReflection[] = [];\n\tif (typescript) {\n\t\tconsole.log('Parsing Typescript in source files...');\n\t\tconst app = new Application();\n\t\tapp.options.addReader(new TSConfigReader());\n\t\tapp.bootstrap({ entryPoints: input });\n\t\tconst project = app.convert();\n\t\tif (project) {\n\t\t\t// @ts-expect-error\n\t\t\tdata = app.serializer.toObject(project).children!;\n\t\t\tconsole.log(`${data.length} items parsed.`);\n\t\t}\n\t} else {\n\t\tconsole.log('Parsing JSDocs in source files...');\n\t\tdata = jsdoc2md.getTemplateDataSync({ files: input }) as (RootTypes & ChildTypes)[];\n\t\tconsole.log(`${data.length} JSDoc items parsed.`);\n\t}\n\n\tconst custom: Record<string, CustomDocs> = {};\n\tif (customDocs) {\n\t\tconsole.log('Loading custom docs files...');\n\t\tconst customDir = dirname(customDocs);\n\t\tconst file = readFileSync(customDocs, 'utf-8');\n\t\tconst data = JSON.parse(file) as CustomFiles[];\n\n\t\tfor (const category of data) {\n\t\t\tconst categoryId = category.id ?? category.name.toLowerCase();\n\t\t\tconst dir = join(customDir, category.path ?? categoryId);\n\t\t\tcustom[categoryId] = {\n\t\t\t\tname: category.name || category.id!,\n\t\t\t\tfiles: {},\n\t\t\t};\n\n\t\t\tfor (const f of category.files) {\n\t\t\t\tconst fileRootPath = join(dir, f.path);\n\t\t\t\tconst extension = extname(f.path);\n\t\t\t\tconst fileId = f.id ?? basename(f.path, extension);\n\t\t\t\tconst fileData = readFileSync(fileRootPath, 'utf-8');\n\t\t\t\tcustom[categoryId]!.files[fileId] = {\n\t\t\t\t\tname: f.name,\n\t\t\t\t\ttype: extension.toLowerCase().replace(/^\\./, ''),\n\t\t\t\t\tcontent: fileData,\n\t\t\t\t\tpath: relative(root, fileRootPath).replace(/\\\\/g, '/'),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst fileCount = Object.keys(custom)\n\t\t\t.map((k) => Object.keys(custom[k]!))\n\t\t\t.reduce((prev, c) => prev + c.length, 0);\n\t\tconst categoryCount = Object.keys(custom).length;\n\t\tconsole.log(\n\t\t\t`${fileCount} custom docs file${fileCount === 1 ? '' : 's'} in ` +\n\t\t\t\t`${categoryCount} categor${categoryCount === 1 ? 'y' : 'ies'} loaded.`,\n\t\t);\n\t}\n\n\tconsole.log(`Serializing documentation with format version ${Documentation.FORMAT_VERSION}...`);\n\tconst docs = new Documentation(data, { input, custom: customDocs, root, output, typescript }, custom);\n\n\tif (output) {\n\t\tconsole.log(`Writing to ${output}...`);\n\t\twriteFileSync(output, JSON.stringify(docs.serialize()));\n\t}\n\tconsole.log('Done!');\n}\n"],"names":["L","J","b","h","C","j","w","F","R","$"],"mappings":";;;;;;AAAmS,SAAS,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAIA,WAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,IAAIC,cAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CA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