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C,CAAC,EACpC,EAAE,EACF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE5B,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC;QAE7B,MAAM,OAAO,GAAG,6BAAgB,CAAC,OAAO,CAAC;QACzC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;YACvB,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;SACvB;QAED,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AAvFkB,0BAAW,GAAG,UAAU,CAAC;AAOzB,0BAAW,GAAG,SAAS,CAAC;AAZvC;IANC,kBAAM,CAAC;QACJ,IAAI,EAAE,gBAAc,CAAC,WAAW;QAChC,IAAI,EAAE,4IAA4I;QAClJ,IAAI,EAAE,2BAAa,CAAC,MAAM;QAC1B,IAAI,EAAE,2BAAa,CAAC,IAAI;KAC3B,CAAC;+CACe;AAPR,cAAc;IAD1B,qBAAS,CAAC,EAAC,IAAI,EAAE,kBAAkB,EAAC,CAAC;GACzB,cAAc,CAmG1B;AAnGY,wCAAc","sourcesContent":["import * as Path from 'path';\nimport * as FS from 'fs';\nimport * as _ from 'lodash';\nimport * as ts from 'typescript';\n\nimport { Component, Option } from '../../component';\nimport { OptionsComponent, OptionsReadMode, DiscoverEvent } from '../options';\nimport { ParameterType, ParameterHint } from '../declaration';\nimport { TypeScriptSource } from '../sources/typescript';\n\n/**\n * Obtains option values from tsconfig.json\n */\n@Component({name: 'options:tsconfig'})\nexport class TSConfigReader extends OptionsComponent {\n @Option({\n name: TSConfigReader.OPTIONS_KEY,\n help: 'Specify a typescript config file that should be loaded. If not specified TypeDoc will look for \\'tsconfig.json\\' in the current directory.',\n type: ParameterType.String,\n hint: ParameterHint.File\n })\n options!: string;\n\n /**\n * The name of the parameter that specifies the tsconfig file.\n */\n private static OPTIONS_KEY = 'tsconfig';\n\n /**\n * The name of the parameter that specifies the TS project\n *\n * https://github.com/Microsoft/TypeScript/blob/master/src/compiler/commandLineParser.ts#L49\n */\n private static PROJECT_KEY = 'project';\n\n initialize() {\n this.listenTo(this.owner, DiscoverEvent.DISCOVER, this.onDiscover, -100);\n }\n\n onDiscover(event: DiscoverEvent) {\n // Do nothing until were fetching options\n if (event.mode !== OptionsReadMode.Fetch) {\n return;\n }\n\n let file: string | undefined;\n\n if (TSConfigReader.OPTIONS_KEY in event.data) {\n const tsconfig = event.data[TSConfigReader.OPTIONS_KEY];\n\n if (FS.existsSync(tsconfig) && FS.statSync(tsconfig).isFile()) {\n file = Path.resolve(tsconfig);\n } else {\n file = ts.findConfigFile(tsconfig, ts.sys.fileExists);\n }\n\n if (!file || !FS.existsSync(file)) {\n event.addError('The tsconfig file %s does not exist.', file || '');\n return;\n }\n } else if (TSConfigReader.PROJECT_KEY in event.data) {\n const resolved = Path.resolve(event.data[TSConfigReader.PROJECT_KEY]);\n // If the file exists, use it\n if (FS.existsSync(resolved)) {\n file = resolved;\n } else {\n // Use TS to find the file, since it could be a directory\n file = ts.findConfigFile(resolved, ts.sys.fileExists);\n }\n } else if (this.application.isCLI) {\n // No file or directory has been specified so find the file in the root of the project\n file = ts.findConfigFile('.', ts.sys.fileExists);\n }\n\n // If file is undefined, we found no file to load.\n if (file) {\n this.load(event, file);\n }\n }\n\n /**\n * Load the specified tsconfig file.\n *\n * @param event The event that triggered the loading. Used to store error messages.\n * @param fileName The absolute path and file name of the tsconfig file.\n */\n load(event: DiscoverEvent, fileName: string) {\n const { config } = ts.readConfigFile(fileName, ts.sys.readFile);\n if (config === undefined) {\n event.addError('No valid tsconfig file found for %s.', fileName);\n return;\n }\n if (!_.isPlainObject(config)) {\n event.addError('The tsconfig file %s does not contain a JSON object.', fileName);\n return;\n }\n\n const { fileNames, options, raw: { typedocOptions }} = ts.parseJsonConfigFileContent(\n config,\n ts.sys,\n Path.resolve(Path.dirname(fileName)),\n {},\n Path.resolve(fileName));\n\n event.inputFiles = fileNames;\n\n const ignored = TypeScriptSource.IGNORED;\n for (const key of ignored) {\n delete options[key];\n }\n\n _.defaults(event.data, typedocOptions, options);\n }\n}\n"]}
\No newline at end of file