react-native-navigation的迁移库

12345678910111213141516171819202122232425262728293031323334
  1. import * as fs from 'fs';
  2. import { ReflectionsReader } from './ReflectionsReader';
  3. import { MarkdownCreator } from './MarkdownCreator';
  4. import * as Handlebars from 'handlebars';
  5. const MD_RELATIVE_LINK = `/lib/src/`;
  6. const OUTPUT_DIR = `${__dirname}/../../docs/api`;
  7. const TEMPLATES_DIR = `${__dirname}/templates`;
  8. const TSCONFIG = JSON.parse(fs.readFileSync(`${__dirname}/../../tsconfig.json`).toString());
  9. class Main {
  10. public run() {
  11. const handlebarsFn = this.setupHandlebars();
  12. const reflection = new ReflectionsReader(TSCONFIG).read('./lib/src/Navigation.ts');
  13. const markdown = new MarkdownCreator(MD_RELATIVE_LINK, handlebarsFn).create(reflection);
  14. fs.writeFileSync(`${OUTPUT_DIR}/Navigation.md`, markdown, { encoding: 'utf8' });
  15. }
  16. private setupHandlebars() {
  17. const mainTemplate = fs.readFileSync(`${TEMPLATES_DIR}/main.hbs`).toString();
  18. const classTemplate = fs.readFileSync(`${TEMPLATES_DIR}/class.hbs`).toString();
  19. const methodTemplate = fs.readFileSync(`${TEMPLATES_DIR}/method.hbs`).toString();
  20. Handlebars.registerPartial('class', classTemplate);
  21. Handlebars.registerPartial('method', methodTemplate);
  22. return Handlebars.compile(mainTemplate, { strict: true, noEscape: true });
  23. }
  24. }
  25. new Main().run();