react-native-navigation的迁移库

MarkdownCreator.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as Handlebars from 'handlebars';
  2. import * as Typedoc from 'typedoc';
  3. import * as fs from 'fs';
  4. export class MarkdownCreator {
  5. constructor(private mdRelativeLinkPath: string, private handlebarsFn: HandlebarsTemplateDelegate<any>) { }
  6. public create(reflection: Typedoc.DeclarationReflection) {
  7. const context = {
  8. name: reflection.name,
  9. properties: this.readProperties(reflection),
  10. methods: this.readMethods(reflection)
  11. };
  12. return this.handlebarsFn(context);
  13. }
  14. private readMethods(reflection: Typedoc.DeclarationReflection) {
  15. const methodReflections = reflection.getChildrenByKind(Typedoc.ReflectionKind.Method);
  16. methodReflections.sort((a, b) => a.sources[0].line - b.sources[0].line);
  17. return methodReflections.map((methodReflection) => ({
  18. name: methodReflection.name,
  19. arguments: this.readArguments(methodReflection.signatures[0].parameters || []),
  20. returnType: methodReflection.signatures[0].type.toString(),
  21. source: `${this.mdRelativeLinkPath}/${methodReflection.sources[0].fileName}#${methodReflection.sources[0].line}`,
  22. comment: methodReflection.signatures[0].comment ? methodReflection.signatures[0].comment.shortText : ''
  23. }));
  24. }
  25. private readArguments(parameters: Typedoc.ParameterReflection[]) {
  26. return parameters.map((parameter) => ({
  27. name: parameter.name,
  28. type: parameter.type.toString()
  29. }));
  30. }
  31. private readProperties(reflection: Typedoc.DeclarationReflection) {
  32. const propsReflections = reflection.getChildrenByKind(Typedoc.ReflectionKind.Property);
  33. return propsReflections.map((propReflection) => ({
  34. name: propReflection.name,
  35. type: propReflection.type.toString()
  36. }));
  37. }
  38. }