react-native-navigation的迁移库

generate-js-doc.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const jsdoc2md = require('jsdoc-to-markdown');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const paramsDir = './lib/src/params/';
  5. const optionsDir = './lib/src/params/options/';
  6. const OUTPUT_DIR = './docs/docs/';
  7. const partial = ['./docs/templates/scope.hbs', './docs/templates/docs.hbs'];
  8. const generateMarkdownForFile = ({ file, outputDir }) => {
  9. const templateData = jsdoc2md.getTemplateDataSync({ files: file });
  10. const classNames = getClassesInFile(templateData);
  11. classNames.forEach((className) => createDocFileForClass(className, templateData, outputDir));
  12. };
  13. function getClassesInFile(templateData) {
  14. const classNames = templateData.reduce((classNames, identifier) => {
  15. if (identifier.kind === 'class') {
  16. classNames.push(identifier.name);
  17. }
  18. return classNames;
  19. }, []);
  20. return classNames;
  21. }
  22. function createDocFileForClass(className, templateData, outputDir) {
  23. const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`;
  24. const options = {
  25. data: templateData,
  26. template,
  27. separators: true,
  28. partial
  29. };
  30. console.log(`rendering ${className}, template: ${template} ${outputDir}`);
  31. const output = jsdoc2md.renderSync(options);
  32. fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output);
  33. }
  34. function inputFiles() {
  35. return [
  36. { file: './lib/src/Navigation.js', outputDir: OUTPUT_DIR },
  37. ...fs.readdirSync(optionsDir).map((file) => {
  38. return {
  39. file: optionsDir + file,
  40. outputDir: OUTPUT_DIR + 'options/'
  41. };
  42. }),
  43. ...fs.readdirSync(paramsDir)
  44. .filter((file) => fs.statSync(paramsDir + file).isFile())
  45. .map((file) => {
  46. return {
  47. file: paramsDir + file,
  48. outputDir: OUTPUT_DIR
  49. };
  50. })
  51. ];
  52. }
  53. inputFiles().forEach((inputFile) => generateMarkdownForFile(inputFile));