(filePath: string, args: IParseArgs)
| 477 | const defaultTsConfigPath = path.resolve(__dirname, './tsconfig.json'); |
| 478 | |
| 479 | export default function parseTS(filePath: string, args: IParseArgs): ComponentDoc[] { |
| 480 | if (!filePath) return []; |
| 481 | |
| 482 | let basePath = args.moduleDir || args.workDir || path.dirname(filePath); |
| 483 | let tsConfigPath = findConfig('tsconfig.json', { cwd: basePath }); // path.resolve(basePath, 'tsconfig.json') |
| 484 | if ( |
| 485 | !tsConfigPath || |
| 486 | !existsSync(tsConfigPath) || |
| 487 | (args.accesser === 'online' && tsConfigPath === 'tsconfig.json') |
| 488 | ) { |
| 489 | tsConfigPath = defaultTsConfigPath; |
| 490 | } else { |
| 491 | basePath = path.dirname(tsConfigPath); |
| 492 | } |
| 493 | |
| 494 | log('ts config path is', tsConfigPath); |
| 495 | const { config, error } = ts.readConfigFile(tsConfigPath, (filename) => |
| 496 | readFileSync(filename, 'utf8')); |
| 497 | |
| 498 | if (error !== undefined) { |
| 499 | const errorText = `Cannot load custom tsconfig.json from provided path: ${tsConfigPath}, with error code: ${error.code}, message: ${error.messageText}`; |
| 500 | throw new Error(errorText); |
| 501 | } |
| 502 | |
| 503 | const { options, errors } = ts.parseJsonConfigFileContent( |
| 504 | config, |
| 505 | ts.sys, |
| 506 | basePath, |
| 507 | {}, |
| 508 | tsConfigPath, |
| 509 | ); |
| 510 | |
| 511 | if (errors && errors.length) { |
| 512 | throw errors[0]; |
| 513 | } |
| 514 | log('ts config is', options); |
| 515 | // const filePaths = Array.isArray(filePathOrPaths) ? filePathOrPaths : [filePathOrPaths]; |
| 516 | generateDTS(args); |
| 517 | const program = ts.createProgram([filePath], options); |
| 518 | |
| 519 | const parser = new MyParser(program, {}); |
| 520 | |
| 521 | const checker = program.getTypeChecker(); |
| 522 | |
| 523 | const result = [filePath] |
| 524 | .map((fPath) => program.getSourceFile(fPath)) |
| 525 | .filter((sourceFile) => typeof sourceFile !== 'undefined') |
| 526 | .reduce((docs: any[], sourceFile) => { |
| 527 | const moduleSymbol = checker.getSymbolAtLocation(sourceFile as ts.Node); |
| 528 | |
| 529 | if (!moduleSymbol) { |
| 530 | return docs; |
| 531 | } |
| 532 | |
| 533 | const exportSymbols = checker.getExportsOfModule(moduleSymbol); |
| 534 | |
| 535 | for (let index = 0; index < exportSymbols.length; index++) { |
| 536 | const sym: SymbolWithMeta = exportSymbols[index]; |
no test coverage detected
searching dependent graphs…