react-native-navigation的迁移库

Main.ts 1.4KB

123456789101112131415161718192021222324252627282930313233
  1. import * as fs from 'fs';
  2. import { ReflectionsReader } from './ReflectionsReader';
  3. import { ClassParser } from './ClassParser';
  4. import { MarkdownWriter } from './MarkdownWriter';
  5. import { ReflectionKind } from 'typedoc';
  6. const INPUT_DIR = `${__dirname}/../../lib/src`;
  7. const OUTPUT_DIR = `${__dirname}/../../docs/api`;
  8. const TEMPLATES_DIR = `${__dirname}/templates`;
  9. const TSCONFIG_PATH = `${__dirname}/../../tsconfig.json`;
  10. const SOURCE_LINK_PREFIX = `https://github.com/wix/react-native-navigation/blob/v2/lib/src`;
  11. class Main {
  12. public run() {
  13. const classParser = new ClassParser(SOURCE_LINK_PREFIX);
  14. const markdownWriter = new MarkdownWriter(TEMPLATES_DIR, OUTPUT_DIR);
  15. const projectReflections = new ReflectionsReader(TSCONFIG_PATH).read(INPUT_DIR);
  16. const externalModules = projectReflections.getChildrenByKind(ReflectionKind.ExternalModule)
  17. .filter((m) => !m.name.endsWith('.mock"') && !m.name.endsWith('.test"'));
  18. const classReflections = externalModules.filter((m) => m.getChildrenByKind(ReflectionKind.Class).length === 1)
  19. .map((m) => m.getChildrenByKind(ReflectionKind.Class)[0]);
  20. // just class modules, TODO: extract interfaces and types to their own modules, generate docs for interfaces and types
  21. const parsedClasses = classReflections.map((c) => classParser.parseClass(c));
  22. markdownWriter.writeClasses(parsedClasses);
  23. markdownWriter.writeMenu(parsedClasses);
  24. }
  25. }
  26. new Main().run();