react-native-navigation的迁移库

generate-js-doc.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const jsdoc2md = require('jsdoc-to-markdown');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const inputFiles = ['./lib/src/params/NavigationOptions.js', './lib/src/Navigation.js'];
  5. const outputDir = './docs/docs/';
  6. const partial = ['./docs/templates/scope.hbs', './docs/templates/docs.hbs'];
  7. const generateMarkdownForFile = (file) => {
  8. const templateData = jsdoc2md.getTemplateDataSync({ files: file });
  9. const classNames = getClassesInFile(templateData);
  10. classNames.forEach((className) => createDocFileForClass(className, templateData));
  11. };
  12. function getClassesInFile(templateData) {
  13. const classNames = templateData.reduce((classNames, identifier) => {
  14. if (identifier.kind === 'class') {
  15. classNames.push(identifier.name);
  16. }
  17. return classNames;
  18. }, []);
  19. return classNames;
  20. }
  21. function createDocFileForClass(className, templateData) {
  22. const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
  23. const options = {
  24. data: templateData,
  25. template,
  26. separators: true,
  27. partial
  28. };
  29. console.log(`rendering ${className}, template: ${template}`);
  30. const output = jsdoc2md.renderSync(options);
  31. fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
  32. }
  33. inputFiles.forEach((inputFile) => generateMarkdownForFile(inputFile));