-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,322 additions
and
2,475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,56 @@ | ||
import * as TypeDoc from "typedoc"; | ||
import { Application, TSConfigReader, TypeDocReader } from "typedoc"; | ||
|
||
import { PluginOptions } from "../../types/package.types"; | ||
import { info } from "../../utils/log.utils"; | ||
|
||
export const parseTypescriptToJson = async ( | ||
packageDocsPath: string, | ||
docsJsonPath: string, | ||
entryPoints: string[], | ||
tsconfig: string, | ||
pluginOptions: PluginOptions, | ||
) => { | ||
// 1. Prepare typedoc application to render | ||
const app = new TypeDoc.Application(); | ||
try { | ||
// 1. Parser options to bootstrap project | ||
const app = await Application.bootstrapWithPlugins({ | ||
excludeExternals: true, | ||
excludeInternal: true, | ||
excludePrivate: true, | ||
excludeProtected: true, | ||
exclude: [ | ||
"node_modules", | ||
"tests", | ||
"__tests__", | ||
"**/*.spec.ts", | ||
"**/*.test.ts", | ||
"**/*.tests.ts", | ||
], | ||
logLevel: "Error", | ||
entryPointStrategy: "expand", | ||
...pluginOptions.typeDocOptions, | ||
plugin: ["typedoc-plugin-markdown", ...(pluginOptions.typeDocOptions?.plugin || [])], | ||
tsconfig, | ||
entryPoints, | ||
}); | ||
|
||
// 2. Prepare parser readers | ||
app.options.addReader(new TypeDoc.TSConfigReader()); | ||
app.options.addReader(new TypeDoc.TypeDocReader()); | ||
// 2. Prepare parser readers | ||
app.options.addReader(new TSConfigReader()); | ||
app.options.addReader(new TypeDocReader()); | ||
|
||
// 3. Parser options to bootstrap project | ||
app.bootstrap({ | ||
excludeExternals: true, | ||
excludeInternal: true, | ||
excludePrivate: true, | ||
excludeProtected: true, | ||
exclude: ["node_modules", "tests", "__tests__", "*.spec.ts", "*.test.ts"], | ||
logLevel: "Error", | ||
entryPointStrategy: "expand", | ||
...pluginOptions.typeDocOptions, | ||
plugin: ["typedoc-plugin-markdown", ...(pluginOptions.typeDocOptions?.plugin || [])], | ||
tsconfig, | ||
entryPoints, | ||
}); | ||
// 3. Parse project | ||
const project = await app.convert(); | ||
|
||
// 4. Generate json output | ||
const project = app.convert(); | ||
if (project) { | ||
await app.generateJson(project, packageDocsPath); | ||
} else { | ||
throw new Error(`Cannot generate docs for dir: ${packageDocsPath}.`); | ||
// 4. Generate json output | ||
if (pluginOptions.watch) { | ||
app.convertAndWatch(async (watchProject) => { | ||
info("Watching for changes..."); | ||
await app.generateJson(watchProject, docsJsonPath); | ||
}); | ||
} else if (project) { | ||
await app.generateJson(project, docsJsonPath); | ||
} else { | ||
throw new Error(`Cannot generate docs for dir: ${docsJsonPath}.`); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; |
Oops, something went wrong.