react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import * as Handlebars from 'handlebars';
  2. import * as Typedoc from 'typedoc';
  3. export interface PropertyContext {
  4. name: string;
  5. type: string;
  6. }
  7. export interface ArgumentContext {
  8. name: string;
  9. type: string;
  10. }
  11. export interface MethodContext {
  12. name: string;
  13. arguments: ArgumentContext[];
  14. returnType: string;
  15. source: string;
  16. comment?: string;
  17. }
  18. export interface ClassContext {
  19. name: string;
  20. properties: PropertyContext[];
  21. methods: MethodContext[];
  22. }
  23. export class ClassParser {
  24. constructor(private sourceLinkPrefix: string) { }
  25. public parseClasses(classReflections: Typedoc.DeclarationReflection[]): ClassContext[] {
  26. return classReflections.map((r) => this.parseClass(r));
  27. }
  28. private parseClass(classReflection: Typedoc.DeclarationReflection): ClassContext {
  29. return {
  30. name: classReflection.name,
  31. properties: this.parseProperties(classReflection),
  32. methods: this.parseMethods(classReflection)
  33. };
  34. }
  35. private parseMethods(reflection: Typedoc.DeclarationReflection): MethodContext[] {
  36. const methodReflections = reflection.getChildrenByKind(Typedoc.ReflectionKind.Method);
  37. methodReflections.sort((a, b) => a.sources[0].line - b.sources[0].line);
  38. return methodReflections.map((methodReflection) => ({
  39. name: methodReflection.name,
  40. arguments: this.parseArguments(methodReflection.signatures[0].parameters || []),
  41. returnType: methodReflection.signatures[0].type.toString(),
  42. source: `${this.sourceLinkPrefix}/${methodReflection.sources[0].fileName}#L${methodReflection.sources[0].line}`,
  43. comment: methodReflection.signatures[0].comment ? methodReflection.signatures[0].comment.shortText : ''
  44. }));
  45. }
  46. private parseArguments(parameters: Typedoc.ParameterReflection[]): ArgumentContext[] {
  47. return parameters.map((parameter) => ({
  48. name: parameter.name,
  49. type: parameter.type.toString()
  50. }));
  51. }
  52. private parseProperties(reflection: Typedoc.DeclarationReflection): PropertyContext[] {
  53. const propsReflections = reflection.getChildrenByKind(Typedoc.ReflectionKind.Property);
  54. return propsReflections.map((propReflection) => ({
  55. name: propReflection.name,
  56. type: propReflection.type.toString()
  57. }));
  58. }
  59. }