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ANC,kBAAM,CAAC;QACJ,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,yGAAyG;QAC/G,IAAI,EAAE,2BAAa,CAAC,MAAM;QAC1B,YAAY,EAAE,SAAS;KAC1B,CAAC;2CACiB;AAOnB;IALC,kBAAM,CAAC;QACJ,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE,0EAA0E;QAChF,IAAI,EAAE,2BAAa,CAAC,OAAO;KAC9B,CAAC;oDAC2B;AAM7B;IAJC,kBAAM,CAAC;QACJ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,kEAAkE;KAC3E,CAAC;sCACY;AAOd;IALC,kBAAM,CAAC;QACJ,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,6DAA6D;QACnE,YAAY,EAAE,MAAM;KACvB,CAAC;wCACc;AAOhB;IALC,kBAAM,CAAC;QACJ,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,uDAAuD;QAC7D,IAAI,EAAE,2BAAa,CAAC,OAAO;KAC9B,CAAC;+CACsB;AAOxB;IALC,kBAAM,CAAC;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,sFAAsF;QAC5F,IAAI,EAAE,2BAAa,CAAC,MAAM;KAC7B,CAAC;4CACkB;AAOpB;IALC,kBAAM,CAAC;QACJ,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,4CAA4C;QAClD,IAAI,EAAE,2BAAa,CAAC,KAAK;KAC5B,CAAC;qCACa;AArDN,QAAQ;IADpB,qBAAS,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,8BAAiB,EAAC,CAAC;GAChE,QAAQ,CA2OpB;AA3OY,4BAAQ;AA6OrB,qBAAmB","sourcesContent":["/**\n * Holds all logic used render and output the final documentation.\n *\n * The [[Renderer]] class is the central controller within this namespace. When invoked it creates\n * an instance of [[BaseTheme]] which defines the layout of the documentation and fires a\n * series of [[RendererEvent]] events. Instances of [[BasePlugin]] can listen to these events and\n * alter the generated output.\n */\n\nimport * as Path from 'path';\nimport * as FS from 'fs-extra';\n// tslint:disable-next-line:variable-name\nconst ProgressBar = require('progress');\n\nimport { Application } from '../application';\nimport { Theme } from './theme';\nimport { RendererEvent, PageEvent } from './events';\nimport { ProjectReflection } from '../models/reflections/project';\nimport { UrlMapping } from './models/UrlMapping';\nimport { writeFile } from '../utils/fs';\nimport { DefaultTheme } from './themes/DefaultTheme';\nimport { RendererComponent } from './components';\nimport { Component, ChildableComponent, Option } from '../utils/component';\nimport { ParameterType } from '../utils/options/declaration';\n\n/**\n * The renderer processes a [[ProjectReflection]] using a [[BaseTheme]] instance and writes\n * the emitted html documents to a output directory. You can specify which theme should be used\n * using the ```--theme <name>``` commandline argument.\n *\n * Subclasses of [[BasePlugin]] that have registered themselves in the [[Renderer.PLUGIN_CLASSES]]\n * will be automatically initialized. Most of the core functionality is provided as separate plugins.\n *\n * [[Renderer]] is a subclass of [[EventDispatcher]] and triggers a series of events while\n * a project is being processed. You can listen to these events to control the flow or manipulate\n * the output.\n *\n * * [[Renderer.EVENT_BEGIN]]<br>\n * Triggered before the renderer starts rendering a project. The listener receives\n * an instance of [[RendererEvent]]. By calling [[RendererEvent.preventDefault]] the entire\n * render process can be canceled.\n *\n * * [[Renderer.EVENT_BEGIN_PAGE]]<br>\n * Triggered before a document will be rendered. The listener receives an instance of\n * [[PageEvent]]. By calling [[PageEvent.preventDefault]] the generation of the\n * document can be canceled.\n *\n * * [[Renderer.EVENT_END_PAGE]]<br>\n * Triggered after a document has been rendered, just before it is written to disc. The\n * listener receives an instance of [[PageEvent]]. When calling\n * [[PageEvent.preventDefault]] the the document will not be saved to disc.\n *\n * * [[Renderer.EVENT_END]]<br>\n * Triggered after the renderer has written all documents. The listener receives\n * an instance of [[RendererEvent]].\n */\n@Component({name: 'renderer', internal: true, childClass: RendererComponent})\nexport class Renderer extends ChildableComponent<Application, RendererComponent> {\n /**\n * The theme that is used to render the documentation.\n */\n theme?: Theme;\n\n @Option({\n name: 'theme',\n help: 'Specify the path to the theme that should be used or \\'default\\' or \\'minimal\\' to use built-in themes.',\n type: ParameterType.String,\n defaultValue: 'default'\n })\n themeName!: string;\n\n @Option({\n name: 'disableOutputCheck',\n help: 'Should TypeDoc disable the testing and cleaning of the output directory?',\n type: ParameterType.Boolean\n })\n disableOutputCheck!: boolean;\n\n @Option({\n name: 'gaID',\n help: 'Set the Google Analytics tracking ID and activate tracking code.'\n })\n gaID!: string;\n\n @Option({\n name: 'gaSite',\n help: 'Set the site name for Google Analytics. Defaults to `auto`.',\n defaultValue: 'auto'\n })\n gaSite!: string;\n\n @Option({\n name: 'hideGenerator',\n help: 'Do not print the TypeDoc link at the end of the page.',\n type: ParameterType.Boolean\n })\n hideGenerator!: boolean;\n\n @Option({\n name: 'entryPoint',\n help: 'Specifies the fully qualified name of the root symbol. Defaults to global namespace.',\n type: ParameterType.String\n })\n entryPoint!: string;\n\n @Option({\n name: 'toc',\n help: 'Specifies the top level table of contents.',\n type: ParameterType.Array\n })\n toc!: string[];\n\n /**\n * Create a new Renderer instance.\n *\n * @param application The application this dispatcher is attached to.\n */\n initialize() {\n }\n\n /**\n * Render the given project reflection to the specified output directory.\n *\n * @param project The project that should be rendered.\n * @param outputDirectory The path of the directory the documentation should be rendered to.\n */\n render(project: ProjectReflection, outputDirectory: string) {\n if (!this.prepareTheme() || !this.prepareOutputDirectory(outputDirectory)) {\n return;\n }\n\n const output = new RendererEvent(RendererEvent.BEGIN, outputDirectory, project);\n output.settings = this.application.options.getRawValues();\n output.urls = this.theme!.getUrls(project);\n\n const bar = new ProgressBar('Rendering [:bar] :percent', {\n total: output.urls.length,\n width: 40\n });\n\n this.trigger(output);\n if (!output.isDefaultPrevented) {\n output.urls.forEach((mapping: UrlMapping) => {\n this.renderDocument(output.createPageEvent(mapping));\n bar.tick();\n });\n\n this.trigger(RendererEvent.END, output);\n }\n }\n\n /**\n * Render a single page.\n *\n * @param page An event describing the current page.\n * @return TRUE if the page has been saved to disc, otherwise FALSE.\n */\n private renderDocument(page: PageEvent): boolean {\n this.trigger(PageEvent.BEGIN, page);\n if (page.isDefaultPrevented) {\n return false;\n }\n\n // Theme must be set as this is only called in render, and render ensures theme is set.\n page.template = page.template || this.theme!.resources.templates.getResource(page.templateName)!.getTemplate();\n page.contents = page.template(page);\n\n this.trigger(PageEvent.END, page);\n if (page.isDefaultPrevented) {\n return false;\n }\n\n try {\n writeFile(page.filename, page.contents, false);\n } catch (error) {\n this.application.logger.error('Could not write %s', page.filename);\n return false;\n }\n\n return true;\n }\n\n /**\n * Ensure that a theme has been setup.\n *\n * If a the user has set a theme we try to find and load it. If no theme has\n * been specified we load the default theme.\n *\n * @returns TRUE if a theme has been setup, otherwise FALSE.\n */\n private prepareTheme(): boolean {\n if (!this.theme) {\n const themeName = this.themeName;\n let path = Path.resolve(themeName);\n if (!FS.existsSync(path)) {\n path = Path.join(Renderer.getThemeDirectory(), themeName);\n if (!FS.existsSync(path)) {\n this.application.logger.error('The theme %s could not be found.', themeName);\n return false;\n }\n }\n\n const filename = Path.join(path, 'theme.js');\n if (!FS.existsSync(filename)) {\n this.theme = this.addComponent('theme', new DefaultTheme(this, path));\n } else {\n try {\n const themeClass = typeof require(filename) === 'function' ? require(filename) : require(filename).default;\n\n this.theme = this.addComponent('theme', new (themeClass)(this, path));\n } catch (err) {\n throw new Error(\n `Exception while loading \"${filename}\". You must export a \\`new Theme(renderer, basePath)\\` compatible class.\\n` +\n err\n );\n }\n }\n }\n\n this.theme!.resources.activate();\n return true;\n }\n\n /**\n * Prepare the output directory. If the directory does not exist, it will be\n * created. If the directory exists, it will be emptied.\n *\n * @param directory The path to the directory that should be prepared.\n * @returns TRUE if the directory could be prepared, otherwise FALSE.\n */\n private prepareOutputDirectory(directory: string): boolean {\n if (FS.existsSync(directory)) {\n if (!FS.statSync(directory).isDirectory()) {\n this.application.logger.error(\n 'The output target \"%s\" exists but it is not a directory.',\n directory);\n return false;\n }\n\n if (this.disableOutputCheck) {\n return true;\n }\n\n if (FS.readdirSync(directory).length === 0) {\n return true;\n }\n\n // Theme must be set as this is only called after the theme is created.\n if (!this.theme!.isOutputDirectory(directory)) {\n this.application.logger.error(\n 'The output directory \"%s\" exists but does not seem to be a documentation generated by TypeDoc.\\n' +\n 'Make sure this is the right target directory, delete the folder and rerun TypeDoc.',\n directory);\n return false;\n }\n\n try {\n FS.removeSync(directory);\n } catch (error) {\n this.application.logger.warn('Could not empty the output directory.');\n }\n }\n\n if (!FS.existsSync(directory)) {\n try {\n FS.mkdirpSync(directory);\n } catch (error) {\n this.application.logger.error('Could not create output directory %s', directory);\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Return the path containing the themes shipped with TypeDoc.\n *\n * @returns The path to the theme directory.\n */\n static getThemeDirectory(): string {\n return Path.dirname(require.resolve('typedoc-default-themes'));\n }\n\n /**\n * Return the path to the default theme.\n *\n * @returns The path to the default theme.\n */\n static getDefaultTheme(): string {\n return Path.join(Renderer.getThemeDirectory(), 'default');\n }\n}\n\nimport './plugins';\n"]}
\No newline at end of file