in build-scripts/doc-gen/parser.ts [82:140]
export function parse(
programRoot: string, srcRoot: string, repoPath: string, githubRoot: string,
allowedDeclarationFileSubpaths: string[]): RepoDocsAndMetadata {
if (!fs.existsSync(programRoot)) {
throw new Error(
`Program root ${programRoot} does not exist. Please run this script ` +
`from the root of repository.`);
}
const docHeadings: DocHeading[] = [];
// We keep an auxillary map of explicitly marked "subclass" fields on
// @doc to the method entries
const subclassMethodMap: {[subclass: string]: DocFunction[]} = {};
const docTypeAliases: {[type: string]: string} = {};
const docLinkAliases: {[symbolName: string]: string} = {};
const globalSymbolDocMap:
{[symbolName: string]: {docs: string, params: DocFunctionParam[]}} = {};
const configInterfaceParamMap:
{[interfaceName: string]: DocFunctionParam[]} = {};
const inlineTypes: {[typeName: string]: string} = {};
// Use the same compiler options that we use to compile the library
// here.
const tsconfig =
JSON.parse(fs.readFileSync(path.join(repoPath, 'tsconfig.json'), 'utf8'));
delete tsconfig.compilerOptions.moduleResolution;
const program = ts.createProgram([programRoot], tsconfig.compilerOptions);
const checker = program.getTypeChecker();
// Visit all the nodes that are transitively linked from the source
// root.
for (const sourceFile of program.getSourceFiles()) {
if (!sourceFile.isDeclarationFile ||
allowedDeclarationFileSubpaths.some(
allowedPath => sourceFile.fileName.includes(allowedPath))) {
ts.forEachChild(
sourceFile,
node => visitNode(
docHeadings, subclassMethodMap, docTypeAliases, docLinkAliases,
globalSymbolDocMap, configInterfaceParamMap, inlineTypes, checker,
node, sourceFile, srcRoot, repoPath, githubRoot));
}
}
util.replaceUseDocsFromDocStrings(docHeadings, globalSymbolDocMap);
util.addSubclassMethods(docHeadings, subclassMethodMap);
const docs: Docs = {headings: docHeadings};
return {
docs,
docLinkAliases,
configInterfaceParamMap,
inlineTypes,
docTypeAliases
};
}