import { Package } from 'dgeni' ; import { Host } from 'dgeni-packages/typescript/services/ts-host/host' ; import { HighlightNunjucksExtension } from './nunjucks-tags/highlight' ; import { patchLogService } from './patch-log-service' ; import { DocsPrivateFilter } from './processors/docs-private-filter' ; import { Categorizer } from './processors/categorizer' ; import { FilterDuplicateExports } from './processors/filter-duplicate-exports' ; import { MergeInheritedProperties } from './processors/merge-inherited-properties' ; import { EntryPointGrouper } from './processors/entry-point-grouper' ; import { ReadTypeScriptModules } from 'dgeni-packages/typescript/processors/readTypeScriptModules' ; import { TsParser } from 'dgeni-packages/typescript/services/TsParser' ; import { TypeFormatFlags } from 'dgeni-packages/node_modules/typescript' ; import { sync as globSync } from 'glob' ; import * as path from 'path' ; const jsdocPackage = require ( 'dgeni-packages/jsdoc' ) ; const nunjucksPackage = require ( 'dgeni-packages/nunjucks' ) ; const typescriptPackage = require ( 'dgeni-packages/typescript' ) ; const projectRootDir = path . resolve ( __dirname , '../..' ) ; const sourceDir = path . resolve ( projectRootDir , 'src' ) ; const outputDir = path . resolve ( projectRootDir , 'dist/docs/api' ) ; const templateDir = path . resolve ( __dirname , './templates' ) ; /** List of CDK packages that need to be documented. */ const cdkPackages = globSync ( path . join ( sourceDir , 'cdk' , '*/' ) ) . filter ( packagePath => ! packagePath . endsWith ( 'testing/' ) ) . map ( packagePath => path . basename ( packagePath ) ) ; /** List of Material packages that need to be documented. */ const materialPackages = globSync ( path . join ( sourceDir , 'lib' , '*/' ) ) . map ( packagePath => path . basename ( packagePath ) ) ; /**
 * Dgeni package for the Angular Material docs. This just defines the package, but doesn't
 * generate the docs yet.
 *
 * Dgeni packages are very similar to AngularJS modules. Those can contain:
 *
 *  - Services that can be injected
 *  - Templates that are used to convert the data into HTML output.
 *  - Processors that can modify the doc items (like a build pipeline).
 *
 * Similar to AngularJS, there is also a `config` lifecycle hook, that can be used to
 * configure specific processors, services before the procession begins.
 */ export const apiDocsPackage = new Package ( 'material2-api-docs' , [ jsdocPackage , nunjucksPackage , typescriptPackage , ] ) ; apiDocsPackage . processor ( new FilterDuplicateExports ( ) ) ; apiDocsPackage . processor ( new MergeInheritedProperties ( ) ) ; apiDocsPackage . processor ( new DocsPrivateFilter ( ) ) ; apiDocsPackage . processor ( new Categorizer ( ) ) ; apiDocsPackage . processor ( new EntryPointGrouper ( ) ) ; apiDocsPackage . config ( ( log ) => log . level = 'info' ) ; apiDocsPackage . config ( ( readFilesProcessor , writeFilesProcessor ) => { readFilesProcessor . basePath = sourceDir ; readFilesProcessor . $enabled = false ; writeFilesProcessor . outputFolder = outputDir ; } ) ; apiDocsPackage . config ( ( log ) => patchLogService ( log ) ) ; apiDocsPackage . config ( ( computePathsProcessor ) => { computePathsProcessor . pathTemplates = [ { docTypes : [ 'entry-point' ] , pathTemplate : '${name}' , outputPathTemplate : '${name}.html' , } ] ; } ) ; apiDocsPackage . config ( ( parseTagsProcessor ) => { parseTagsProcessor . tagDefinitions = parseTagsProcessor . tagDefinitions . concat ( [ { name : 'docs-private' } , { name : 'breaking-change' } ] ) ; } ) ; apiDocsPackage . config ( ( checkAnchorLinksProcessor ) => { checkAnchorLinksProcessor . ignoredLinks . push ( /(components|cdk)\/[\w-]+\/api#\w+/ ) ; } ) ; apiDocsPackage . config ( ( readTypeScriptModules , tsParser ) => { readTypeScriptModules . basePath = sourceDir ; readTypeScriptModules . ignoreExportsMatching = [ /^_/ ] ; readTypeScriptModules . hidePrivateMembers = true ; const typescriptPathMap = { } ; cdkPackages . forEach ( packageName => { typescriptPathMap [ `@angular/cdk/${ packageName }` ] = [ `./cdk/${ packageName }/index.ts` ] ; } ) ; materialPackages . forEach ( packageName => { typescriptPathMap [ `@angular/material/${ packageName }` ] = [ `./lib/${ packageName }/index.ts` ] ; } ) ; tsParser . options . paths = typescriptPathMap ; tsParser . options . baseUrl = sourceDir ; readTypeScriptModules . sourceFiles = [ ... cdkPackages . map ( packageName => `./cdk/${ packageName }/index.ts` ) , ... materialPackages . map ( packageName => `./lib/${ packageName }/index.ts` ) ] ; } ) ; apiDocsPackage . config ( ( tsHost ) => { tsHost . concatMultipleLeadingComments = false ; tsHost . typeFormatFlags = TypeFormatFlags . NoTruncation ; } ) ; apiDocsPackage . config ( ( templateFinder , templateEngine ) => { templateFinder . templateFolders = [ templateDir ] ; templateFinder . templatePatterns = [ '${ doc.template }' , '${ doc.id }.${ doc.docType }.template.html' , '${ doc.id }.template.html' , '${ doc.docType }.template.html' , '${ doc.id }.${ doc.docType }.template.js' , '${ doc.id }.template.js' , '${ doc.docType }.template.js' , '${ doc.id }.${ doc.docType }.template.json' , '${ doc.id }.template.json' , '${ doc.docType }.template.json' , 'common.template.html' ] ; templateEngine . config . autoescape = true ; templateEngine . config . tags = { variableStart : '{$' , variableEnd : '$}' } ; templateEngine . tags . push ( new HighlightNunjucksExtension ( ) ) ; } ) ;