|
| 1 | +const path = require('path'); |
| 2 | +const fs = require('fs'); |
| 3 | +const Dgeni = require('dgeni'); |
| 4 | +const DgeniPackage = Dgeni.Package; |
| 5 | + |
| 6 | +// dgeni packages |
| 7 | +const jsdocPackage = require('dgeni-packages/jsdoc'); |
| 8 | +const nunjucksPackage = require('dgeni-packages/nunjucks'); |
| 9 | +const typescriptPackage = require('dgeni-packages/typescript'); |
| 10 | + |
| 11 | + |
| 12 | +// Project configuration. |
| 13 | +const projectRootDir = path.resolve(__dirname, '../..'); |
| 14 | +const sourceDir = path.resolve(projectRootDir, 'src/lib'); |
| 15 | +const outputDir = path.resolve(projectRootDir, 'dist/docs'); |
| 16 | +const templateDir = path.resolve(__dirname, './templates'); |
| 17 | + |
| 18 | +// Package definition for material2 api docs. This only *defines* the package- it does not yet |
| 19 | +// actually *run* anything. |
| 20 | +// |
| 21 | +// A dgeni package is very similar to an Angular 1 module. Modules contain: |
| 22 | +// "services" (injectables) |
| 23 | +// "processors" (injectables that conform to a specific interface) |
| 24 | +// "templates": nunjucks templates that can be used to render content |
| 25 | +// |
| 26 | +// A dgeni package also has a `config` method, similar to an Angular 1 module. |
| 27 | +// A config block can inject any services/processors and configure them before |
| 28 | +// docs processing begins. |
| 29 | + |
| 30 | +const dgeniPackageDeps = [ |
| 31 | + jsdocPackage, |
| 32 | + nunjucksPackage, |
| 33 | + typescriptPackage, |
| 34 | +]; |
| 35 | + |
| 36 | +let apiDocsPackage = new DgeniPackage('material2-api-docs', dgeniPackageDeps) |
| 37 | + |
| 38 | +// Processor that filters out symbols that should not be shown in the docs. |
| 39 | +.processor(require('./processors/docs-private-filter')) |
| 40 | + |
| 41 | +// Processor that appends categorization flags to the docs, e.g. `isDirective`, `isNgModule`, etc. |
| 42 | +.processor(require('./processors/categorizer')) |
| 43 | + |
| 44 | +// Processor to group components into top-level groups such as "Tabs", "Sidenav", etc. |
| 45 | +.processor(require('./processors/component-grouper')) |
| 46 | + |
| 47 | +.config(function(log) { |
| 48 | + log.level = 'info'; |
| 49 | +}) |
| 50 | + |
| 51 | +// Configure the processor for reading files from the file system. |
| 52 | +.config(function(readFilesProcessor, writeFilesProcessor) { |
| 53 | + readFilesProcessor.basePath = sourceDir; |
| 54 | + readFilesProcessor.$enabled = false; // disable for now as we are using readTypeScriptModules |
| 55 | + |
| 56 | + writeFilesProcessor.outputFolder = outputDir; |
| 57 | +}) |
| 58 | + |
| 59 | +// Configure the output path for written files (i.e., file names). |
| 60 | +.config(function(computePathsProcessor) { |
| 61 | + computePathsProcessor.pathTemplates = [{ |
| 62 | + docTypes: ['componentGroup'], |
| 63 | + pathTemplate: '${name}', |
| 64 | + outputPathTemplate: '${name}.html', |
| 65 | + }]; |
| 66 | +}) |
| 67 | + |
| 68 | +// Configure custom JsDoc tags. |
| 69 | +.config(function(parseTagsProcessor) { |
| 70 | + parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions.concat([ |
| 71 | + {name: 'docs-private'} |
| 72 | + ]); |
| 73 | +}) |
| 74 | + |
| 75 | +// Configure the processor for understanding TypeScript. |
| 76 | +.config(function(readTypeScriptModules) { |
| 77 | + console.log(sourceDir); |
| 78 | + readTypeScriptModules.basePath = sourceDir; |
| 79 | + readTypeScriptModules.ignoreExportsMatching = [/^_/]; |
| 80 | + readTypeScriptModules.hidePrivateMembers = true; |
| 81 | + |
| 82 | + // Entry points for docs generation. All publically exported symbols found through these |
| 83 | + // files will have docs generated. |
| 84 | + readTypeScriptModules.sourceFiles = [ |
| 85 | + 'autocomplete/index.ts', |
| 86 | + 'button/index.ts', |
| 87 | + 'button-toggle/index.ts', |
| 88 | + 'card/index.ts', |
| 89 | + 'checkbox/index.ts', |
| 90 | + 'chips/index.ts', |
| 91 | + 'core/index.ts', |
| 92 | + 'dialog/index.ts', |
| 93 | + 'grid-list/index.ts', |
| 94 | + 'icon/index.ts', |
| 95 | + 'input/index.ts', |
| 96 | + 'list/index.ts', |
| 97 | + 'menu/index.ts', |
| 98 | + 'progress-bar/index.ts', |
| 99 | + 'progress-circle/index.ts', |
| 100 | + 'radio/index.ts', |
| 101 | + 'select/index.ts', |
| 102 | + 'sidenav/index.ts', |
| 103 | + 'slide-toggle/index.ts', |
| 104 | + 'slider/index.ts', |
| 105 | + 'snack-bar/index.ts', |
| 106 | + 'tabs/index.ts', |
| 107 | + 'toolbar/index.ts', |
| 108 | + 'tooltip/index.ts', |
| 109 | + ]; |
| 110 | +}) |
| 111 | + |
| 112 | + |
| 113 | +// Configure processor for finding nunjucks templates. |
| 114 | +.config(function(templateFinder, templateEngine) { |
| 115 | + // Where to find the templates for the doc rendering |
| 116 | + templateFinder.templateFolders = [templateDir]; |
| 117 | + |
| 118 | + // Standard patterns for matching docs to templates |
| 119 | + templateFinder.templatePatterns = [ |
| 120 | + '${ doc.template }', |
| 121 | + '${ doc.id }.${ doc.docType }.template.html', |
| 122 | + '${ doc.id }.template.html', |
| 123 | + '${ doc.docType }.template.html', |
| 124 | + '${ doc.id }.${ doc.docType }.template.js', |
| 125 | + '${ doc.id }.template.js', |
| 126 | + '${ doc.docType }.template.js', |
| 127 | + '${ doc.id }.${ doc.docType }.template.json', |
| 128 | + '${ doc.id }.template.json', |
| 129 | + '${ doc.docType }.template.json', |
| 130 | + 'common.template.html' |
| 131 | + ]; |
| 132 | + |
| 133 | + // Nunjucks and Angular conflict in their template bindings so change Nunjucks |
| 134 | + templateEngine.config.tags = { |
| 135 | + variableStart: '{$', |
| 136 | + variableEnd: '$}' |
| 137 | + }; |
| 138 | +}); |
| 139 | + |
| 140 | + |
| 141 | +module.exports = apiDocsPackage; |
| 142 | + |
| 143 | +// Run the dgeni pipeline, generating documentation. |
| 144 | +// TODO(jelbourn): remove this once the process is more final in favor of gulp. |
| 145 | +let dgeni = new Dgeni([apiDocsPackage]); |
| 146 | +dgeni.generate().then(docs => { |
| 147 | + console.log(docs); |
| 148 | +}); |
0 commit comments