docusaurus-plugin-typedoc
Advanced tools
| import { PluginOptions } from '../models.js'; | ||
| export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): Promise<{ | ||
| name: string; | ||
| extendCli(cli: any): void; | ||
| }>; |
| import * as fs from 'fs'; | ||
| import { getPluginOptions } from '../options/options.js'; | ||
| import { writeSidebar } from './sidebar.js'; | ||
| export default async function pluginDocusaurus(context, opts) { | ||
| await generateTypedoc(context, opts); | ||
| return { | ||
| name: 'docusaurus-plugin-typedoc', | ||
| extendCli(cli) { | ||
| cli | ||
| .command('generate-typedoc') | ||
| .description(`[docusaurus-plugin-typedoc] Generate TypeDoc docs independently of the Docusaurus build process.`) | ||
| .action(async () => { | ||
| context.siteConfig?.plugins.forEach((pluginConfig) => { | ||
| // Check PluginConfig is typed to [string, PluginOptions] | ||
| if (pluginConfig && typeof pluginConfig[1] === 'object') { | ||
| generateTypedoc(context, pluginConfig[1]); | ||
| } | ||
| }); | ||
| }); | ||
| }, | ||
| }; | ||
| } | ||
| /** | ||
| * Initiates a new typedoc Application bootstrapped with plugin options | ||
| */ | ||
| async function generateTypedoc(context, opts) { | ||
| // get plugin options | ||
| const options = getPluginOptions(context, opts); | ||
| // create outDir if it doesn't exist | ||
| if (!fs.existsSync(options.out)) { | ||
| fs.mkdirSync(options.out, { recursive: true }); | ||
| } | ||
| // configure options for typedoc | ||
| const { | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| id, siteDir, numberPrefixParser, docsPresetPath, sidebar, ...optionsPassedToTypeDoc } = options; | ||
| const typeDocApp = await import('./typedoc.cjs'); | ||
| // bootstrap typedoc with options | ||
| await typeDocApp.bootstrap(optionsPassedToTypeDoc, async (renderer) => { | ||
| writeSidebar(renderer.navigation, renderer.outputDirectory, sidebar, siteDir, docsPresetPath, numberPrefixParser); | ||
| }); | ||
| } |
| import { NavigationItem } from 'typedoc-plugin-markdown'; | ||
| import { Sidebar } from '../types/options.js'; | ||
| export declare function writeSidebar(navigation: NavigationItem[], outputDir: string, sidebar: Sidebar, siteDir: string, docsPresetPath: string, numberPrefixParser: any): void; |
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import { adjustBaseDirectory } from '../utils/adjust-basedir.js'; | ||
| export function writeSidebar(navigation, outputDir, sidebar, siteDir, docsPresetPath, numberPrefixParser) { | ||
| if (sidebar?.autoConfiguration) { | ||
| const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs'); | ||
| let baseDir = path | ||
| .relative(siteDir, outputDir) | ||
| .split(path.sep) | ||
| .slice(1) | ||
| .join('/'); | ||
| if (docsPresetPath) { | ||
| baseDir = adjustBaseDirectory(baseDir, docsPresetPath); | ||
| } | ||
| const sidebarJson = getSidebar(navigation, baseDir, sidebar, numberPrefixParser); | ||
| fs.writeFileSync(sidebarPath, `// @ts-check | ||
| /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ | ||
| const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}}; | ||
| module.exports = typedocSidebar.items;`); | ||
| } | ||
| } | ||
| function getSidebar(navigation, basePath, options, numberPrefixParser) { | ||
| return navigation | ||
| .map((navigationItem) => getNavigationItem(navigationItem, basePath, options, numberPrefixParser)) | ||
| .filter((navItem) => Boolean(navItem)); | ||
| } | ||
| function getNavigationItem(navigationItem, basePath, options, numberPrefixParser) { | ||
| const navigationItemPath = navigationItem.path || navigationItem.url; | ||
| const parsedUrl = numberPrefixParser === false | ||
| ? navigationItemPath | ||
| : navigationItemPath?.replace(/\d+-/g, ''); | ||
| const getId = () => { | ||
| const idParts = []; | ||
| if (basePath.length > 0) { | ||
| idParts.push(basePath); | ||
| } | ||
| if (parsedUrl) { | ||
| idParts.push(parsedUrl.replace(/\\/g, '/')); | ||
| } | ||
| if (navigationItemPath) { | ||
| return idParts.join('/').replace(/(.*)\.\w+$/, '$1'); | ||
| } | ||
| return null; | ||
| }; | ||
| const id = getId(); | ||
| if (navigationItem.children?.length) { | ||
| return { | ||
| type: 'category', | ||
| label: navigationItem.title, | ||
| items: getSidebar(navigationItem.children, basePath, options, numberPrefixParser), | ||
| ...(id && { | ||
| link: { | ||
| type: 'doc', | ||
| id, | ||
| }, | ||
| }), | ||
| }; | ||
| } | ||
| return id | ||
| ? { | ||
| type: 'doc', | ||
| id, | ||
| label: navigationItem.title, | ||
| ...(navigationItem.isDeprecated && { | ||
| className: options.deprecatedItemClassName, | ||
| }), | ||
| } | ||
| : null; | ||
| } |
| /** | ||
| * Export as cjs to be compatible with esm | ||
| */ | ||
| module.exports = { | ||
| bootstrap: async (options, postRenderCallbackFn) => { | ||
| const typedoc = await import('typedoc'); | ||
| const app = await typedoc.Application.bootstrapWithPlugins(options, [ | ||
| new typedoc.TypeDocReader(), | ||
| new typedoc.PackageJsonReader(), | ||
| new typedoc.TSConfigReader(), | ||
| ]); | ||
| app.renderer.postRenderAsyncJobs.push(postRenderCallbackFn); | ||
| const project = await app.convert(); | ||
| // if project is undefined typedoc has a problem - error logging will be supplied by typedoc. | ||
| if (!project) { | ||
| return; | ||
| } | ||
| if (options.watch) { | ||
| app.convertAndWatch(async (project) => { | ||
| await app.generateOutputs(project); | ||
| }); | ||
| } else { | ||
| await app.generateOutputs(project); | ||
| } | ||
| }, | ||
| }; |
+1
-1
@@ -5,2 +5,2 @@ /** | ||
| export { PluginOptions } from './models.js'; | ||
| export { default } from './plugins/docusaurus.js'; | ||
| export { default } from './plugin/docusaurus.js'; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export { default } from './plugins/docusaurus.js'; | ||
| export { default } from './plugin/docusaurus.js'; |
| import { DeclarationOption } from 'typedoc'; | ||
| /** | ||
| * Used internally to pass options from docusaurus.config to TypeDoc. | ||
| * | ||
| * @internal | ||
| * | ||
| * @hidden | ||
| */ | ||
| export declare const docusaurusConfigOptions: Partial<DeclarationOption>; | ||
| /** | ||
| * **autoConfiguration** | ||
@@ -12,0 +4,0 @@ * |
| import { ParameterType } from 'typedoc'; | ||
| import { DEFAULT_SIDEBAR_OPTIONS } from './options.js'; | ||
| /** | ||
| * Used internally to pass options from docusaurus.config to TypeDoc. | ||
| * | ||
| * @internal | ||
| * | ||
| * @hidden | ||
| */ | ||
| export const docusaurusConfigOptions = { | ||
| help: 'docusaurus.config options - should not be used if running as a docusaurus plugin.', | ||
| type: ParameterType.String, | ||
| defaultValue: '{}', | ||
| }; | ||
| /** | ||
| * **autoConfiguration** | ||
@@ -17,0 +5,0 @@ * |
@@ -29,6 +29,3 @@ import { presets } from './presets.js'; | ||
| plugin: [ | ||
| ...new Set([ | ||
| ...['typedoc-plugin-markdown', 'docusaurus-plugin-typedoc/typedoc'], | ||
| ...(opts.plugin || []), | ||
| ]), | ||
| ...new Set([...['typedoc-plugin-markdown'], ...(opts.plugin || [])]), | ||
| ], | ||
@@ -35,0 +32,0 @@ }; |
+5
-6
| { | ||
| "name": "docusaurus-plugin-typedoc", | ||
| "version": "1.2.2", | ||
| "version": "1.2.3", | ||
| "description": "A Docusaurus plugin to integrate TypeDoc ( + typedoc-plugin-markdown ) into a Docusaurus project.", | ||
| "exports": { | ||
| ".": "./dist/index.js", | ||
| "./typedoc": "./dist/plugins/typedoc.js" | ||
| ".": "./dist/index.js" | ||
| }, | ||
@@ -27,3 +26,3 @@ "type": "module", | ||
| "lint": "eslint ./src", | ||
| "prebuild": "rm -rf dist && prebuild-options", | ||
| "prebuild": "rm -rf dist && copyfiles --up 1 ./src/**/*.cjs ./dist/", | ||
| "prepublishOnly": "npm run lint && npm run build", | ||
@@ -43,5 +42,5 @@ "build": "tsc", | ||
| "devDependencies": { | ||
| "@docusaurus/core": "^3.6.1", | ||
| "@docusaurus/types": "^3.6.1" | ||
| "@docusaurus/core": "^3.7.0", | ||
| "@docusaurus/types": "^3.7.0" | ||
| } | ||
| } |
| import { PluginOptions } from '../models.js'; | ||
| export default function pluginDocusaurus(context: any, opts: Partial<PluginOptions>): Promise<{ | ||
| name: string; | ||
| extendCli(cli: any): void; | ||
| }>; |
| import { spawnSync } from 'child_process'; | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import { getPluginOptions } from '../options/options.js'; | ||
| import { presets } from '../options/presets.js'; | ||
| export default async function pluginDocusaurus(context, opts) { | ||
| await generateTypedoc(context, opts); | ||
| return { | ||
| name: 'docusaurus-plugin-typedoc', | ||
| extendCli(cli) { | ||
| cli | ||
| .command('generate-typedoc') | ||
| .description(`[docusaurus-plugin-typedoc] Generate TypeDoc docs independently of the Docusaurus build process.`) | ||
| .action(async () => { | ||
| context.siteConfig?.plugins.forEach((pluginConfig) => { | ||
| // Check PluginConfig is typed to [string, PluginOptions] | ||
| if (pluginConfig && typeof pluginConfig[1] === 'object') { | ||
| generateTypedoc(context, pluginConfig[1]); | ||
| } | ||
| }); | ||
| }); | ||
| }, | ||
| }; | ||
| } | ||
| /** | ||
| * Initiates a new typedoc Application bootstrapped with plugin options | ||
| */ | ||
| async function generateTypedoc(context, opts) { | ||
| // create outDir if it doesn't exist | ||
| const outputDir = path.join(context?.siteDir, presets.out); | ||
| if (!fs.existsSync(outputDir)) { | ||
| fs.mkdirSync(outputDir, { recursive: true }); | ||
| } | ||
| const { plugin, ...options } = getPluginOptions(context, opts); | ||
| // spawn typedoc process and pass docusaurus.config options as a string | ||
| const typedocExecutable = process.platform === 'win32' ? 'typedoc.cmd' : 'typedoc'; | ||
| spawnSync(typedocExecutable, [ | ||
| ...plugin.flatMap((plugin) => ['--plugin', plugin]), | ||
| '--docusaurusConfigOptions', | ||
| `${JSON.stringify(options)}`, | ||
| ], { | ||
| stdio: 'inherit', | ||
| }); | ||
| } |
| import { MarkdownApplication } from 'typedoc-plugin-markdown'; | ||
| export declare function load(app: MarkdownApplication): void; |
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| import * as options from '../options/declarations.js'; | ||
| import { adjustBaseDirectory } from '../utils/adjust-basedir.js'; | ||
| import { getSidebar } from '../utils/get-sidebar.js'; | ||
| export function load(app) { | ||
| Object.entries(options).forEach(([name, option]) => { | ||
| app.options.addDeclaration({ | ||
| name, | ||
| ...option, | ||
| }); | ||
| }); | ||
| app.options.addReader(new (class { | ||
| name = 'docusaurus-options'; | ||
| order = 100; | ||
| supportsPackages = false; | ||
| read(container) { | ||
| const presets = JSON.parse(container.getValue('docusaurusConfigOptions')); | ||
| const ignoreKeys = [ | ||
| 'id', | ||
| 'siteDir', | ||
| 'docsPresetPath', | ||
| 'numberPrefixParser', | ||
| ]; | ||
| Object.entries(presets) | ||
| .filter(([key]) => !ignoreKeys.includes(key)) | ||
| .forEach(([key, value]) => { | ||
| container.setValue(key, value); | ||
| }); | ||
| } | ||
| })()); | ||
| app.renderer.postRenderAsyncJobs.push(async (output) => { | ||
| const outputDir = app.options.getValue('out'); | ||
| const docusaurusConfigOptions = JSON.parse(app.options.getValue('docusaurusConfigOptions')); | ||
| const sidebar = app.options.getValue('sidebar'); | ||
| const siteDir = docusaurusConfigOptions.siteDir; | ||
| const docsPresetPath = docusaurusConfigOptions.docsPresetPath; | ||
| const numberPrefixParser = docusaurusConfigOptions.numberPrefixParser; | ||
| if (sidebar?.autoConfiguration && output.navigation) { | ||
| const sidebarPath = path.resolve(outputDir, 'typedoc-sidebar.cjs'); | ||
| let baseDir = path | ||
| .relative(siteDir, outputDir) | ||
| .split(path.sep) | ||
| .slice(1) | ||
| .join('/'); | ||
| if (docsPresetPath) { | ||
| baseDir = adjustBaseDirectory(baseDir, docsPresetPath); | ||
| } | ||
| const sidebarJson = getSidebar(output.navigation, baseDir, sidebar, numberPrefixParser); | ||
| fs.writeFileSync(sidebarPath, `// @ts-check | ||
| /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ | ||
| const typedocSidebar = { items: ${JSON.stringify(sidebarJson, null, sidebar.pretty ? 2 : 0)}}; | ||
| module.exports = typedocSidebar.items;`); | ||
| } | ||
| }); | ||
| } |
| import { NavigationItem } from 'typedoc-plugin-markdown'; | ||
| import { Sidebar } from '../types/options.js'; | ||
| export declare function getSidebar(navigation: NavigationItem[], basePath: string, options: Sidebar, numberPrefixParser?: any): any; |
| export function getSidebar(navigation, basePath, options, numberPrefixParser) { | ||
| return navigation | ||
| .map((navigationItem) => getNavigationItem(navigationItem, basePath, options, numberPrefixParser)) | ||
| .filter((navItem) => Boolean(navItem)); | ||
| } | ||
| function getNavigationItem(navigationItem, basePath, options, numberPrefixParser) { | ||
| const navigationItemPath = navigationItem.path || navigationItem.url; | ||
| const parsedUrl = numberPrefixParser === false | ||
| ? navigationItemPath | ||
| : navigationItemPath?.replace(/\d+-/g, ''); | ||
| const getId = () => { | ||
| const idParts = []; | ||
| if (basePath.length > 0) { | ||
| idParts.push(basePath); | ||
| } | ||
| if (parsedUrl) { | ||
| idParts.push(parsedUrl.replace(/\\/g, '/')); | ||
| } | ||
| if (navigationItemPath) { | ||
| return idParts.join('/').replace(/(.*)\.\w+$/, '$1'); | ||
| } | ||
| return null; | ||
| }; | ||
| const id = getId(); | ||
| if (navigationItem.children?.length) { | ||
| return { | ||
| type: 'category', | ||
| label: navigationItem.title, | ||
| items: getSidebar(navigationItem.children, basePath, options, numberPrefixParser), | ||
| ...(id && { | ||
| link: { | ||
| type: 'doc', | ||
| id, | ||
| }, | ||
| }), | ||
| }; | ||
| } | ||
| return id | ||
| ? { | ||
| type: 'doc', | ||
| id, | ||
| label: navigationItem.title, | ||
| ...(navigationItem.isDeprecated && { | ||
| className: options.deprecatedItemClassName, | ||
| }), | ||
| } | ||
| : null; | ||
| } |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
-100%13848
-8.33%25
-3.85%338
-9.63%